Repository: great-expectations/great_expectations

Issue:
Use cleaner solution for non-truncating division in python 2
Prefer `from __future__ import division` to `1.*x/y`


Discussion:
Done inline during improve_partitions push.

Resolving patch:
diff --git a/great_expectations/execution_engine/sqlalchemy_batch_data.py b/great_expectations/execution_engine/sqlalchemy_batch_data.py
--- a/great_expectations/execution_engine/sqlalchemy_batch_data.py
+++ b/great_expectations/execution_engine/sqlalchemy_batch_data.py
@@ -113,7 +113,9 @@ def __init__(
         try:
             dialect: GESqlDialect = GESqlDialect(dialect_name)
         except ValueError:
-            dialect: GESqlDialect = GESqlDialect.UNSUPPORTED
+            dialect: GESqlDialect = GESqlDialect.OTHER
+
+        self._dialect = dialect
 
         if table_name:
             # Suggestion: pull this block out as its own _function
@@ -171,6 +173,10 @@ def __init__(
             else:
                 self._selectable = selectable.alias(self._record_set_name)
 
+    @property
+    def dialect(self) -> GESqlDialect:
+        return self._dialect
+
     @property
     def sql_engine_dialect(self) -> DefaultDialect:
         """Returns the Batches' current engine dialect"""
@@ -203,12 +209,8 @@ def _create_temporary_table(
         Create Temporary table based on sql query. This will be used as a basis for executing expectations.
         :param query:
         """
-        dialect_name: str = self.sql_engine_dialect.name.lower()
 
-        try:
-            dialect: GESqlDialect = GESqlDialect(dialect_name)
-        except ValueError:
-            dialect: GESqlDialect = GESqlDialect.UNSUPPORTED
+        dialect: GESqlDialect = self.dialect
 
         if dialect == GESqlDialect.BIGQUERY:
             # BigQuery Table is created using with an expiration of 24 hours using Google's Data Definition Language
diff --git a/great_expectations/execution_engine/sqlalchemy_dialect.py b/great_expectations/execution_engine/sqlalchemy_dialect.py
--- a/great_expectations/execution_engine/sqlalchemy_dialect.py
+++ b/great_expectations/execution_engine/sqlalchemy_dialect.py
@@ -22,7 +22,7 @@ class GESqlDialect(enum.Enum):
     SQLITE = "sqlite"
     TERADATASQL = "teradatasql"
     TRINO = "trino"
-    UNSUPPORTED = "unsupported"
+    OTHER = "other"
 
     @classmethod
     def _missing_(cls, value: Any) -> None:
@@ -38,10 +38,10 @@ def get_all_dialect_names(cls) -> List[str]:
         return [
             dialect_name.value
             for dialect_name in cls
-            if dialect_name != GESqlDialect.UNSUPPORTED
+            if dialect_name != GESqlDialect.OTHER
         ]
 
     @classmethod
     def get_all_dialects(cls) -> List[GESqlDialect]:
         """Get all dialects."""
-        return [dialect for dialect in cls if dialect != GESqlDialect.UNSUPPORTED]
+        return [dialect for dialect in cls if dialect != GESqlDialect.OTHER]


Test patch:
diff --git a/tests/execution_engine/test_sqlalchemy_batch_data.py b/tests/execution_engine/test_sqlalchemy_batch_data.py
--- a/tests/execution_engine/test_sqlalchemy_batch_data.py
+++ b/tests/execution_engine/test_sqlalchemy_batch_data.py
@@ -2,6 +2,7 @@
 
 from great_expectations.core.batch_spec import SqlAlchemyDatasourceBatchSpec
 from great_expectations.execution_engine import SqlAlchemyExecutionEngine
+from great_expectations.execution_engine.sqlalchemy_dialect import GESqlDialect
 
 try:
     sqlalchemy = pytest.importorskip("sqlalchemy")
@@ -134,3 +135,17 @@ def test_instantiation_with_and_without_temp_table(sqlite_view_engine, sa):
     )
     res = execution_engine.get_batch_data_and_markers(batch_spec=my_batch_spec)
     assert len(res) == 2
+
+
+@pytest.mark.unit
+def test_instantiation_with_unknown_dialect(sqlite_view_engine):
+    execution_engine: SqlAlchemyExecutionEngine = SqlAlchemyExecutionEngine(
+        engine=sqlite_view_engine
+    )
+    execution_engine.engine.dialect.name = "not_a_supported_dialect"
+    batch_data: SqlAlchemyBatchData = SqlAlchemyBatchData(
+        execution_engine=execution_engine,
+        table_name="test_table",
+    )
+
+    assert batch_data.dialect == GESqlDialect.OTHER
diff --git a/tests/execution_engine/test_sqlalchemy_dialect.py b/tests/execution_engine/test_sqlalchemy_dialect.py
--- a/tests/execution_engine/test_sqlalchemy_dialect.py
+++ b/tests/execution_engine/test_sqlalchemy_dialect.py
@@ -1,17 +1,23 @@
+import pytest
+
 from great_expectations.execution_engine.sqlalchemy_dialect import GESqlDialect
 
 
+@pytest.mark.unit
 def test_dialect_instantiation_with_string():
     assert GESqlDialect("hive") == GESqlDialect.HIVE
 
 
+@pytest.mark.unit
 def test_dialect_instantiation_with_byte_string():
     assert GESqlDialect(b"hive") == GESqlDialect.HIVE
 
 
-def test_get_all_dialect_names_no_unsupported():
-    assert GESqlDialect.UNSUPPORTED.value not in GESqlDialect.get_all_dialect_names()
+@pytest.mark.unit
+def test_get_all_dialect_names_no_other_dialects():
+    assert GESqlDialect.OTHER.value not in GESqlDialect.get_all_dialect_names()
 
 
-def test_get_all_dialects_no_unsupported():
-    assert GESqlDialect.UNSUPPORTED not in GESqlDialect.get_all_dialects()
+@pytest.mark.unit
+def test_get_all_dialects_no_other_dialects():
+    assert GESqlDialect.OTHER not in GESqlDialect.get_all_dialects()
diff --git a/tests/execution_engine/test_sqlalchemy_execution_engine.py b/tests/execution_engine/test_sqlalchemy_execution_engine.py
--- a/tests/execution_engine/test_sqlalchemy_execution_engine.py
+++ b/tests/execution_engine/test_sqlalchemy_execution_engine.py
@@ -11,6 +11,7 @@
 )
 from great_expectations.core.metric_domain_types import MetricDomainTypes
 from great_expectations.data_context.util import file_relative_path
+from great_expectations.execution_engine.sqlalchemy_dialect import GESqlDialect
 from great_expectations.execution_engine.sqlalchemy_execution_engine import (
     SqlAlchemyExecutionEngine,
 )
@@ -23,6 +24,7 @@
 from great_expectations.self_check.util import build_sa_engine
 from great_expectations.util import get_sqlalchemy_domain_data
 from great_expectations.validator.metric_configuration import MetricConfiguration
+from great_expectations.validator.validator import Validator
 from tests.expectations.test_util import get_table_columns_metric
 from tests.test_utils import get_sqlite_table_names, get_sqlite_temp_table_names
 
@@ -69,6 +71,42 @@ def test_instantiation_via_url(sa):
     )
 
 
+@pytest.mark.integration
+def test_instantiation_via_url_and_retrieve_data_with_other_dialect(sa):
+    """Ensure that we can still retrieve data when the dialect is not recognized."""
+
+    # 1. Create engine with sqlite db
+    db_file = file_relative_path(
+        __file__,
+        os.path.join("..", "test_sets", "test_cases_for_sql_data_connector.db"),
+    )
+    my_execution_engine = SqlAlchemyExecutionEngine(url="sqlite:///" + db_file)
+    assert my_execution_engine.connection_string is None
+    assert my_execution_engine.credentials is None
+    assert my_execution_engine.url[-36:] == "test_cases_for_sql_data_connector.db"
+
+    # 2. Change dialect to one not listed in GESqlDialect
+    my_execution_engine.engine.dialect.name = "other_dialect"
+
+    # 3. Get data
+    num_rows_in_sample: int = 10
+    batch_data, _ = my_execution_engine.get_batch_data_and_markers(
+        batch_spec=SqlAlchemyDatasourceBatchSpec(
+            table_name="table_partitioned_by_date_column__A",
+            sampling_method="_sample_using_limit",
+            sampling_kwargs={"n": num_rows_in_sample},
+        )
+    )
+
+    # 4. Assert dialect and data are as expected
+
+    assert batch_data.dialect == GESqlDialect.OTHER
+
+    my_execution_engine.load_batch_data("__", batch_data)
+    validator = Validator(my_execution_engine)
+    assert len(validator.head(fetch_all=True)) == num_rows_in_sample
+
+
 def test_instantiation_via_credentials(sa, test_backends, test_df):
     if "postgresql" not in test_backends:
         pytest.skip("test_database_store_backend_get_url_for_key requires postgresql")