Skip to content

Repository files navigation

iQuey

数据仓库通用查询服务

最近更新

  • 添加维度计算
  • 支持窗口函数

安装依赖

pip install -r requirements.txt

根据所需要连接的数据仓库, 安装对应的扩展库

pip install sqlalchemy-hana # hana
pip install ibm_db_sa # db2
pip install PyHive # hive
pip install impyla # impala
pip install sqlalchemy-redshift # redshift
pip install sqlalchemy-sqlany # driver for SAP Sybase SQL Anywhere, developed by SAP
...

根据所需要连接的数据仓库, 安装对应的连接驱动

pip install MySQL-python # mysql
pip install cx_Oracle # oracle
pip install pymssql # mssql
pip install psycopg2 # postgresql
pip install PyHive # hive
pip install impyla # impala
pip install pypyodbc # odbc
pip install pyhdb # hana
...

配置文件

[config]
log_cfg='conf/logging.conf' # 日志配置文件
log_dir='./logs' # 日志路径文件夹
port=8000 # 服务默认端口
pool_size=50 # 线程池数目

启动服务

python main.py

启动参数

main.py options:
--debug debug模式 (default: False)
--port 服务端口
--processors 进程数 (default: 1)

API 接口文档

计算接口

GET/api/calculate/result 获取计算结果

