betodealmeida commented on a change in pull request #13519:
URL: https://github.com/apache/superset/pull/13519#discussion_r589874422



##########
File path: superset/db_engine_specs/base.py
##########
@@ -153,64 +152,40 @@ class BaseEngineSpec:  # pylint: 
disable=too-many-public-methods
     allows_joins = True
     allows_subqueries = True
     allows_column_aliases = True
-    allows_sql_comments = True
     force_column_alias_quotes = False
     arraysize = 0
     max_column_name_length = 0
     try_remove_schema_from_table_name = True  # pylint: disable=invalid-name
     run_multiple_statements_as_one = False
 
-    # default matching patterns to convert database specific column types to
-    # more generic types
-    db_column_types: Dict[utils.GenericDataType, Tuple[Pattern[str], ...]] = {
-        utils.GenericDataType.NUMERIC: (
+    # default matching patterns for identifying column types
+    db_column_types: Dict[utils.DbColumnType, Tuple[Pattern[Any], ...]] = {
+        utils.DbColumnType.NUMERIC: (
             re.compile(r"BIT", re.IGNORECASE),
-            re.compile(
-                r".*(DOUBLE|FLOAT|INT|NUMBER|REAL|NUMERIC|DECIMAL|MONEY).*",
-                re.IGNORECASE,
-            ),
+            re.compile(r".*DOUBLE.*", re.IGNORECASE),
+            re.compile(r".*FLOAT.*", re.IGNORECASE),
+            re.compile(r".*INT.*", re.IGNORECASE),
+            re.compile(r".*NUMBER.*", re.IGNORECASE),
             re.compile(r".*LONG$", re.IGNORECASE),
+            re.compile(r".*REAL.*", re.IGNORECASE),
+            re.compile(r".*NUMERIC.*", re.IGNORECASE),
+            re.compile(r".*DECIMAL.*", re.IGNORECASE),
+            re.compile(r".*MONEY.*", re.IGNORECASE),
         ),
-        utils.GenericDataType.STRING: (
-            re.compile(r".*(CHAR|STRING|TEXT).*", re.IGNORECASE),
+        utils.DbColumnType.STRING: (
+            re.compile(r".*CHAR.*", re.IGNORECASE),
+            re.compile(r".*STRING.*", re.IGNORECASE),
+            re.compile(r".*TEXT.*", re.IGNORECASE),
         ),
-        utils.GenericDataType.TEMPORAL: (
-            re.compile(r".*(DATE|TIME).*", re.IGNORECASE),
+        utils.DbColumnType.TEMPORAL: (
+            re.compile(r".*DATE.*", re.IGNORECASE),
+            re.compile(r".*TIME.*", re.IGNORECASE),
         ),
     }
 
-    @classmethod
-    def get_dbapi_exception_mapping(cls) -> Dict[Type[Exception], 
Type[Exception]]:
-        """
-        Each engine can implement and converge its own specific exceptions into
-        Superset DBAPI exceptions
-
-        Note: On python 3.9 this method can be changed to a classmethod 
property
-        without the need of implementing a metaclass type
-
-        :return: A map of driver specific exception to superset custom 
exceptions
-        """
-        return {}
-
-    @classmethod
-    def get_dbapi_mapped_exception(cls, exception: Exception) -> Exception:
-        """
-        Get a superset custom DBAPI exception from the driver specific 
exception.
-
-        Override if the engine needs to perform extra changes to the 
exception, for
-        example change the exception message or implement custom more complex 
logic
-
-        :param exception: The driver specific exception
-        :return: Superset custom DBAPI exception
-        """
-        new_exception = cls.get_dbapi_exception_mapping().get(type(exception))
-        if not new_exception:
-            return exception
-        return new_exception(str(exception))
-

Review comment:
       Looks like you need to rebase your `master`, since this shouldn't be 
removed.

##########
File path: superset/db_engine_specs/base.py
##########
@@ -456,9 +424,15 @@ def apply_limit_to_sql(cls, sql: str, limit: int, 
database: "Database") -> str:
             )
             return database.compile_sqla_query(qry)
 
-        if cls.limit_method == LimitMethod.FORCE_LIMIT:
-            parsed_query = sql_parse.ParsedQuery(sql)
-            sql = parsed_query.set_or_update_query_limit(limit)
+        if LimitMethod.FORCE_LIMIT:
+            engine = cls.get_engine(database)
+            url_type = str(engine.url).split(':')[0]
+            parsed_query = sql_parse.ParsedQuery(sql, uri_type = url_type)
+            print(dir(engine.url))
+            if url_type in ['teradatasql','teradata']:
+                sql = parsed_query.set_or_update_query_limit_td(limit)

Review comment:
       My main concern with this approach is this. We shouldn't have 
Teradata-specific logic living inside this file, since all database specific 
logic should live in the custom DB engine spec 
(`superset/db_engine_specs/teradata.py` in this case).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to