Daft sql查询数据库处理简单说明

此sql 不是Daft 对于dataframe 的sql 查询处理,而是对于database 数据源的查询处理,以下是一些简单数名

简单说明

  • 支持20+ 数据库方言,基于了sqlGlot,当然处理部分有基于connector-x的以及sqlalchemy的,默认使用connector-x 对于不支持的会进行fall back 到sqlalchemy,我们也可以指定明确使用的数据connection
  • 执行并行以及分布式读,当然这个是Daft 的标配能力
  • 支持数据过滤,select,limit,where
  • 目前对于db的写入暂时是不支持的,同时对于ADBC的支持也在规划中

Daft 对于使用connector-x以及sqlalchemy的判断

实际上就是内部支持db 类型的判断,代码如下

def execute_sql_query(self, sql: str) -> pa.Table:
    if self._should_use_connectorx():
        return self._execute_sql_query_with_connectorx(sql)
    else:
        return self._execute_sql_query_with_sqlalchemy(sql)

_should_use_connectorx 的处理

def _should_use_connectorx(self) -> bool:
    # Supported DBs extracted from here https://github.com/sfu-db/connector-x/tree/7b3147436b7e20b96691348143d605e2249d6119?tab=readme-ov-file#sources
    connectorx_supported_dbs = {
        "postgres",
        "postgresql",
        "mysql",
        "mssql",
        "oracle",
        "bigquery",
        "sqlite",
        "clickhouse",
        "redshift",
    }

    if isinstance(self.conn, str):
        if self.dialect in connectorx_supported_dbs and self.driver == "":
            return True
    return False

说明

尽管Daft 对于数据的查询会有使用到connector-x以及sqlalchemy,但是Daft 为了提升内部的并发使用了类似connector-x 的查询分片以及统计能力,提升系统的性能

参考资料

daft/sql/sql_connection.py

daft/sql/sql_scan.py

https://www.getdaft.io/projects/docs/en/stable/user_guide/integrations/sql.html

https://sqlglot.com/sqlglot.html

https://github.com/tobymao/sqlglot

https://docs.sqlalchemy.org/en/20/orm/quickstart.html

https://sfu-db.github.io/connector-x/databases.html

https://arrow.apache.org/docs/format/ADBC.html

posted on   荣锋亮  阅读(10)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2024-02-03 dremio 官方一篇关于使用了到的技术进行对象存储查询加速的博客
2024-02-03 dremio 服务暴露的一些端口
2024-02-03 dremio LivenessService 服务简单说明
2024-02-03 dbt_artifacts 一个很不错的dbt模型元数据扩展
2024-02-03 dremio cluster docker-compose 运行
2024-02-03 elementary 面向对象分析师的开源数据可观测工具
2022-02-03 让自己的npm包支持npm WARN deprecated

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示