def test_reflect(self):
        # checking, that after call metadata.reflect()
        # we have a clickhouse-specific table, which has overridden join
        # methods

        session = self.session
        metadata = self.metadata()

        # ### Maybe: ###
        # # session = native_session  # database=test
        # session = self.__class__.session
        # same as in `self.metadata()`  # database=default
        # unbound_metadata = MetaData(bind=session.bind)

        table = CHTable(
            'test_reflect',
            metadata,
            Column('x', types.Int32),
            engines.Log()
        )

        table.drop(session.bind, if_exists=True)
        table.create(session.bind)

        # Sub-test: ensure the `metadata.reflect` makes a CHTable
        metadata.clear()  # reflect from clean state
        self.assertFalse(metadata.tables)
        metadata.reflect(only=[table.name])
        table2 = metadata.tables.get(table.name)
        self.assertIsNotNone(table2)
        self.assertListEqual([c.name for c in table2.columns], ['x'])
        self.assertTrue(isinstance(table2, CHTable))

        # Sub-test: ensure `CHTable(..., autoload=True)` works too
        metadata.clear()
        table3 = CHTable('test_reflect', metadata, autoload=True)
        self.assertListEqual([c.name for c in table3.columns], ['x'])

        # Sub-test: check that they all reflected the same.
        for table_x in [table, table2, table3]:
            query = table_x.select().select_from(table_x.join(
                text('another_table'),
                table.c.x == 'xxx',
                type='INNER',
                strictness='ALL',
                distribution='GLOBAL'
            ))
            self.assertEqual(
                self.compile(query),
                "SELECT test_reflect.x FROM test_reflect "
                "GLOBAL ALL INNER JOIN another_table "
                "ON test_reflect.x = %(x_1)s"
            )
Beispiel #2
0
    def test_reflect(self):
        """
        checking, that after call metadata.reflect()
        we have clickohouse-specific table, which have overridden join methods
        """
        unbound_metadata = MetaData(bind=native_session.bind)
        table = CHTable('test_reflect', unbound_metadata,
                        Column('x', types.Int32), engines.Log())
        table.drop(native_session.bind, if_exists=True)
        table.create(native_session.bind)

        std_metadata = self.metadata()
        self.assertFalse(std_metadata.tables)
        std_metadata.reflect(only=[table.name])
        table = std_metadata.tables.get(table.name)
        assert table is not None
        self.assertTrue(isinstance(table, CHTable))

        query = table.select().join(text('another_table'),
                                    table.c.x == 'xxx',
                                    type='INNER',
                                    strictness='ALL',
                                    distribution='GLOBAL')
        self.assertEqual(
            self.compile(query), "SELECT x FROM test_reflect "
            "GLOBAL ALL INNER JOIN another_table "
            "ON x = %(x_1)s")