You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/09/07 09:12:59 UTC

[GitHub] [airflow] potiuk commented on a change in pull request #17329: Split sql statements in DbApi run

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



##########
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:
       I think in many editors you have to set it manually (Intellij https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000617684-Configuring-PEP8-not-ignoring-rules-really-changing-it-#:~:text=The%20PEP8%20limit%20in%20PyCharm,(and%2072%20for%20comments).) 
   
   PEP8 is flexible around line length and indeed we "strongly prefer a bit longer line"




-- 
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: commits-unsubscribe@airflow.apache.org

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