栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

ClickHouse通过File ENGINE 导出Parquet文件

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ClickHouse通过File ENGINE 导出Parquet文件

  1. 导读:https://clickhouse.com/docs/en/engines/table-engines/special/file/
  2. 创建clickhouse_sink表并插入数据。
SELECt  * FROM  clickhouse_sink

userId|score|EventDate |
------+-----+----------+
     1|    1|1970-01-01|
     2|    3|2022-06-26|
     
  1. 创建File引擎表。
CREATE TABLE file_table (userId UInt64, score UInt8,EventDate Date) ENGINE=File(Parquet)
  1. 将表数据写入File引擎表
insert into file_table  SELECt  * FROM  clickhouse_sink
  1. file_table 表数据查询。
select * from file_table

userId|score|EventDate |
------+-----+----------+
     1|    1|1970-01-01|
     2|    3|2022-06-26|
     
  1. 导出的Parquet文件查看、
➜  file_table pwd
/your_clickhouse_data_path/yourdatabasename/file_table
➜  file_table ls
data.Parquet
  1. Spark读取Parquet文件。
//1. create path
 val path = "/your_clickhouse_data_path/yourdatabasename/file_table/data.Parquet"
      //2:create SparkSession
      val spark = SparkSession
        .builder()
        .appName("SparkBatchDemo")
        .master("local")
        //.master("yarn")
        // .config("spark.some.config.option", "some-value")
        .getOrCreate()
      //3:read clickhouse data from path
      val df = spark.read.parquet(path)
      //4.1: Displays the content of the DataFrame to stdout
      df.show()
      df.printSchema()

运行结果如下:

+------+-----+---------+
|userId|score|EventDate|
+------+-----+---------+
|     1|    1|        0|
|     2|    3|    19169|
+------+-----+---------+

root
 |-- userId: decimal(20,0) (nullable = true)
 |-- score: short (nullable = true)
 |-- EventDate: integer (nullable = true)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1025421.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号