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 TDengine.py driver to db_engine #32041

Merged
merged 19 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Here are some of the major database solutions that are supported:
<img src="https://superset.apache.org/img/databases/sap-hana.png" alt="oceanbase" border="0" width="220" />
<img src="https://superset.apache.org/img/databases/denodo.png" alt="denodo" border="0" width="200" />
<img src="https://superset.apache.org/img/databases/ydb.svg" alt="ydb" border="0" width="200" />
<img src="https://superset.apache.org/img/databases/tdengine.png" alt="TDengine" border="0" width="200" />
</p>

**A more comprehensive list of supported databases** along with the configuration instructions can be found [here](https://superset.apache.org/docs/configuration/databases).
Expand Down
21 changes: 21 additions & 0 deletions docs/docs/configuration/databases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ are compatible with Superset.
| [Snowflake](/docs/configuration/databases#snowflake) | `pip install snowflake-sqlalchemy` | `snowflake://{user}:{password}@{account}.{region}/{database}?role={role}&warehouse={warehouse}` |
| SQLite | No additional library needed | `sqlite://path/to/file.db?check_same_thread=false` |
| [SQL Server](/docs/configuration/databases#sql-server) | `pip install pymssql` | `mssql+pymssql://` |
| [TDengine](/docs/configuration/databases#tdengine) | `pip install taospy` `pip install taos-ws-py` | `taosws://<user>:<password>@<host>:<port>` |
| [Teradata](/docs/configuration/databases#teradata) | `pip install teradatasqlalchemy` | `teradatasql://{user}:{password}@{host}` |
| [TimescaleDB](/docs/configuration/databases#timescaledb) | `pip install psycopg2` | `postgresql://<UserName>:<DBPassword>@<Database Host>:<Port>/<Database Name>` |
| [Trino](/docs/configuration/databases#trino) | `pip install trino` | `trino://{username}:{password}@{hostname}:{port}/{catalog}` |
Expand Down Expand Up @@ -1336,6 +1337,26 @@ starrocks://<User>:<Password>@<Host>:<Port>/<Catalog>.<Database>
StarRocks maintains their Superset docuementation [here](https://docs.starrocks.io/docs/integrations/BI_integrations/Superset/).
:::

#### TDengine

The recommended connector library for TDengine is
[taospy](https://pypi.org/project/taospy/).
You need to install the extras as well for this library.
We recommend adding something like the following
text to your requirements file:

```
taospy>=2.7.19
taos-ws-py>=0.3.5
```
DuanKuanJun marked this conversation as resolved.
Show resolved Hide resolved

The expected connection string is formatted as follows:

```
taosws://<user>:<password>@<host>:<port>
```


#### Teradata

The recommended connector library is
Expand Down
Binary file added docs/static/img/tdengine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions superset/db_engine_specs/TDengine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# TDengine driver for Apache SuperSet
DuanKuanJun marked this conversation as resolved.
Show resolved Hide resolved
from superset.db_engine_specs.base import BaseEngineSpec
from urllib import parse

class TDengineEngineSpec(BaseEngineSpec):
engine = "taosws"
engine_name = "TDengine"
max_column_name_length = 64
default_driver = "taosws"
sqlalchemy_uri_placeholder = ("taosws://user:password@host:port/dbname[?key=value&key=value...]")
DuanKuanJun marked this conversation as resolved.
Show resolved Hide resolved

# time grain
_time_grain_expressions = {
None: "{col}",
"PT1S": "TIMETRUNCATE({col}, 1s, 0)",
"PT1M": "TIMETRUNCATE({col}, 1m, 0)",
"PT1H": "TIMETRUNCATE({col}, 1h, 0)",
"P1D": "TIMETRUNCATE({col}, 1d, 0)",
"P1W": "TIMETRUNCATE({col}, 1w, 0)",
}

@classmethod
def get_schema_from_engine_params(
cls,
sqlalchemy_uri: URL,
connect_args: dict[str, Any],
) -> Optional[str]:
DuanKuanJun marked this conversation as resolved.
Show resolved Hide resolved
"""
Return the configured schema.

A TDengine database is a SQLAlchemy schema.
"""
return parse.unquote(sqlalchemy_uri.database)
51 changes: 51 additions & 0 deletions tests/unit_tests/db_engine_specs/test_TDengine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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 datetime import datetime
from decimal import Decimal
from typing import Any, Optional
from unittest.mock import Mock, patch

import pytest
from sqlalchemy import types
from sqlalchemy.engine.url import make_url, URL # noqa: F401
from tests.unit_tests.db_engine_specs.utils import assert_convert_dttm

# test dttm
def test_convert_dttm(
target_type: str,
expected_result: Optional[str],
dttm: datetime, # noqa: F811
) -> None:
from superset.db_engine_specs.rockset import RocksetEngineSpec as spec # noqa: N813

assert_convert_dttm(spec, target_type, expected_result, dttm)


# test get schema
def test_get_schema_from_engine_params() -> None:
"""
Test the ``get_schema_from_engine_params`` method.
"""
from superset.db_engine_specs.TDengine import TDengineEngineSpec

assert (
TDengineEngineSpec.get_schema_from_engine_params(
make_url("taosws://user:password@host:port/dbname"), {}
)
== "dbname"
)
Loading