def visit_insert(self, statement: AbstractStatement): """Converter for parsed insert statement Arguments: statement {AbstractStatement} -- [input insert statement] """ # Bind the table reference video = statement.table catalog_table_id = bind_table_ref(video.table_info) # Bind column_list col_list = statement.column_list for col in col_list: if col.table_name is None: col.table_name = video.table_info.table_name if col.table_metadata_id is None: col.table_metadata_id = catalog_table_id bind_columns_expr(col_list, {}) # Nothing to be done for values as we add support for other variants of # insert we will handle them value_list = statement.value_list # Ready to create Logical node insert_opr = LogicalInsert( video, catalog_table_id, col_list, value_list) self._plan = insert_opr
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_false_for_unequal_plans(self): create_plan = LogicalCreate(TableRef(TableInfo('video')), [MagicMock()]) create_udf_plan = LogicalCreateUDF('udf', False, None, None, None) insert_plan = LogicalInsert(MagicMock(), 0, [MagicMock()], [MagicMock()]) query_derived_plan = LogicalQueryDerivedGet() load_plan = LogicalLoadData(MagicMock(), MagicMock()) self.assertEqual(create_plan, create_plan) self.assertEqual(create_udf_plan, create_udf_plan) self.assertNotEqual(create_plan, create_udf_plan) self.assertNotEqual(create_udf_plan, create_plan) create_plan.append_child(create_udf_plan) self.assertNotEqual(create_plan, create_udf_plan) self.assertNotEqual(query_derived_plan, create_plan) self.assertNotEqual(insert_plan, query_derived_plan) self.assertNotEqual(load_plan, insert_plan)
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()