Repository: great-expectations/great_expectations

Issue:
[BUG] Bug in Query template values metric when it gets int values
**Describe the bug**
Hi, 
The new version of GX with #8570  was supposed to fix a bug in Query template values metric, but [this addition](https://github.com/great-expectations/great_expectations/blob/develop/great_expectations/expectations/metrics/query_metrics/query_template_values.py#L30) introduced another bug. 


**To Reproduce**
Trying to run this expectation will result in an error:, because sa.text() doesnt like an Int value (which is provided in "num_of_distinct_values" inside the template_dict)

```
{
        "expectation_type": "expect_queried_column_to_have_n_distinct_values_with_condition",
        "kwargs": {"template_dict": {'condition': 'is_current', 'column_to_check': 'end_date',
                                     'num_of_distinct_values': 1
                                     },
                  }
    }
```




The error message is: TypeError: expected string or bytes-like object.
Stack trace: 
```
File "/Users/itaise/github/wix-data-dev/wix_venv/lib/python3.10/site-packages/great_expectations/expectations/metrics/query_metrics/query_template_values.py", line 30, in get_query
template_dict_reformatted = {
File "/Users/itaise/github/wix-data-dev/wix_venv/lib/python3.10/site-packages/great_expectations/expectations/metrics/query_metrics/query_template_values.py", line 31, in
k: sa.text(v).format(active_batch=selectable)
File "", line 2, in text
File "", line 2, in _create_text
File "/Users/itaise/github/wix-data-dev/wix_venv/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 375, in warned
return fn(*args, **kwargs)
File "/Users/itaise/github/wix-data-dev/wix_venv/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 1922, in _create_text
return TextClause(text, bind=bind)
File "/Users/itaise/github/wix-data-dev/wix_venv/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 1822, in __init__
self.text = self._bind_params_regex.sub(repl, text)
TypeError: expected string or bytes-like object
```

@Kilo59  Can you please check? thanks! 

**Environment (please complete the following information):**
 - Great Expectations Version: great-expectations==0.17.11
 


Discussion:

Resolving patch:
diff --git a/great_expectations/expectations/metrics/query_metrics/query_template_values.py b/great_expectations/expectations/metrics/query_metrics/query_template_values.py
--- a/great_expectations/expectations/metrics/query_metrics/query_template_values.py
+++ b/great_expectations/expectations/metrics/query_metrics/query_template_values.py
@@ -1,3 +1,4 @@
+import numbers
 from typing import TYPE_CHECKING, Any, Dict, List, Union
 
 from great_expectations.compatibility.sqlalchemy import (
@@ -26,10 +27,10 @@ class QueryTemplateValues(QueryMetricProvider):
     )
 
     @classmethod
-    def get_query(cls, query, template_dict, selectable):
+    def get_query(cls, query, template_dict, selectable) -> str:
         template_dict_reformatted = {
-            k: sa.text(v).format(active_batch=selectable)
-            if isinstance(v, int)
+            k: str(v).format(active_batch=selectable)
+            if isinstance(v, numbers.Number)
             else v.format(active_batch=selectable)
             for k, v in template_dict.items()
         }


Test patch:
diff --git a/tests/expectations/metrics/query_metrics/test_query_metrics.py b/tests/expectations/metrics/query_metrics/test_query_metrics.py
new file mode 100644
--- /dev/null
+++ b/tests/expectations/metrics/query_metrics/test_query_metrics.py
@@ -0,0 +1,56 @@
+import pytest
+
+from great_expectations.compatibility.sqlalchemy import (
+    sqlalchemy as sa,
+)
+from great_expectations.expectations.metrics.query_metrics.query_template_values import (
+    QueryTemplateValues,
+)
+
+
+@pytest.mark.unit
+def test_query_template_get_query_function_with_int():
+    """Simple test to ensure that the `get_query()` method for QueryTemplateValue can handle integer value"""
+    query: str = """
+            SELECT {column_to_check}
+            FROM {active_batch}
+            WHERE {condition}
+            GROUP BY {column_to_check}
+            """
+    selectable = sa.Table("gx_temp_aaa", sa.MetaData(), schema=None)
+    template_dict: dict = {"column_to_check": 1, "condition": "is_open"}
+    metric_ob: QueryTemplateValues = QueryTemplateValues()
+    formatted_query: str = metric_ob.get_query(query, template_dict, selectable)
+    assert (
+        formatted_query
+        == """
+            SELECT 1
+            FROM gx_temp_aaa
+            WHERE is_open
+            GROUP BY 1
+            """
+    )
+
+
+@pytest.mark.unit
+def test_query_template_get_query_function_with_float():
+    """Simple test to ensure that the `get_query()` method for QueryTemplateValue can handle float value"""
+    query: str = """
+            SELECT {column_to_check}
+            FROM {active_batch}
+            WHERE {condition}
+            GROUP BY {column_to_check}
+            """
+    selectable = sa.Table("gx_temp_aaa", sa.MetaData(), schema=None)
+    template_dict: dict = {"column_to_check": 1.0, "condition": "is_open"}
+    metric_ob: QueryTemplateValues = QueryTemplateValues()
+    formatted_query: str = metric_ob.get_query(query, template_dict, selectable)
+    assert (
+        formatted_query
+        == """
+            SELECT 1.0
+            FROM gx_temp_aaa
+            WHERE is_open
+            GROUP BY 1.0
+            """
+    )