zhongjiajie commented on a change in pull request #4584: [AIRFLOW-3741] Add
extra config to Oracle hook
URL: https://github.com/apache/airflow/pull/4584#discussion_r251024458
##########
File path: airflow/hooks/oracle_hook.py
##########
@@ -128,13 +181,33 @@ def bulk_insert_rows(self, table, rows,
target_fields=None, commit_every=5000):
A performant bulk insert for cx_Oracle
that uses prepared statements via `executemany()`.
For best performance, pass in `rows` as an iterator.
+
+ :param table: target Oracle table, use dot notation to target a
+ specific database
+ :type table: str
+ :param rows: the rows to insert into the table
+ :type rows: iterable of tuples
+ :param target_fields: the names of the columns to fill in the table,
default None.
+ If None, each rows should have some order as table columns name
+ :type target_fields: iterable of str Or None
+ :param commit_every: the maximum number of rows to insert in one
transaction
+ Default 5000. Set greater than 0. Set 1 to insert each row in each
transaction
+ :type commit_every: int
"""
+ if not rows:
+ raise ValueError("rows could not be null or None.")
conn = self.get_conn()
cursor = conn.cursor()
- values = ', '.join(':%s' % i for i in range(1, len(target_fields) + 1))
- prepared_stm = 'insert into {tablename} ({columns}) values
({values})'.format(
+ if target_fields:
Review comment:
@ashb This change ref the sub commit message
> Fix Oracle hook bulk_insert_rows bug
when target_fields use default None
value
Old code define `target_fields=None` but when target_fields is None both
https://github.com/apache/airflow/blob/2c7bb17435926628914571f14dad3c45bc53753b/airflow/hooks/oracle_hook.py#L136
and
https://github.com/apache/airflow/blob/2c7bb17435926628914571f14dad3c45bc53753b/airflow/hooks/oracle_hook.py#L139
will raise Error
So this is to fix that
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services