예제 #1
0
 def test_get_conditions(self):
     parts = list(
         SystemPart.get(self.database, conditions="table='testtable'"))
     self.assertEqual(len(parts), 1)
     parts = list(
         SystemPart.get(self.database, conditions=u"table='othertable'"))
     self.assertEqual(len(parts), 0)
예제 #2
0
 def test_get_conditions(self):
     parts = list(SystemPart.get(self.database, conditions="table='testtable'"))
     self.assertEqual(len(parts), 1)
     parts = list(SystemPart.get(self.database, conditions=u"table='custompartitionedtable'"))
     self.assertEqual(len(parts), 1)
     parts = list(SystemPart.get(self.database, conditions=u"table='invalidtable'"))
     self.assertEqual(len(parts), 0)
 def test_get_conditions(self):
     parts = list(SystemPart.get(self.database, conditions="table='testtable'"))
     self.assertEqual(len(parts), 1)
     parts = list(SystemPart.get(self.database, conditions=u"table='custompartitionedtable'"))
     self.assertEqual(len(parts), 1)
     parts = list(SystemPart.get(self.database, conditions=u"table='invalidtable'"))
     self.assertEqual(len(parts), 0)
예제 #4
0
    def test_custom_partitioning(self):
        class TestModel(SampleModel):
            engine = MergeTree(
                order_by=('date', 'event_id', 'event_group'),
                partition_key=('toYYYYMM(date)', 'event_group')
            )

        class TestCollapseModel(SampleModel):
            sign = Int8Field()

            engine = CollapsingMergeTree(
                sign_col='sign',
                order_by=('date', 'event_id', 'event_group'),
                partition_key=('toYYYYMM(date)', 'event_group')
            )

        self._create_and_insert(TestModel)
        self._create_and_insert(TestCollapseModel)

        # Result order may be different, lets sort manually
        parts = sorted(list(SystemPart.get(self.database)), key=lambda x: x.table)

        self.assertEqual(2, len(parts))
        self.assertEqual('testcollapsemodel', parts[0].table)
        self.assertEqual('(201701, 13)'.replace(' ', ''), parts[0].partition.replace(' ', ''))
        self.assertEqual('testmodel', parts[1].table)
        self.assertEqual('(201701, 13)'.replace(' ', ''), parts[1].partition.replace(' ', ''))
예제 #5
0
 def test_freeze(self):
     parts = list(SystemPart.get(self.database))
     # There can be other backups in the folder
     prev_backups = set(self._get_backups())
     parts[0].freeze()
     backups = set(self._get_backups())
     self.assertEqual(len(backups), len(prev_backups) + 1)
 def test_freeze(self):
     parts = list(SystemPart.get(self.database))
     # There can be other backups in the folder
     prev_backups = set(self._get_backups())
     for p in parts:
         p.freeze()
     backups = set(self._get_backups())
     self.assertEqual(len(backups), len(prev_backups) + 2)
 def test_freeze(self):
     parts = list(SystemPart.get(self.database))
     # There can be other backups in the folder
     prev_backups = set(self._get_backups())
     parts[0].freeze()
     backups = set(self._get_backups())
     self.assertEqual(len(backups), len(prev_backups) + 1)
     # Clean created backup
     shutil.rmtree(self.BACKUP_DIR + '{0}'.format(list(backups - prev_backups)[0]))
예제 #8
0
    def test_custom_primary_key(self):
        class TestModel(SampleModel):
            engine = MergeTree(
                order_by=('date', 'event_id', 'event_group'),
                partition_key=('toYYYYMM(date)',),
                primary_key=('date', 'event_id')
            )

        class TestCollapseModel(SampleModel):
            sign = Int8Field()

            engine = CollapsingMergeTree(
                sign_col='sign',
                order_by=('date', 'event_id', 'event_group'),
                partition_key=('toYYYYMM(date)',),
                primary_key=('date', 'event_id')
            )

        self._create_and_insert(TestModel)
        self._create_and_insert(TestCollapseModel)

        self.assertEqual(2, len(list(SystemPart.get(self.database))))
예제 #9
0
 def test_get_all(self):
     parts = SystemPart.get(self.database)
     self.assertEqual(len(list(parts)), 1)
 def test_get_all(self):
     parts = SystemPart.get(self.database)
     self.assertEqual(len(list(parts)), 2)