def test_should_return_only_frames_satisfy_predicate(self):
        dataframe = create_dataframe(3)
        batch = FrameBatch(frames=dataframe)
        expression = type("AbstractExpression", (), {"evaluate": lambda x: [
            False, False, True]})

        plan = type("PPScanPlan", (), {"predicate": expression})
        predicate_executor = PPExecutor(plan)
        predicate_executor.append_child(DummyExecutor([batch]))

        expected = batch[[2]]
        filtered = list(predicate_executor.exec())[0]
        self.assertEqual(expected, filtered)
Beispiel #2
0
    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
Beispiel #3
0
    def test_should_return_only_frames_satisfy_predicate(self):
        frame_1 = Frame(1, np.ones((1, 1)), None)
        frame_2 = Frame(1, 2 * np.ones((1, 1)), None)
        frame_3 = Frame(1, 3 * np.ones((1, 1)), None)
        batch = FrameBatch(frames=[
            frame_1,
            frame_2,
            frame_3,
        ], info=None)
        expression = type("AbstractExpression", (),
                          {"evaluate": lambda x: [False, False, True]})

        plan = type("PPScanPlan", (), {"predicate": expression})
        predicate_executor = PPExecutor(plan)
        predicate_executor.append_child(DummyExecutor([batch]))

        expected = FrameBatch(frames=[frame_3], info=None)
        filtered = list(predicate_executor.exec())[0]
        self.assertEqual(expected, filtered)
Beispiel #4
0
    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