flolas commented on a change in pull request #17329:
URL: https://github.com/apache/airflow/pull/17329#discussion_r702888607



##########
File path: tests/hooks/test_dbapi.py
##########
@@ -232,3 +233,74 @@ def handler(cur):
         assert called == 2
         assert self.conn.commit.called
         assert result == [obj, obj]
+
+    @patch('airflow.hooks.dbapi.DbApiHook._run_command')
+    def test_run_with_multiple_statements_and_split(self, _run_command):
+        _cases = [
+            (['SQL1; SQL2;', 'SQL3'], 3),
+            (['SQL1; SQL2;', 'SQL3;'], 3),
+            (['SQL1; SQL2; SQL3;'], 3),
+            ('SQL1; SQL2; SQL3;', 3),
+            (['SQL1;', 'SQL2'], 2),
+            (['SQL1;', 'SQL2;'], 2),
+            (['SQL1; SQL2;'], 2),
+            ('SQL1; SQL2;', 2),
+            (['SQL1'], 1),
+            (['SQL1;'], 1),
+            ('SQL1;', 1),
+            ('SQL1', 1),
+            (
+                """
+            CREATE OR REPLACE FUNCTION dfp.extract_vcode(NAME VARCHAR)
+                RETURNS string
+                LANGUAGE javascript
+                STRICT
+                AS '
+                const regex = /[[]v=([0-9]+)/ig;
+                let s = NAME.match(regex);
+                if (s != null) {
+                    return s[0].split('=')[1];
+                } else {
+                    return null;
+                }
+                ';
+                CREATE OR REPLACE FUNCTION dfp.parse_metadata(DATA varchar)
+                RETURNS OBJECT
+                LANGUAGE javascript
+                STRICT
+                AS '
+                if (!DATA) {
+                    return {}
+                }
+
+                let dict = {}
+                const parts = DATA.split("|")
+
+                parts.forEach((p) => {
+                    const split = p.split("=")
+                    dict[split[0]] = split[1]
+                })
+
+                return dict
+                ';
+            """,  # nopep8
+                2,
+            ),
+            (
+                """
+            SELECT
+                *
+            FROM country
+            LEFT JOIN city ON city.country_id = country.id
+            LEFT JOIN customer ON city.id = customer.city_id
+            LEFT JOIN call ON call.customer_id = customer.id;
+            SELECT country, count(*) FROM country
+            GROUP BY 1;
+            """,  # nopep8

Review comment:
       1) because the static checks fails without that because of E501 (long 
multiline string), if there is a better way, im open to change it.
   
   2) I think that is a good improvement for the test. Will do at the end of 
the day.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to