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_execution_engine.py b/great_expectations/execution_engine/sqlalchemy_execution_engine.py
--- a/great_expectations/execution_engine/sqlalchemy_execution_engine.py
+++ b/great_expectations/execution_engine/sqlalchemy_execution_engine.py
@@ -480,6 +480,14 @@ def get_domain_records(
         else:
             selectable = data_object.selectable
 
+        """
+        If a custom query is passed, selectable will be TextClause and not formatted
+        as a subquery wrapped in "(subquery) alias". TextClause must first be converted
+        to TextualSelect using sa.columns() before it can be converted to type Subquery
+        """
+        if TextClause and isinstance(selectable, TextClause):
+            selectable = selectable.columns().subquery()
+
         # Filtering by row condition.
         if (
             "row_condition" in domain_kwargs
@@ -490,10 +498,11 @@ def get_domain_records(
                 parsed_condition = parse_condition_to_sqlalchemy(
                     domain_kwargs["row_condition"]
                 )
-                selectable = sa.select(
-                    "*", from_obj=selectable, whereclause=parsed_condition
+                selectable = (
+                    sa.select(sa.text("*"))
+                    .select_from(selectable)
+                    .where(parsed_condition)
                 )
-
             else:
                 raise GreatExpectationsError(
                     "SqlAlchemyExecutionEngine only supports the great_expectations condition_parser."
@@ -1082,6 +1091,11 @@ def get_batch_data_and_markers(
 
         create_temp_table: bool = batch_spec.get(
             "create_temp_table", self._create_temp_table
+        ) and (
+            self.engine.dialect.name.lower()
+            not in [
+                "trino",
+            ]
         )
 
         if isinstance(batch_spec, RuntimeQueryBatchSpec):
diff --git a/great_expectations/execution_engine/util.py b/great_expectations/execution_engine/util.py
--- a/great_expectations/execution_engine/util.py
+++ b/great_expectations/execution_engine/util.py
@@ -10,12 +10,8 @@
 
 try:
     import sqlalchemy
-    from sqlalchemy.engine.default import DefaultDialect
-    from sqlalchemy.sql.elements import WithinGroup
 except ImportError:
     logger.debug("Unable to load SqlAlchemy or one of its subclasses.")
-    DefaultDialect = None
-    WithinGroup = None
 
 
 def is_valid_partition_object(partition_object):
diff --git a/great_expectations/expectations/metrics/util.py b/great_expectations/expectations/metrics/util.py
--- a/great_expectations/expectations/metrics/util.py
+++ b/great_expectations/expectations/metrics/util.py
@@ -1,5 +1,5 @@
 import logging
-from typing import Any, Dict, List, Optional, Set
+from typing import Any, Dict, List, Optional
 
 import numpy as np
 from dateutil.parser import parse


Test patch:
diff --git a/tests/datasource/test_new_datasource_with_runtime_data_connector.py b/tests/datasource/test_new_datasource_with_runtime_data_connector.py
--- a/tests/datasource/test_new_datasource_with_runtime_data_connector.py
+++ b/tests/datasource/test_new_datasource_with_runtime_data_connector.py
@@ -1021,7 +1021,7 @@ def test_batch_identifiers_and_batch_identifiers_success_no_temp_table(
     datasource_with_runtime_data_connector_and_sqlalchemy_execution_engine, sa
 ):
     # interacting with the database using query
-    test_query: str = "SELECT * FROM table_full__I;"
+    test_query: str = "SELECT * FROM table_full__I"
     batch_identifiers = {
         "pipeline_stage_name": "core_processing",
         "airflow_run_id": 1234567890,
@@ -1052,7 +1052,7 @@ def test_batch_identifiers_and_batch_identifiers_error_illegal_key_with_query_mo
     datasource_with_runtime_data_connector_and_sqlalchemy_execution_engine, sa
 ):
     # interacting with the database using query
-    test_query: str = "SELECT * FROM table_full__I;"
+    test_query: str = "SELECT * FROM table_full__I"
     batch_identifiers = {
         "pipeline_stage_name": "core_processing",
         "airflow_run_id": 1234567890,