Ejemplo n.º 1
0
    def test_write_complex_db(self):
        """Test writing a more complex table."""
        database = TestTQLWriter.get_complex_db()

        writer = TQLWriter(create_db=True)
        string_io = StringIO()
        writer.write_tql(database=database, outfile=string_io)
        tql = string_io.getvalue()
        string_io.close()

        print(tql)

        self.assertIn('CONSTRAINT PRIMARY KEY ("col1")', tql)
        self.assertIn('CONSTRAINT PRIMARY KEY ("col4", "Col5")', tql)
        self.assertIn('PARTITION BY HASH(128) KEY("col1")', tql)
        self.assertIn('PARTITION BY HASH(96) KEY("col4", "Col5")', tql)

        self.assertIn(
            'ALTER TABLE "falcon_default_schema"."table2" ADD CONSTRAINT "FK_table2_to_table1" '
            + 'FOREIGN KEY ("Col5") ' +
            'REFERENCES "falcon_default_schema"."table1" ("COL3");', tql)
        self.assertIn(
            'ALTER TABLE "falcon_default_schema"."table1" ADD RELATIONSHIP "REL_table1_to_table2" '
            'WITH "falcon_default_schema"."table2" AS ("table1"."col1" == "table2."COL6");',
            tql)
def write_tql(args, database):
    """
    Writes the database to TQL to the output file.
    :param args: The command line arguments.
    :param database: The database to write.
    :type database: Database
    """
    writer = TQLWriter(args.uppercase, args.lowercase, args.camelcase,
                       args.create_db)
    writer.write_tql(database, args.to_tql)
Ejemplo n.º 3
0
    def test_write_upper(self):
        """Test writing with upper flag set."""
        database = TestTQLWriter.get_simple_db()

        writer = TQLWriter(uppercase=True)
        string_io = StringIO()
        writer.write_tql(database=database, outfile=string_io)
        tql = string_io.getvalue()
        string_io.close()

        self.assertIn('USE "DATABASE1"', tql)
        self.assertIn('DROP TABLE "falcon_default_schema"."TABLE1"', tql)
        self.assertIn('CREATE TABLE "falcon_default_schema"."TABLE1"', tql)
        self.assertIn('"COL1" INT', tql)
        self.assertIn('"COL2" DOUBLE', tql)
        self.assertIn('"COL3" FLOAT', tql)
        self.assertNotIn("PRIMARY KEY", tql)
Ejemplo n.º 4
0
    def test_write_simple_db(self):
        """Tests creating a single table with no keys or shards."""
        database = TestTQLWriter.get_simple_db()

        writer = TQLWriter()
        string_io = StringIO()
        writer.write_tql(database=database, outfile=string_io)
        tql = string_io.getvalue()
        string_io.close()

        self.assertIn('USE "database1"', tql)
        self.assertIn('DROP TABLE "falcon_default_schema"."table1"', tql)
        self.assertIn('CREATE TABLE "falcon_default_schema"."table1"', tql)
        self.assertIn('"col1" INT', tql)
        self.assertIn('"Col2" DOUBLE', tql)
        self.assertIn('"COL3" FLOAT', tql)
        self.assertNotIn("PRIMARY KEY", tql)