turbaszek commented on a change in pull request #9960:
URL: https://github.com/apache/airflow/pull/9960#discussion_r487567645



##########
File path: airflow/hooks/dbapi_hook.py
##########
@@ -132,14 +133,35 @@ def get_records(self, sql, parameters=None):
         :type sql: str or list
         :param parameters: The parameters to render the SQL query with.
         :type parameters: dict or iterable
+        :param first_only: Bool indicating whether to return full set or first 
record
+        :type first_only: bool
         """
+        if isinstance(sql, str):
+            sql = [sql]
         with closing(self.get_conn()) as conn:
             with closing(conn.cursor()) as cur:
-                if parameters is not None:
-                    cur.execute(sql, parameters)
+                for sql_statement in sql:
+                    if parameters is not None:
+                        cur.execute(sql_statement, parameters)
+                    else:
+                        cur.execute(sql_statement)
+                if first_only:
+                    return cur.fetchone()
                 else:
-                    cur.execute(sql)
-                return cur.fetchall()
+                    return cur.fetchall()
+
+
+    def get_records(self, sql, parameters=None):

Review comment:
       ```suggestion
       def get_records(self, sql: Union[str, List[str]], parameters: 
Optional[Dict] = None):
   ```

##########
File path: airflow/hooks/dbapi_hook.py
##########
@@ -132,14 +133,35 @@ def get_records(self, sql, parameters=None):
         :type sql: str or list
         :param parameters: The parameters to render the SQL query with.
         :type parameters: dict or iterable
+        :param first_only: Bool indicating whether to return full set or first 
record
+        :type first_only: bool
         """
+        if isinstance(sql, str):
+            sql = [sql]
         with closing(self.get_conn()) as conn:
             with closing(conn.cursor()) as cur:
-                if parameters is not None:
-                    cur.execute(sql, parameters)
+                for sql_statement in sql:
+                    if parameters is not None:
+                        cur.execute(sql_statement, parameters)
+                    else:
+                        cur.execute(sql_statement)
+                if first_only:
+                    return cur.fetchone()
                 else:
-                    cur.execute(sql)
-                return cur.fetchall()
+                    return cur.fetchall()
+
+
+    def get_records(self, sql, parameters=None):
+        """
+        Executes the sql and returns a set of records.
+
+        :param sql: the sql statement to be executed (str) or a list of
+            sql statements to execute
+        :type sql: str or list

Review comment:
       ```suggestion
           :type sql: Union[str, List[str]]
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to