参数名类型含义参数位置是否必选示例
typestr数据库类型URL
hoststr数据库地址URL
portint数据库端口URL
usernamestr数据库用户名URL
passwordstr数据库密码URL
aliasstr数据库其他连接参数URL
schemastr数据库名称URL
kwargsstr - json数据库其他配置参数URL
xAxisstr/json维度BODYname
["name", "age"]
[{"params": ["cdatetime"], "func": "cast_year"}]
yAxisstr/json维度BODYname
[{"name": "name", "func": "count"]
{"name": "name", "func": "count", "calculate": "percert"
tablestr/json表名BODYtable_name
{"table": "test", "schema": "schema"}
wherestr/json过滤条件BODYage<2
orderstr - json(list)排序BODY[0]
[(0, "DESC"), 1]

yAxiscalculate对应取值:

percent: 百分比
accumulate: 累加计算
same: 同比
annular: 环比

请求示例
curl -i -X POST 'http://127.0.0.1:8000/api/calculate/result?schema=bin_test&type=mysql&host=192.168.1.1&username=root&password=123456' -d '{"table": "faker91", "yAxis": [{"name": "name", "func": "count", "calculate": "same", "result_type": "rate"}], "xAxis": [{"params": ["cdatetime"], "func": "cast_year"}]}'

结果返回:

{"data": [[0, null], [1970, null], [2009, -5], [2010, 4], [2011, 0], [2012, -6], [2013, 0], [2014, 3], [2015, 1], [2016, -1], [2017, 0], [2018, -4], [2019, 3], [2020, 1]], "columns": [{"type": "long", "name": "x_0"}, {"type": "long", "name": "anon_1"}]}

数据库接口

GET/api/schemas 获取全部SCHEMA

参数名类型含义参数位置是否必选
typestr数据库类型URL
hoststr数据库地址URL
portint数据库端口URL
usernamestr数据库用户名URL
passwordstr数据库密码URL
aliasstr数据库其他连接参数URL
kwargsstr - json数据库其他配置参数URL
请求示例
curl -i -X GET 'http://127.0.0.1:8000/api/db/schema?type=mysql&host=127.0.0.1&port=3306&username=root&password=123456'

结果返回:

{"databases": ["information_schema", "mysql", "performance_schema"]}

GET/api/tables 获取数据库中全部表(含视图)

参数名类型含义参数位置是否必选
typestr数据库类型URL
hoststr数据库地址URL
portint数据库端口URL
usernamestr数据库用户名URL
passwordstr数据库密码URL
aliasstr数据库其他连接参数URL
schemastr数据库名称URL
kwargsstr - json数据库其他配置参数URL
请求示例
curl -i -X GET 'http://127.0.0.1:8000/api/tables?type=mysql&host=127.0.0.1&port=3306&username=root&password=12345&schema=mysql'

结果返回:

{"tables": [{"type": "table", "name": "columns_priv"}, {"type": "table", "name": "db"}, {"type": "table", "name": "event"}, {"type": "table", "name": "func"}, {"type": "table", "name": "general_log"}, {"type": "table", "name": "help_category"}, {"type": "table", "name": "help_keyword"}, {"type": "table", "name": "help_relation"}, {"type": "table", "name": "help_topic"}, {"type": "table", "name": "host"}, {"type": "table", "name": "ndb_binlog_index"}, {"type": "table", "name": "plugin"}, {"type": "table", "name": "proc"}, {"type": "table", "name": "procs_priv"}, {"type": "table", "name": "proxies_priv"}, {"type": "table", "name": "servers"}, {"type": "table", "name": "slow_log"}, {"type": "table", "name": "tables_priv"}, {"type": "table", "name": "time_zone"}, {"type": "table", "name": "time_zone_leap_second"}, {"type": "table", "name": "time_zone_name"}, {"type": "table", "name": "time_zone_transition"}, {"type": "table", "name": "time_zone_transition_type"}, {"type": "table", "name": "user"}]}

GET/api/columns 查看数据库表字段信息

参数名类型含义参数位置是否必选
typestr数据库类型URL
hoststr数据库地址URL
portint数据库端口URL
usernamestr数据库用户名URL
passwordstr数据库密码URL
aliasstr数据库其他连接参数URL
schemastr数据库名称URL
tablestr数据表名称URL
kwargsstr - json数据库其他配置参数URL
请求示例
curl -i -X GET 'http://127.0.0.1:8000/api/schema?type=mysql&host=127.0.0.1&port=3306&username=root&password=123456&schema=mysql&table=user'

结果返回:

{"columns": [{"default": "''", "type": "str", "name": "Host", "nullable": false}, {"default": "''", "type": "str", "name": "User", "nullable": false}, {"default": "''", "type": "str", "name": "Password", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Select_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Insert_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Update_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Delete_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Create_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Drop_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Reload_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Shutdown_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Process_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "File_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Grant_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "References_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Index_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Alter_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Show_db_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Super_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Create_tmp_table_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Lock_tables_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Execute_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Repl_slave_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Repl_client_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Create_view_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Show_view_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Create_routine_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Alter_routine_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Create_user_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Event_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Trigger_priv", "nullable": false}, {"default": "'N'", "type": "unicode", "name": "Create_tablespace_priv", "nullable": false}, {"default": "''", "type": "unicode", "name": "ssl_type", "nullable": false}, {"default": null, "type": "str", "name": "ssl_cipher", "nullable": false}, {"default": null, "type": "str", "name": "x509_issuer", "nullable": false}, {"default": null, "type": "str", "name": "x509_subject", "nullable": false}, {"default": "'0'", "autoincrement": false, "type": "int", "name": "max_questions", "nullable": false}, {"default": "'0'", "autoincrement": false, "type": "int", "name": "max_updates", "nullable": false}, {"default": "'0'", "autoincrement": false, "type": "int", "name": "max_connections", "nullable": false}, {"default": "'0'", "autoincrement": false, "type": "int", "name": "max_user_connections", "nullable": false}, {"default": "''", "type": "str", "name": "plugin", "nullable": true}, {"default": null, "type": "str", "name": "authentication_string", "nullable": true}]}

GET/api/query/result 获取查询结果

参数名类型含义参数位置是否必选
typestr数据库类型URL
hoststr数据库地址URL
portint数据库端口URL
usernamestr数据库用户名URL
passwordstr数据库密码URL
aliasstr数据库其他连接参数URL
schemastr数据库名称URL
sqlstrSQL 语句,标准SQLURL
kwargsstr - json数据库其他配置参数URL
请求示例
curl -i -X GET 'http://127.0.0.1:8000/api/query/result?type=mysql&host=127.0.0.1&port=3306&username=root&password=123456& schema=test&sql=select+*+from+test+limit+2'

结果返回:

{
"schema": [
{"type": "number", "name": "id"},
{"type": "string", "name": "name"},
{"type": "string", "name": "addr"},
{"type": "number", "name": "age"},
{"type": "string", "name": "info"},
{"type": "date", "name": "birthday"}
],
"data": [
[5903367, "zhangsan", "beijing", 1, null, "1997-08-24 11:56:08"],
[5903369, "lisi", "shanghai", 1, null, "1995-08-24 11:56:08"]
]
}

GET/api/query/sql 获取查询SQL

参数名类型含义参数位置是否必选
typestr数据库类型URL
sqlstrSQL 语句,标准SQLURL
schemastr数据库名URL
请求示例
curl -i -X GET 'http://127.0.0.1:8000/api/query/sql?sql=SELECT+*+FROM+faker91+limit+10&type=oracle'
curl -i -X GET 'http://127.0.0.1:8000/api/query/sql?sql=SELECT+age,sum(age)+over(order+by+age)+FROM+faker91&type=mysql'

结果返回:

{"sql": "SELECT * FROM (SELECT * FROM faker91) WHERE ROWNUM <= 10"}
{"sql": "SELECT age, (SELECT sum(age) AS sum_1 FROM faker91 AS tb_ad1f41 WHERE tb_ad1f41.age <= faker91.age) AS fd_7e4a47 FROM faker91"}

GET/api/query/tree 获取查询语法树

参数名类型含义参数位置是否必选
sqlstrSQL 语句,标准SQLURL
请求示例
curl -i -X GET 'http://127.0.0.1:8000/api/query/tree?sql=SELECT+*+FROM+faker91+limit+10'

结果返回:

{"tree": {"query": {"windowDecls": {"list": [], "pos": {"columnNumber": 1, "endLineNumber": 1, "endColumnNumber": 21, "lineNumber": 1}}, "keywordList": {"list": [], "pos": {"columnNumber": 1, "endLineNumber": 1, "endColumnNumber": 6, "lineNumber": 1}}, "from": {"pos": {"columnNumber": 15, "endLineNumber": 1, "endColumnNumber": 21, "lineNumber": 1}, "names": ["faker91"], "componentPositions": [{"columnNumber": 15, "endLineNumber": 1, "endColumnNumber": 21, "lineNumber": 1}]}, "selectList": {"list": [{"pos": {"columnNumber": 8, "endLineNumber": 1, "endColumnNumber": 8, "lineNumber": 1}, "names": [""], "componentPositions": [{"columnNumber": 8, "endLineNumber": 1, "endColumnNumber": 8, "lineNumber": 1}]}], "pos": {"columnNumber": 8, "endLineNumber": 1, "endColumnNumber": 8, "lineNumber": 1}}, "pos": {"columnNumber": 1, "endLineNumber": 1, "endColumnNumber": 21, "lineNumber": 1}}, "fetch": {"scale": 0, "isExact": true, "pos": {"columnNumber": 29, "endLineNumber": 1, "endColumnNumber": 30, "lineNumber": 1}, "value": 10, "typeName": "DECIMAL", "prec": 2}, "pos": {"columnNumber": 29, "endLineNumber": 1, "endColumnNumber": 30, "lineNumber": 1}}}

TodoList

  • 数据分析
  • 数据导出
  • 可视化界面

About

The service for general query.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages