def test_build_execution_tree_should_create_correct_exec_node(self): # SequentialScanExecutor plan = SeqScanPlan(MagicMock(), []) executor = PlanExecutor(plan)._build_execution_tree(plan) self.assertIsInstance(executor, SequentialScanExecutor) # PPExecutor plan = PPScanPlan(MagicMock()) executor = PlanExecutor(plan)._build_execution_tree(plan) self.assertIsInstance(executor, PPExecutor) # CreateExecutor plan = CreatePlan(MagicMock(), [], False) executor = PlanExecutor(plan)._build_execution_tree(plan) self.assertIsInstance(executor, CreateExecutor) # InsertExecutor plan = InsertPlan(0, [], []) executor = PlanExecutor(plan)._build_execution_tree(plan) self.assertIsInstance(executor, InsertExecutor) # CreateUDFExecutor plan = CreateUDFPlan('test', False, [], [], MagicMock(), None) executor = PlanExecutor(plan)._build_execution_tree(plan) self.assertIsInstance(executor, CreateUDFExecutor) # LoadDataExecutor plan = LoadDataPlan(MagicMock(), MagicMock()) executor = PlanExecutor(plan)._build_execution_tree(plan) self.assertIsInstance(executor, LoadDataExecutor)
def test_insert_plan(self): video_id = 0 column_ids = [0, 1] expression = type("AbstractExpression", (), {"evaluate": lambda: 1}) values = [expression, expression] dummy_plan_node = InsertPlan(video_id, column_ids, values) self.assertEqual(dummy_plan_node.node_type, PlanNodeType.INSERT)
def test_should_insert_row_in_table(self): dummy_info = TableInfo('MyVideo') dummy_table = TableRef(dummy_info) columns = [ DataFrameColumn('Frame_ID', ColumnType.INTEGER), DataFrameColumn('Frame_Path', ColumnType.TEXT, array_dimensions=50) ] plan_node = CreatePlan(dummy_table, columns, False) createExec = CreateExecutor(plan_node) url = createExec.exec() parser = Parser() insert_query = """INSERT INTO MyVideo (Frame_ID, Frame_Path) VALUES (1, '/mnt/frames/1.png'); """ eva_statement_list = parser.parse(insert_query) insert_stmt = eva_statement_list[0] convertor = StatementToPlanConvertor() convertor.visit(insert_stmt) logical_plan_node = convertor.plan print("logical", logical_plan_node) phy_plan_node = InsertPlan(logical_plan_node.video_catalog_id, logical_plan_node.column_list, logical_plan_node.value_list) insertExec = InsertExecutor(phy_plan_node) insertExec.exec() # test if we have a added the in our storage df = load_dataframe(url) self.assertEqual(df.collect()[0][0], 1) self.assertEqual(df.collect()[0][1], "'/mnt/frames/1.png'")
def test_execute_plan_for_create_insert_load_plans(self, mock_batch, mock_clean, mock_build): mock_batch.return_value = [] # CreateExecutor tree = MagicMock(node=CreatePlan(None, [], False)) mock_build.return_value = tree actual = PlanExecutor(None).execute_plan() tree.exec.assert_called_once() mock_batch.assert_called_once() assert_frame_equal(mock_batch.call_args[0][0], pd.DataFrame()) mock_build.assert_called_once_with(None) mock_clean.assert_called_once() self.assertEqual(actual, []) # InsertExecutor mock_batch.reset_mock() mock_build.reset_mock() mock_clean.reset_mock() tree = MagicMock(node=InsertPlan(0, [], [])) mock_build.return_value = tree actual = PlanExecutor(None).execute_plan() tree.exec.assert_called_once() mock_batch.assert_called_once() assert_frame_equal(mock_batch.call_args[0][0], pd.DataFrame()) mock_build.assert_called_once_with(None) mock_clean.assert_called_once() self.assertEqual(actual, []) # CreateUDFExecutor mock_batch.reset_mock() mock_build.reset_mock() mock_clean.reset_mock() tree = MagicMock(node=CreateUDFPlan(None, False, [], [], None)) mock_build.return_value = tree actual = PlanExecutor(None).execute_plan() tree.exec.assert_called_once() mock_batch.assert_called_once() assert_frame_equal(mock_batch.call_args[0][0], pd.DataFrame()) mock_build.assert_called_once_with(None) mock_clean.assert_called_once() self.assertEqual(actual, []) # LoadDataExecutor mock_batch.reset_mock() mock_build.reset_mock() mock_clean.reset_mock() tree = MagicMock(node=LoadDataPlan(None, None)) mock_build.return_value = tree actual = PlanExecutor(None).execute_plan() tree.exec.assert_called_once() mock_batch.assert_called_once() assert_frame_equal(mock_batch.call_args[0][0], pd.DataFrame()) mock_build.assert_called_once_with(None) mock_clean.assert_called_once() self.assertEqual(actual, [])
def build(self, operator: Operator): self.__init__() self._visit(operator) insert_plan = InsertPlan(self._table_id, self._col_list, self._val_list) return insert_plan
def apply(self, before: LogicalInsert, context: OptimizerContext): after = InsertPlan(before.video_catalog_id, before.column_list, before.value_list) return after