hyper-db 试用

hyper-db 是tableau查询引擎的核心,tableau 官方也提供了比较完整的文档,可以方便学习使用,同时官方也提供了python,c++,java 的api
以下是一个简单试用,体验下hyper 的功能

参考代码

为了方便基于了python 运行,里边已经直接包含了hyper,使用起来比较方便

  • 安装
pip install tableauhyperapi
  • 参考代码
from tableauhyperapi import HyperProcess, Telemetry, Connection,CreateMode
 
with HyperProcess(telemetry=Telemetry.DO_NOT_SEND_USAGE_DATA_TO_TABLEAU) as hyper:
    with Connection(endpoint=hyper.endpoint,database='app.hyper',create_mode=CreateMode.CREATE_AND_REPLACE) as connection:
        connection.execute_command("""
            CREATE TEMPORARY TABLE animals(name, legs) AS VALUES
                ('dog', 4),
                ('cat', 4),
                ('bird', 2),
                ('kangaroo', 2),
                ('centipede', 100)
            """)
 
        with connection.execute_query("SELECT name FROM animals") as results:
            for row in results:
                print(row)
 
        bipeds = connection.execute_list_query(
            "SELECT name FROM animals WHERE legs = 2")
        print(bipeds)
 
        max_legs = connection.execute_scalar_query(
            "SELECT MAX(legs) FROM animals")
        print("max legs: ", max_legs)
        #  读取一个parquet 文件,对于parquet 文件,包含了schema 不需要指定,csv 的需要指定
        sensors = connection.execute_list_query("SELECT * FROM external('demo.parquet')")
        print(sensors) 

说明

hyper 支持的功能还是不少的,是tableau 的核心引擎,类似的duckdb 也是一个很不错的olap 嵌入式引擎,社区也有一些比较,包括来自duckdb 的

参考资料

https://tableau.github.io/hyper-db/docs
https://tableau.github.io/hyper-db/docs/sql/external/syntax
https://github.com/tableau/hyper-api-samples
https://tableau.github.io/hyper-db/docs/sql/command/create_external_table
https://duckdb.org/2021/08/27/external-sorting.html
https://www.architecture-performance.fr/ap_blog/tpc-h-benchmark-of-hyper-duckdb-and-datafusion-on-parquet-files/
https://tableau.github.io/hyper-db/lang_docs/py/tableauhyperapi.html

posted on 2024-03-17 08:00  荣锋亮  阅读(27)  评论(0编辑  收藏  举报

导航