def test_create_table(self):
        base = get_declarative_base()

        class TestTable(base):
            x = Column(types.Int32, primary_key=True)
            y = Column(types.String)

            __table_args__ = (engines.Memory(), )

        self.assertEqual(
            self.compile(CreateTable(TestTable.__table__)),
            'CREATE TABLE test_table (x Int32, y String) ENGINE = Memory')
    def test_text_engine_columns_declarative(self):
        base = get_declarative_base()

        class TestTable(base):
            date = Column(types.Date, primary_key=True)
            x = Column(types.Int32)
            y = Column(types.String)

            __table_args__ = (engines.MergeTree('date', ('date', 'x')), )

        self.assertEqual(
            self.compile(CreateTable(TestTable.__table__)),
            'CREATE TABLE test_table (date Date, x Int32, y String) '
            'ENGINE = MergeTree(date, (date, x), 8192)')
    def test_merge_tree_index_granularity(self):
        base = get_declarative_base()

        class TestTable(base):
            date = Column(types.Date, primary_key=True)
            x = Column(types.Int32)
            y = Column(types.String)

            __table_args__ = (engines.MergeTree(date, (date, x),
                                                index_granularity=4096), )

        self.assertEqual(
            self.compile(CreateTable(TestTable.__table__)),
            'CREATE TABLE test_table (date Date, x Int32, y String) '
            'ENGINE = MergeTree(date, (date, x), 4096)')
    def test_summing_merge_tree(self):
        base = get_declarative_base()

        class TestTable(base):
            date = Column(types.Date, primary_key=True)
            x = Column(types.Int32)
            y = Column(types.Int32)

            __table_args__ = (engines.SummingMergeTree(date, (date, x),
                                                       (y, )), )

        self.assertEqual(
            self.compile(CreateTable(TestTable.__table__)),
            'CREATE TABLE test_table (date Date, x Int32, y Int32) '
            'ENGINE = SummingMergeTree(date, (date, x), 8192, (y))')
    def test_buffer(self):
        base = get_declarative_base()

        class TestTable(base):
            date = Column(types.Date, primary_key=True)
            x = Column(types.Int32)
            y = Column(types.String)

            __table_args__ = (engines.Buffer('db', 'table'), )

        self.assertEqual(
            self.compile(CreateTable(TestTable.__table__)),
            "CREATE TABLE test_table (date Date, x Int32, y String) "
            "ENGINE = Buffer("
            "db, table, 16, 10, 100, 10000, 1000000, 10000000, 100000000"
            ")")
    def test_collapsing_merge_tree(self):
        base = get_declarative_base()

        class TestTable(base):
            date = Column(types.Date, primary_key=True)
            x = Column(types.Int32)
            y = Column(types.String)
            sign = Column(types.Int8)

            __table_args__ = (engines.CollapsingMergeTree(
                date, (date, x), sign), )

        self.assertEqual(
            self.compile(CreateTable(TestTable.__table__)),
            'CREATE TABLE test_table '
            '(date Date, x Int32, y String, sign Int8) '
            'ENGINE = CollapsingMergeTree(date, (date, x), 8192, sign)')
    def test_func_engine_columns(self):
        base = get_declarative_base()

        class TestTable(base):
            date = Column(types.Date, primary_key=True)
            x = Column(types.Int32)
            y = Column(types.String)

            __table_args__ = (engines.MergeTree('date',
                                                ('date', func.intHash32(x)),
                                                sampling=func.intHash32(x)), )

        self.assertEqual(
            self.compile(CreateTable(TestTable.__table__)),
            'CREATE TABLE test_table (date Date, x Int32, y String) '
            'ENGINE = MergeTree('
            'date, intHash32(x), (date, intHash32(x)), 8192'
            ')')
Ejemplo n.º 8
0
 def base(self):
     return get_declarative_base()