This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch VIZ-1202
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git

commit 991e284a65dac17d7e9b0d15f965b8470643b056
Author: Beto Dealmeida <[email protected]>
AuthorDate: Mon Nov 25 16:16:54 2019 -0800

    Add unit test
---
 tests/db_engine_specs/presto_tests.py | 65 ++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/tests/db_engine_specs/presto_tests.py 
b/tests/db_engine_specs/presto_tests.py
index bfb0322..fbb9430 100644
--- a/tests/db_engine_specs/presto_tests.py
+++ b/tests/db_engine_specs/presto_tests.py
@@ -19,9 +19,9 @@ from unittest import mock, skipUnless
 import pandas as pd
 from sqlalchemy.engine.result import RowProxy
 from sqlalchemy.sql import select
+from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
 
 from superset.db_engine_specs.presto import PrestoEngineSpec
-from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
 
 
 class PrestoTests(DbEngineSpecTestCase):
@@ -372,3 +372,66 @@ class PrestoTests(DbEngineSpecTestCase):
             PrestoEngineSpec.convert_dttm("TIMESTAMP", dttm),
             "from_iso8601_timestamp('2019-01-02T03:04:05.678900')",
         )
+
+    def test_query_cost_formatter(self):
+        raw_cost = [
+            {
+                "inputTableColumnInfos": [
+                    {
+                        "table": {
+                            "catalog": "hive",
+                            "schemaTable": {
+                                "schema": "default",
+                                "table": "fact_passenger_state",
+                            },
+                        },
+                        "columnConstraints": [
+                            {
+                                "columnName": "ds",
+                                "typeSignature": "varchar",
+                                "domain": {
+                                    "nullsAllowed": False,
+                                    "ranges": [
+                                        {
+                                            "low": {
+                                                "value": "2019-07-10",
+                                                "bound": "EXACTLY",
+                                            },
+                                            "high": {
+                                                "value": "2019-07-10",
+                                                "bound": "EXACTLY",
+                                            },
+                                        }
+                                    ],
+                                },
+                            }
+                        ],
+                        "estimate": {
+                            "outputRowCount": 9.04969899e8,
+                            "outputSizeInBytes": 3.54143678301e11,
+                            "cpuCost": 3.54143678301e11,
+                            "maxMemory": 0.0,
+                            "networkCost": 0.0,
+                        },
+                    }
+                ],
+                "estimate": {
+                    "outputRowCount": 9.04969899e8,
+                    "outputSizeInBytes": 3.54143678301e11,
+                    "cpuCost": 3.54143678301e11,
+                    "maxMemory": 0.0,
+                    "networkCost": 3.54143678301e11,
+                },
+            }
+        ]
+        formatted_cost = PrestoEngineSpec.query_cost_formatter(raw_cost)
+        expected = [
+            {
+                "Output count": "904 M rows",
+                "Output size": "354 GB",
+                "CPU cost": "354 G",
+                "Max memory": "0 B",
+                "Network cost": "354 G",
+            }
+        ]
+        self.assertEqual(formatted_cost, expected)

Reply via email to