Beispiel #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)
Beispiel #2
0
 def test_attach_detach(self):
     parts = list(SystemPart.get_active(self.database))
     self.assertEqual(len(parts), 1)
     parts[0].detach()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
     parts[0].attach()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 1)
 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)
Beispiel #4
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_attach_detach(self):
     parts = list(SystemPart.get_active(self.database))
     self.assertEqual(len(parts), 2)
     for p in parts:
         p.detach()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
     for p in parts:
         p.attach()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 2)
 def test_attach_detach(self):
     parts = list(SystemPart.get_active(self.database))
     self.assertEqual(len(parts), 2)
     for p in parts:
         p.detach()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
     for p in parts:
         p.attach()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 2)
Beispiel #7
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(' ', ''))
Beispiel #8
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]))
    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))))
 def test_get_all(self):
     parts = SystemPart.get(self.database)
     self.assertEqual(len(list(parts)), 2)
Beispiel #13
0
 def test_drop(self):
     parts = list(SystemPart.get_active(self.database))
     parts[0].drop()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
 def test_drop(self):
     parts = list(SystemPart.get_active(self.database))
     for p in parts:
         p.drop()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
Beispiel #15
0
 def test_get_all(self):
     parts = SystemPart.get(self.database)
     self.assertEqual(len(list(parts)), 1)
Beispiel #16
0
 def test_query(self):
     SystemPart.objects_in(self.database).count()
     list(SystemPart.objects_in(self.database).filter(table='testtable'))
 def test_insert_system(self):
     m = SystemPart()
     with self.assertRaises(DatabaseException):
         self.database.insert([m])
 def test_get_active(self):
     parts = list(SystemPart.get_active(self.database))
     self.assertEqual(len(parts), 2)
     parts[0].detach()
     self.assertEqual(len(list(SystemPart.get_active(self.database))), 1)
Beispiel #19
0
 def test_get_active(self):
     parts = list(SystemPart.get_active(self.database))
     self.assertEqual(len(parts), 2)
     parts[0].detach()
     parts = list(SystemPart.get_active(self.database))
     self.assertEqual(len(parts), 1)
Beispiel #20
0
 def test_is_system_model(self):
     self.assertTrue(SystemPart.is_system_model())
Beispiel #21
0
 def test_is_read_only(self):
     self.assertTrue(SystemPart.is_read_only())