def test_should_not_call_insert_generator_for_other_types( self, mock_class): PlanGenerator().build(Operator(None)) PlanGenerator().build(Operator(LogicalFilter(None))) PlanGenerator().build(Operator(LogicalGet(None, 1))) PlanGenerator().build(Operator(LogicalProject([]))) mock_class.assert_not_called()
def test_should_return_correct_plan_tree_for_input_logical_tree(self): logical_plan = LogicalInsert("video", 1, [1, 2], [3, 4]) plan = PlanGenerator().build(logical_plan) self.assertIsInstance(plan, InsertPlan) self.assertEqual(plan.video_id, 1) self.assertEqual(plan.column_list, [1, 2]) self.assertEqual(plan.value_list, [3, 4])
def test_should_return_correct_plan_tree_for_input_logical_tree(self): logical_plan = LogicalCreate("video", [1, 2], True) plan = PlanGenerator().build(logical_plan) self.assertIsInstance(plan, CreatePlan) self.assertEqual(plan.video_ref, 'video') self.assertEqual(plan.column_list, [1, 2]) self.assertEqual(plan.if_not_exists, True)
def handle_request(transport, request_message): """ Reads a request from a client and processes it If user inputs 'quit' stops the event loop otherwise just echoes user input """ LoggingManager().log('Receive request: --|' + str(request_message) + '|--') output_batch = None response = None try: stmt = Parser().parse(request_message)[0] l_plan = StatementToPlanConvertor().visit(stmt) p_plan = PlanGenerator().build(l_plan) output_batch = PlanExecutor(p_plan).execute_plan() except Exception as e: LoggingManager().log(e, LoggingLevel.WARNING) response = Response(status=ResponseStatus.FAIL, batch=None) if response is None: response = Response(status=ResponseStatus.SUCCESS, batch=output_batch) responseData = response.to_json() # Send data length, because response can be very large data = (str(len(responseData)) + '|' + responseData).encode('ascii') LoggingManager().log('Response to client: --|' + str(response) + '|--\n' + 'Length: ' + str(len(responseData))) transport.write(data) return response
def test_should_return_correct_plan_tree_for_input_logical_tree(self): logical_plan = LogicalLoadData('metainfo', 'path') plan = PlanGenerator().build(logical_plan) self.assertIsInstance(plan, LoadDataPlan) self.assertEqual(plan.table_metainfo, 'metainfo') self.assertEqual(plan.file_path, 'path')
def execute_query(query) -> Iterator[Batch]: """ Execute the query and return a result generator. """ stmt = Parser().parse(query)[0] l_plan = StatementToPlanConvertor().visit(stmt) p_plan = PlanGenerator().build(l_plan) return PlanExecutor(p_plan).execute_plan()
def test_should_return_correct_plan_tree_for_input_logical_tree(self): logical_plan = LogicalCreateUDF('udf', True, ['inp'], ['out'], 'tmp') plan = PlanGenerator().build(logical_plan) self.assertIsInstance(plan, CreateUDFPlan) self.assertEqual(plan.name, 'udf') self.assertEqual(plan.inputs, ['inp']) self.assertEqual(plan.outputs, ['out']) self.assertEqual(plan.impl_path, 'tmp') self.assertEqual(plan.if_not_exists, True)
def handle_request(transport, query): """ Reads a request from a client and processes it If user inputs 'quit' stops the event loop otherwise just echoes user input """ parser = Parser() eva_statement = parser.parse(query) insert_statement = eva_statement[0] LoggingManager().log("Result from the parser: " + str(insert_statement)) convertor = StatementToPlanConvertor() convertor.visit(insert_statement) convertor.plan eva_statement = parser.parse(query) response_message = "" for i in range(len(eva_statement)): LoggingManager().log("Parse Tree: " + str(eva_statement[i])) logical_plan = StatementToPlanConvertor().visit(eva_statement[i]) physical_plan = PlanGenerator().build(logical_plan) df = PlanExecutor(physical_plan).execute_plan() statement_response_message = ','.join(map(str, df.collect())) response_message += statement_response_message LoggingManager().log('Response to client: --|' + str(response_message) + '|--') data = response_message.encode('ascii') transport.write(data) return response_message
def handle_request(transport, query): """ Reads a request from a client and processes it If user inputs 'quit' stops the event loop otherwise just echoes user input """ parser = Parser() eva_statement = parser.parse(query) for i in range(len(eva_statement)): LoggingManager().log("Result from the parser: " + str(eva_statement[i])) logical_plan = StatementToPlanConvertor().visit(eva_statement[i]) physical_plan = PlanGenerator().build(logical_plan) PlanExecutor(physical_plan).execute_plan() table_name = 'MyVideo' file_url = os.path.join(tempfile.gettempdir(), table_name) file_url = 'file://' + file_url df = load_dataframe(file_url) response_message = ','.join(map(str, df.collect())) LoggingManager().log("Response received" + str(response_message)) LoggingManager().log('Response to client: --|' + str(response_message) + '|--') data = response_message.encode('ascii') transport.write(data) return response_message
def test_should_return_use_insert_generator_for_logical_insert( self, mock_class): mock_instance = mock_class.return_value l_insert = LogicalInsert(None, 1, [], []) PlanGenerator().build(l_insert) mock_instance.build.assert_called_with(l_insert)
def test_should_not_call_scan_generator_for_other_types(self, mock_class): PlanGenerator().build(Operator(None)) PlanGenerator().build(LogicalInsert(None, 1, [], [])) mock_class.assert_not_called()
def test_should_return_use_scan_generator_for_logical_limit(self, mock_class): mock_instance = mock_class.return_value l_limit = LogicalLimit(None) PlanGenerator().build(l_limit) mock_instance.build.assert_called_with(l_limit)
def test_should_return_use_scan_generator_for_logical_orderby(self, mock_class): mock_instance = mock_class.return_value l_orderby = LogicalOrderBy(None) PlanGenerator().build(l_orderby) mock_instance.build.assert_called_with(l_orderby)
def test_should_return_use_scan_generator_for_logical_union(self, mock_class): mock_instance = mock_class.return_value l_union = LogicalUnion(True, None) PlanGenerator().build(l_union) mock_instance.build.assert_called_with(l_union)
def test_should_return_use_scan_generator_for_logical_project(self, mock_class): mock_instance = mock_class.return_value l_project = LogicalProject([]) PlanGenerator().build(l_project) mock_instance.build.assert_called_with(l_project)
def perform_query(query): stmt = Parser().parse(query)[0] l_plan = StatementToPlanConvertor().visit(stmt) p_plan = PlanGenerator().build(l_plan) return PlanExecutor(p_plan).execute_plan()
def test_should_call_create_udf_generator_for_logical_create_udf( self, mock): mock_instance = mock.return_value l_create_udf = LogicalCreateUDF('udf', True, [], [], 'tmp') PlanGenerator().build(l_create_udf) mock_instance.build.assert_called_with(l_create_udf)
def test_should_Call_load_data_generator(self, mock): mock_instance = mock.return_value l_load_Data = LogicalLoadData('meta_info', 'path') PlanGenerator().build(l_load_Data) mock_instance.build.assert_called_with(l_load_Data)