def test_should_return_the_new_path_after_execution(self, mock_class): class_instatnce = mock_class.return_value dummy_expr = type('dummy_expr', (), {"evaluate": lambda x=None: [True, False, True]}) # Build plan tree video = DataFrameMetadata("dataset", "dummy.avi") batch_1 = Batch(pd.DataFrame({'data': [1, 2, 3]})) batch_2 = Batch(pd.DataFrame({'data': [4, 5, 6]})) class_instatnce.load.return_value = map(lambda x: x, [batch_1, batch_2]) storage_plan = StoragePlan(video) seq_scan = SeqScanPlan(predicate=dummy_expr, column_ids=[]) seq_scan.append_child(storage_plan) # Execute the plan executor = PlanExecutor(seq_scan) actual = executor.execute_plan() expected = batch_1[::2] + batch_2[::2] mock_class.assert_called_once() self.assertEqual(expected, actual)
def test_should_return_the_new_path_after_execution(self, mock_class): class_instatnce = mock_class.return_value dummy_expr = type('dummy_expr', (), {"evaluate": lambda x=None: [True, False, True]}) # Build plan tree video = VideoMetaInfo("dummy.avi", 10, VideoFormat.AVI) class_instatnce.load.return_value = map(lambda x: x, [ FrameBatch([1, 2, 3], None), FrameBatch([4, 5, 6], None)]) storage_plan = StoragePlan(video) seq_scan = SeqScanPlan(predicate=dummy_expr) seq_scan.append_child(storage_plan) # Execute the plan executor = PlanExecutor(seq_scan) actual = executor.execute_plan() expected = [ FrameBatch([1, 3], None), FrameBatch([4, 6], None)] mock_class.assert_called_once() self.assertEqual( expected, actual )
def test_calling_storage_executor_should_return_batches(self, mock_class): class_instance = mock_class.return_value video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG) storage_plan = StoragePlan(video_info) executor = DiskStorageExecutor(storage_plan) class_instance.load.return_value = range(5) actual = list(executor.next()) mock_class.assert_called_once_with( video_info, batch_size=storage_plan.batch_size, limit=storage_plan.limit, offset=storage_plan.offset, skip_frames=storage_plan.skip_frames) class_instance.load.assert_called_once() self.assertEqual(list(range(5)), actual)
def test_calling_storage_executor_should_return_batches(self, mock_class): class_instance = mock_class.return_value video_info = DataFrameMetadata('dataset', 'dummy.avi') storage_plan = StoragePlan(video_info) executor = DiskStorageExecutor(storage_plan) class_instance.load.return_value = range(5) actual = list(executor.exec()) mock_class.assert_called_once_with( video_info, batch_size=storage_plan.batch_size, limit=storage_plan.limit, offset=storage_plan.offset, skip_frames=(storage_plan.skip_frames), total_shards=0, curr_shard=0) class_instance.load.assert_called_once() self.assertEqual(list(range(5)), actual)
def _visit_logical_get(self, operator: LogicalGet): self._plan = StoragePlan(operator.dataset_metadata)
def apply(self, before: LogicalGet, context: OptimizerContext): after = SeqScanPlan(before.predicate, before.target_list) after.append_child(StoragePlan(before.dataset_metadata)) return after