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 _build_execution_tree(self, plan: AbstractPlan) -> AbstractExecutor: """build the execution tree from plan tree Arguments: plan {AbstractPlan} -- Input Plan tree Returns: AbstractExecutor -- Compiled Execution tree """ root = None if plan is None: return root # Get plan node type plan_node_type = plan.node_type if plan_node_type == PlanNodeType.SEQUENTIAL_SCAN: executor_node = SequentialScanExecutor(node=plan) elif plan_node_type == PlanNodeType.PP_FILTER: executor_node = PPExecutor(node=plan) elif plan_node_type == PlanNodeType.CREATE: executor_node = CreateExecutor(node=plan) elif plan_node_type == PlanNodeType.INSERT: executor_node = InsertExecutor(node=plan) elif plan_node_type == PlanNodeType.CREATE_UDF: executor_node = CreateUDFExecutor(node=plan) elif plan_node_type == PlanNodeType.LOAD_DATA: executor_node = LoadDataExecutor(node=plan) # Build Executor Tree for children for children in plan.children: executor_node.append_child(self._build_execution_tree(children)) return executor_node
def _build_execution_tree(self, plan: AbstractPlan) -> AbstractExecutor: """build the execution tree from plan tree Arguments: plan {AbstractPlan} -- Input Plan tree Returns: AbstractExecutor -- Compiled Execution tree """ root = None if plan is None: return root # Get plan node type plan_opr_type = plan.opr_type if plan_opr_type == PlanOprType.SEQUENTIAL_SCAN: executor_node = SequentialScanExecutor(node=plan) elif plan_opr_type == PlanOprType.UNION: executor_node = UnionExecutor(node=plan) elif plan_opr_type == PlanOprType.STORAGE_PLAN: executor_node = StorageExecutor(node=plan) elif plan_opr_type == PlanOprType.PP_FILTER: executor_node = PPExecutor(node=plan) elif plan_opr_type == PlanOprType.CREATE: executor_node = CreateExecutor(node=plan) elif plan_opr_type == PlanOprType.INSERT: executor_node = InsertExecutor(node=plan) elif plan_opr_type == PlanOprType.CREATE_UDF: executor_node = CreateUDFExecutor(node=plan) elif plan_opr_type == PlanOprType.LOAD_DATA: executor_node = LoadDataExecutor(node=plan) elif plan_opr_type == PlanOprType.ORDER_BY: executor_node = OrderByExecutor(node=plan) elif plan_opr_type == PlanOprType.LIMIT: executor_node = LimitExecutor(node=plan) elif plan_opr_type == PlanOprType.SAMPLE: executor_node = SampleExecutor(node=plan) # Build Executor Tree for children for children in plan.children: executor_node.append_child(self._build_execution_tree(children)) return executor_node