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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值