marregui commented on code in PR #24172:
URL: https://github.com/apache/superset/pull/24172#discussion_r1200525516


##########
superset/db_engine_specs/questdb.py:
##########
@@ -0,0 +1,311 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import re
+from datetime import datetime
+from typing import Any, Dict, List, Optional, Tuple
+
+from flask_babel import gettext as __
+from flask_babel import lazy_gettext as _
+from marshmallow import Schema, fields
+from sqlalchemy.engine.interfaces import Dialect
+from sqlalchemy.sql import text
+from sqlalchemy.types import TypeEngine
+from superset.db_engine_specs.base import (
+    BaseEngineSpec,
+    BasicParametersMixin,
+    BasicParametersType,
+    TimeGrain,
+    builtin_time_grains,
+)
+from superset.utils import core as utils
+from superset.utils.core import GenericDataType
+
+from questdb_connect import remove_public_schema, types
+from questdb_connect.dialect import connection_uri
+from questdb_connect.function_names import FUNCTION_NAMES
+
+# Apache Superset requires a Python DB-API database driver, and a SQLAlchemy 
dialect
+# https://superset.apache.org/docs/databases/installing-database-drivers
+# https://preset.io/blog/building-database-connector/
+# 
https://preset.io/blog/improving-apache-superset-integration-database-sqlalchemy/
+
+
+class QDBParametersSchema(Schema):
+    username = fields.String(allow_none=True, description=__('user'))
+    password = fields.String(allow_none=True, description=__('password'))
+    host = fields.String(required=True, description=__('host'))
+    port = fields.Integer(allow_none=True, description=__('port'))
+    database = fields.String(allow_none=True, description=__('database'))
+
+
+class QDBEngineSpec(BaseEngineSpec, BasicParametersMixin):
+    engine = 'questdb'
+    engine_name = 'QuestDB Connect'
+    default_driver = "psycopg2"
+    encryption_parameters = {"sslmode": "prefer"}
+    sqlalchemy_uri_placeholder = "questdb://user:password@host:port/database"
+    parameters_schema = QDBParametersSchema()
+    time_groupby_inline = False
+    allows_hidden_cc_in_orderby = True
+    time_secondary_columns = True
+    try_remove_schema_from_table_name = True
+    max_column_name_length = 120
+    supports_dynamic_schema = False
+    top_keywords = {}
+    # https://en.wikipedia.org/wiki/ISO_8601#Durations
+    # https://questdb.io/docs/reference/function/date-time/#date_trunc
+    _time_grain_expressions = {
+        None: '{col}',
+        "PT1S": "date_trunc('second', {col})",
+        "PT5S": "date_trunc('second', {col}) + 5000000L",
+        "PT30S": "date_trunc('second', {col}) + 30000000L",
+        "PT1M": "date_trunc('minute', {col})",
+        "PT5M": "date_trunc('minute', {col}) + 300000000L",
+        "PT10M": "date_trunc('minute', {col}) + 600000000L",
+        "PT15M": "date_trunc('minute', {col}) + 900000000L",
+        "PT30M": "date_trunc('minute', {col}) + 1800000000L",
+        "PT1H": "date_trunc('hour', {col})",
+        "PT6H": "date_trunc('hour', {col}) + 21600000000L",
+        "P1D": "date_trunc('day', {col})",
+        "P1W": "date_trunc('week', {col})",
+        "P1M": "date_trunc('month', {col})",
+        "P1Y": "date_trunc('year', {col})",
+        "P3M": "date_trunc('quarter', {col})",
+    }
+    ret_list = []
+    for duration, func in _time_grain_expressions.items():
+        if duration:
+            name = builtin_time_grains[duration]
+            ret_list.append(TimeGrain(name, _(name), func, duration))
+    _engine_time_grains = tuple(ret_list)
+    _default_column_type_mappings = (
+        (re.compile("^LONG256", re.IGNORECASE), types.Long256, 
GenericDataType.STRING),
+        (re.compile("^BOOLEAN", re.IGNORECASE), types.Boolean, 
GenericDataType.BOOLEAN),
+        (re.compile("^BYTE", re.IGNORECASE), types.Byte, 
GenericDataType.BOOLEAN),
+        (re.compile("^SHORT", re.IGNORECASE), types.Short, 
GenericDataType.NUMERIC),
+        (re.compile("^INT", re.IGNORECASE), types.Int, 
GenericDataType.NUMERIC),

Review Comment:
   I am exposing all QuestDB types defined in 
https://github.com/questdb/questdb-connect/blob/61b9693accf390a03de73ca62e657037dd69d067/src/questdb_connect/types.py#L203
   
   I have renamed the misleading `types.Boolean` for `questdb_types.Boolean`, 
etc, to make it more obvious, also in 9a3c588dc495ad0435666f41b455d54ee57b40fc
   
   



-- 
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.

To unsubscribe, e-mail: [email protected]

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