Skip to content

Commit

Permalink
[feat] Support Hive Conn (#1215)
Browse files Browse the repository at this point in the history
Co-authored-by: xiuzhu <edy@dodge-pro.local>
  • Loading branch information
2 people authored and csunny committed Mar 7, 2024
1 parent 5547595 commit 5542d9d
Show file tree
Hide file tree
Showing 10 changed files with 988 additions and 3 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

923 changes: 922 additions & 1 deletion dbgpt/app/static/database/index.html

Large diffs are not rendered by default.

Binary file added dbgpt/app/static/icons/hive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dbgpt/datasource/manages/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dbgpt.datasource.rdbms.conn_clickhouse import ClickhouseConnect
from dbgpt.datasource.rdbms.conn_doris import DorisConnect
from dbgpt.datasource.rdbms.conn_duckdb import DuckDbConnect
from dbgpt.datasource.rdbms.conn_hive import HiveConnect
from dbgpt.datasource.rdbms.conn_mssql import MSSQLConnect
from dbgpt.datasource.rdbms.conn_mysql import MySQLConnect
from dbgpt.datasource.rdbms.conn_postgresql import PostgreSQLDatabase
Expand Down
58 changes: 58 additions & 0 deletions dbgpt/datasource/rdbms/conn_hive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from typing import Any, Optional
from urllib.parse import quote
from urllib.parse import quote_plus as urlquote

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from dbgpt.datasource.rdbms.base import RDBMSDatabase


class HiveConnect(RDBMSDatabase):
"""db type"""

db_type: str = "hive"
"""db driver"""
driver: str = "hive"
"""db dialect"""
dialect: str = "hive"

@classmethod
def from_uri_db(
cls,
host: str,
port: int,
user: str,
pwd: str,
db_name: str,
engine_args: Optional[dict] = None,
**kwargs: Any,
) -> RDBMSDatabase:
"""Construct a SQLAlchemy engine from uri database.
Args:
host (str): database host.
port (int): database port.
user (str): database user.
pwd (str): database password.
db_name (str): database name.
engine_args (Optional[dict]):other engine_args.
"""
db_url: str = f"{cls.driver}://{host}:{str(port)}/{db_name}"
if user and pwd:
db_url: str = f"{cls.driver}://{quote(user)}:{urlquote(pwd)}@{host}:{str(port)}/{db_name}"
return cls.from_uri(db_url, engine_args, **kwargs)

def table_simple_info(self):
return []

def get_users(self):
return []

def get_grants(self):
return []

def get_collation(self):
"""Get collation."""
return "UTF-8"

def get_charset(self):
return "UTF-8"
1 change: 1 addition & 0 deletions dbgpt/storage/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DBType(Enum):
StarRocks = DbInfo("starrocks")
Spark = DbInfo("spark", True)
Doris = DbInfo("doris")
Hive = DbInfo("hive")

def value(self):
return self._value_.name
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ def all_datasource_requires():
"mysqlclient==2.1.0",
"pydoris>=1.0.2,<2.0.0",
"clickhouse-connect",
"pyhive",
"thrift",
"thrift_sasl",
]


Expand Down
Binary file added web/public/icons/hive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions web/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ export const dbMapper: Record<DBType, { label: string; icon: string; desc: strin
desc: 'Powerful open-source relational database with extensibility and SQL standards.',
},
spark: { label: 'Spark', icon: '/icons/spark.png', desc: 'Unified engine for large-scale data analytics.' },
hive: { label: 'Hive', icon: '/icons/hive.png', desc: 'A distributed fault-tolerant data warehouse system.' },
space: { label: 'Space', icon: '/icons/knowledge.png', desc: 'knowledge analytics.' },
};

0 comments on commit 5542d9d

Please sign in to comment.