Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add connector for CouchbaseDB #29225

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions superset/db_engine_specs/couchbase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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.
from superset.db_engine_specs.base import BaseEngineSpec
from superset.constants import TimeGrain
from datetime import datetime
import sqlparse
from superset.db_engine_specs.base import BaseEngineSpec
from superset.superset_typing import ResultSetColumnType, SQLAColumnType
from flask_babel import gettext as __
from superset.db_engine_specs.base import BaseEngineSpec
from typing import (
Any
)

class CouchbaseEngineSpec(BaseEngineSpec):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can you add BasicParametersMixin to this since using MYSQL dialect
https://github.com/apache/superset/blob/master/superset/db_engine_specs/base.py#L2276

engine = 'couchbase'
engine_name = 'couchbase'
allows_subqueries = False
_time_grain_expressions = {
None: "{col}",
TimeGrain.SECOND: "DATE_TRUNC_STR(TOSTRING({col}),'second')",
TimeGrain.MINUTE: "DATE_TRUNC_STR(TOSTRING({col}),'minute')",
TimeGrain.HOUR: "DATE_TRUNC_STR(TOSTRING({col}),'hour')",
TimeGrain.DAY: "DATE_TRUNC_STR(TOSTRING({col}),'day')",
TimeGrain.MONTH: "DATE_TRUNC_STR(TOSTRING({col}),'month')",
TimeGrain.YEAR: "DATE_TRUNC_STR(TOSTRING({col}),'year')",
TimeGrain.QUARTER: "DATE_TRUNC_STR(TOSTRING({col}),'quarter')"
}

@classmethod
def epoch_to_dttm(cls) -> str:
return "{col} * 1000"

Check warning on line 46 in superset/db_engine_specs/couchbase.py

View check run for this annotation

Codecov / codecov/patch

superset/db_engine_specs/couchbase.py#L46

Added line #L46 was not covered by tests

@classmethod
def epoch_ms_to_dttm(cls) -> str:
return "{col}"

Check warning on line 50 in superset/db_engine_specs/couchbase.py

View check run for this annotation

Codecov / codecov/patch

superset/db_engine_specs/couchbase.py#L50

Added line #L50 was not covered by tests

@classmethod
def convert_dttm(
cls, target_type: str, dttm: datetime, db_extra: dict[str, Any] | None = None
) -> str | None:
sqla_type = cls.get_sqla_column_type(target_type)
return f"DATETIME(DATE_FORMAT_STR(STR_TO_UTC('{dttm.date().isoformat()}'), 'iso8601'))"

Check warning on line 57 in superset/db_engine_specs/couchbase.py

View check run for this annotation

Codecov / codecov/patch

superset/db_engine_specs/couchbase.py#L56-L57

Added lines #L56 - L57 were not covered by tests

@classmethod
def parse_sql(cls, sql: str) -> list[str]:
sql.replace("`COUNT(*)`","COUNT(*)")
return [str(s).strip(" ;") for s in sqlparse.parse(sql)]

Check warning on line 62 in superset/db_engine_specs/couchbase.py

View check run for this annotation

Codecov / codecov/patch

superset/db_engine_specs/couchbase.py#L61-L62

Added lines #L61 - L62 were not covered by tests
1 change: 1 addition & 0 deletions superset/sql_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"clickhouse": Dialects.CLICKHOUSE,
"clickhousedb": Dialects.CLICKHOUSE,
"cockroachdb": Dialects.POSTGRES,
"couchbase": Dialects.MYSQL,
# "crate": ???
# "databend": ???
"databricks": Dialects.DATABRICKS,
Expand Down
Loading