Exemplo n.º 1
0
    def get_complex_db():
        """
        Returns a more complex database with two tables and keys for testing.
        :return: Database with two tables and keys.
        :rtype: Database
        """
        database = Database(database_name="database2")
        table1 = Table(
            table_name="table1",
            primary_key="col1",
            shard_key=ShardKey("col1", 128),
        )
        table1.add_column(Column(column_name="col1", column_type="INT"))
        table1.add_column(Column(column_name="Col2", column_type="DOUBLE"))
        table1.add_column(Column(column_name="COL3", column_type="FLOAT"))
        database.add_table(table1)

        table2 = Table(
            table_name="table2",
            primary_key=["col4", "Col5"],
            shard_key=ShardKey(["col4", "Col5"], 96),
        )
        table2.add_column(Column(column_name="col4", column_type="VARCHAR(0)"))
        table2.add_column(Column(column_name="Col5", column_type="DATE"))
        table2.add_column(Column(column_name="COL6", column_type="BOOL"))
        database.add_table(table2)

        table2.add_foreign_key(from_keys="Col5",
                               to_table="table1",
                               to_keys="COL3")
        table1.add_relationship(
            to_table="table2",
            conditions='("table1"."col1" == "table2."COL6")')

        return database
Exemplo n.º 2
0
    def test_valid_database(self):
        """Tests a good database to make sure there are no false positives."""
        good_db = Database(database_name="good_db")
        table1 = Table(
            table_name="table1",
            primary_key=["col1", "col2"],
            shard_key=ShardKey(shard_keys="col1", number_shards=128),
        )
        table1.add_column(Column(column_name="col1", column_type="INT"))
        table1.add_column(Column(column_name="col2", column_type="INT"))
        good_db.add_table(table1)

        table2 = Table(
            table_name="table2",
            primary_key=["col3", "col4"],
            shard_key=ShardKey(shard_keys="col3", number_shards=128),
        )
        table2.add_foreign_key(
            from_keys=["col3", "col4"],
            to_table="table1",
            to_keys=["col1", "col2"],
        )
        table2.add_column(Column(column_name="col3", column_type="INT"))
        table2.add_column(Column(column_name="col4", column_type="INT"))
        good_db.add_table(table2)

        dv = DatabaseValidator(good_db)
        results = dv.validate()
        self.assertTrue(results.is_valid)
        self.assertEqual([], results.issues)
Exemplo n.º 3
0
    def get_test_table():
        """
        Returns a table for testing columns and such.
        :returns: A table with columns for testing.
        :rtype: Table
        """
        table = Table(table_name="Table", schema_name="test")
        table.add_column(Column(column_name="column_1", column_type="INT"))
        table.add_column(Column(column_name="column_2", column_type="DOUBLE"))
        table.add_column(
            Column(column_name="column_3", column_type="DATETIME")
        )
        table.add_column(Column(column_name="column_4", column_type="BOOL"))

        return table
Exemplo n.º 4
0
    def get_simple_db():
        """
        Returns a simple database with one table for testing.
        :return: Database with one table.
        :rtype: Database
        """
        database = Database(database_name="database1")
        table = Table(table_name="table1")
        table.add_column(Column(column_name="col1", column_type="INT"))
        table.add_column(Column(column_name="Col2", column_type="DOUBLE"))
        table.add_column(Column(column_name="COL3", column_type="FLOAT"))
        database.add_table(table)

        return database
Exemplo n.º 5
0
    def test_with_csvfile(self):
        """test the tsload writer when the csv exists"""
        # todo Create the csv file.
        database = Database(database_name="xdb")

        table = Table(
            table_name="table1",
            schema_name="s1",
            primary_key="column_1",
            shard_key=ShardKey("column_1", 128),
        )
        table.add_column(Column(column_name="column_1", column_type="INT"))
        table.add_column(Column(column_name="column_2", column_type="DOUBLE"))
        table.add_column(Column(column_name="column_3", column_type="FLOAT"))
        table.add_column(Column(column_name="column_3", column_type="DATE"))
        database.add_table(table)

        table = Table(
            table_name="table2",
            schema_name="s1",
            primary_key="column_1",
            shard_key=ShardKey("column_1", 128),
        )
        table.add_column(Column(column_name="column_1", column_type="INT"))
        table.add_column(Column(column_name="column_2", column_type="FLOAT"))
        table.add_column(Column(column_name="column_3", column_type="DOUBLE"))
        database.add_table(table)

        table = Table(
            table_name="table3",
            schema_name="s1",
            primary_key="column_1",
            shard_key=ShardKey("column_1", 128),
        )
        table.add_column(Column(column_name="column_1", column_type="INT"))
        table.add_column(Column(column_name="column_2", column_type="FLOAT"))
        table.add_column(Column(column_name="column_3", column_type="VARCHAR"))
        database.add_table(table)
Exemplo n.º 6
0
    def test_create_excel(self):
        """Test writing to Excel.  Only test is existance.  Checks shoudl be made for validity."""
        database = Database(database_name="xdb")

        table = Table(
            table_name="table1",
            schema_name="s1",
            primary_key="column_1",
            shard_key=ShardKey("column_1", 128),
        )
        table.add_column(Column(column_name="column_1", column_type="INT"))
        table.add_column(Column(column_name="column_2", column_type="DOUBLE"))
        table.add_column(Column(column_name="column_3", column_type="FLOAT"))
        database.add_table(table)

        table = Table(table_name="table2",
                      schema_name="s1",
                      primary_key="column_1")
        table.add_column(Column(column_name="column_1", column_type="INT"))
        table.add_column(Column(column_name="column_2",
                                column_type="DATETIME"))
        table.add_column(Column(column_name="column_3", column_type="BOOL"))
        table.add_column(Column(column_name="column_4", column_type="DOUBLE"))
        table.add_foreign_key(from_keys="column_1",
                              to_table="table_1",
                              to_keys="column_1")
        table.add_relationship(to_table="table1",
                               conditions="table2.column_4 = table1.column_2")
        database.add_table(table)

        writer = XLSWriter()
        writer.write_database(database, "test_excel")