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

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


The following commit(s) were added to refs/heads/fix-numeric by this push:
     new 757bff483a Better fallback field
757bff483a is described below

commit 757bff483a2aa67db90570e8ee4ab57176eb8771
Author: Beto Dealmeida <[email protected]>
AuthorDate: Tue Nov 21 10:23:19 2023 -0500

    Better fallback field
---
 superset/extensions/metadb.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/superset/extensions/metadb.py b/superset/extensions/metadb.py
index 305ac86dd0..bdfe1ae1e7 100644
--- a/superset/extensions/metadb.py
+++ b/superset/extensions/metadb.py
@@ -50,7 +50,6 @@ from shillelagh.adapters.base import Adapter
 from shillelagh.backends.apsw.dialects.base import APSWDialect
 from shillelagh.exceptions import ProgrammingError
 from shillelagh.fields import (
-    Blob,
     Boolean,
     Date,
     DateTime,
@@ -174,6 +173,18 @@ class Decimal(Field[decimal.Decimal, decimal.Decimal]):
     db_api_type = "NUMBER"
 
 
+class FallbackField(Field[Any, str]):
+    """
+    Fallback field for unknown types; converts to string.
+    """
+
+    type = "TEXT"
+    db_api_type = "STRING"
+
+    def parse(self, value: Any) -> str | None:
+        return value if value is None else str(value)
+
+
 # pylint: disable=too-many-instance-attributes
 class SupersetShillelaghAdapter(Adapter):
 
@@ -279,7 +290,7 @@ class SupersetShillelaghAdapter(Adapter):
         """
         Convert a Python type into a Shillelagh field.
         """
-        class_ = cls.type_map.get(python_type, Blob)
+        class_ = cls.type_map.get(python_type, FallbackField)
         return class_(filters=[Equal, Range], order=Order.ANY, exact=True)
 
     def _set_columns(self) -> None:

Reply via email to