villebro commented on a change in pull request #10498:
URL: 
https://github.com/apache/incubator-superset/pull/10498#discussion_r466568237



##########
File path: tests/sqla_models_tests.py
##########
@@ -125,7 +129,11 @@ def test_extra_cache_keys(self, flask_g):
         )
         extra_cache_keys = table.get_extra_cache_keys(query_obj)
         self.assertTrue(table.has_extra_cache_key_calls(query_obj))
-        self.assertListEqual(extra_cache_keys, ["abc"])
+        # TODO: make it work with presto
+        if get_example_database().backend == "presto":
+            assert extra_cache_keys == []
+        else:
+            assert extra_cache_keys == ["abc"]

Review comment:
       Same here..

##########
File path: superset/examples/birth_names.py
##########
@@ -54,19 +54,26 @@ def gen_filter(
 
 def load_data(tbl_name: str, database: Database, sample: bool = False) -> None:
     pdf = pd.read_json(get_example_data("birth_names.json.gz"))
-    pdf.ds = pd.to_datetime(pdf.ds, unit="ms")
+    if database.backend == "presto":
+        pdf.ds = pd.to_datetime(pdf.ds, unit="ms")
+        pdf.ds = pdf.ds.dt.strftime("%Y-%m-%d %H:%M%:%S")
+    else:
+        pdf.ds = pd.to_datetime(pdf.ds, unit="ms")
     pdf = pdf.head(100) if sample else pdf
+
     pdf.to_sql(
         tbl_name,
         database.get_sqla_engine(),
         if_exists="replace",
         chunksize=500,
         dtype={
-            "ds": DateTime,
+            # TODO(bkyryliuk): use TIMESTAMP type for presto
+            "ds": DateTime if database.backend != "presto" else String(255),

Review comment:
       Same here, e.g. `get_examples_datetime_type()`. There are a few places 
below to which I feel the same applies.

##########
File path: superset/examples/birth_names.py
##########
@@ -54,19 +54,26 @@ def gen_filter(
 
 def load_data(tbl_name: str, database: Database, sample: bool = False) -> None:
     pdf = pd.read_json(get_example_data("birth_names.json.gz"))
-    pdf.ds = pd.to_datetime(pdf.ds, unit="ms")
+    if database.backend == "presto":
+        pdf.ds = pd.to_datetime(pdf.ds, unit="ms")
+        pdf.ds = pdf.ds.dt.strftime("%Y-%m-%d %H:%M%:%S")
+    else:
+        pdf.ds = pd.to_datetime(pdf.ds, unit="ms")

Review comment:
       This logic should ideally be moved out to `db_engine_specs/presto.py` to 
keep this clean of db-specific logic. Something along the lines of 
`BaseEngineSpec.convert_examples_datetime()` or similar (there are other 
similar methods there).

##########
File path: tests/database_api_tests.py
##########
@@ -222,7 +223,7 @@ def test_get_select_star_not_found_table(self):
             return
         uri = 
f"api/v1/database/{example_db.id}/select_star/table_does_not_exist/"
         rv = self.client.get(uri)
-        self.assertEqual(rv.status_code, 404)
+        self.assertEqual(rv.status_code, 404 if example_db.backend != "presto" 
else 500)

Review comment:
       I'd be interested in understanding why this is returning a 500. Perhaps 
add a TODO here so we can follow up on it.

##########
File path: tests/celery_tests.py
##########
@@ -174,8 +177,23 @@ def test_run_sync_query_cta(self, ctas_method):
         )
         # provide better error message
         self.assertEqual(QueryStatus.SUCCESS, result["query"]["state"], 
msg=result)
-        self.assertEqual([], result["data"])
-        self.assertEqual([], result["columns"])
+
+        expected_result = []
+        if backend == "presto":
+            expected_result = (
+                [{"rows": 1}] if ctas_method == CtasMethod.TABLE else 
[{"result": True}]
+            )
+        self.assertEqual(expected_result, result["data"])
+        expected_columns = []
+        if backend == "presto":
+            expected_columns = [
+                {
+                    "name": "rows" if ctas_method == CtasMethod.TABLE else 
"result",
+                    "type": "BIGINT" if ctas_method == CtasMethod.TABLE else 
"BOOLEAN",
+                    "is_date": False,
+                }
+            ]

Review comment:
       This also runs the risk of becoming convoluted if we introduce 
db-specific logic for all supported dbs. As this logic is repeated below, I 
think there is merit to centralizing this somewhere, too, but `db_engine_specs` 
probably isn't the right place for test assertion related stuff. I'm open to 
suggestions, but feel we can probably leave this as-is until we come up with a 
more scalable solution.

##########
File path: tests/sqla_models_tests.py
##########
@@ -93,7 +93,11 @@ def test_extra_cache_keys(self, flask_g):
         query_obj = dict(**base_query_obj, extras={})
         extra_cache_keys = table.get_extra_cache_keys(query_obj)
         self.assertTrue(table.has_extra_cache_key_calls(query_obj))
-        self.assertListEqual(extra_cache_keys, ["abc"])
+        # TODO: make it work with presto
+        if get_example_database().backend == "presto":
+            assert extra_cache_keys == []
+        else:
+            assert extra_cache_keys == ["abc"]

Review comment:
       hmm, I wonder why this is failing for presto. This really shouldn't have 
anything to do with the underlying analytical db type..




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to