Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ def column_names(self) -> list[str]:
return self.columns

def _process_rows(self, context: Context):
return self._rows_processor(context, self.rows) # type: ignore
return self._rows_processor(self.rows, **context) # type: ignore

def execute(self, context: Context) -> Any:
if not self.rows:
Expand Down
30 changes: 30 additions & 0 deletions providers/common/sql/tests/unit/common/sql/operators/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
SQLCheckOperator,
SQLColumnCheckOperator,
SQLExecuteQueryOperator,
SQLInsertRowsOperator,
SQLIntervalCheckOperator,
SQLTableCheckOperator,
SQLThresholdCheckOperator,
Expand Down Expand Up @@ -1577,3 +1578,32 @@ def test_new_style_subclass(self, mock_get_connection, operator_class):
mock_get_connection.return_value.get_hook.return_value = MagicMock(spec=DbApiHook)
op.get_db_hook()
mock_get_connection.assert_called_once_with("test_conn")


class TestSQLInsertRowsOperator:
@mock.patch.object(SQLInsertRowsOperator, "get_db_hook")
def test_rows_processor(self, mock_get_db_hook):
operator = SQLInsertRowsOperator(
task_id="test_task",
conn_id="default_conn",
schema="hollywood",
table_name="actors",
rows=[
{"index": 1, "name": "Stallone", "firstname": "Sylvester", "age": 78},
{"index": 2, "name": "Statham", "firstname": "Jason", "age": 57},
{"index": 3, "name": "Li", "firstname": "Jet", "age": 61},
{"index": 4, "name": "Lundgren", "firstname": "Dolph", "age": 66},
{"index": 5, "name": "Norris", "firstname": "Chuck", "age": 84},
],
rows_processor=lambda rows, **context: map(lambda row: tuple(row.values()), rows),
)

processed_rows = list(operator._process_rows({}))

assert processed_rows == [
(1, "Stallone", "Sylvester", 78),
(2, "Statham", "Jason", 57),
(3, "Li", "Jet", 61),
(4, "Lundgren", "Dolph", 66),
(5, "Norris", "Chuck", 84),
]