【问题标题】:Spark Structured Streaming Writestream to Hive ORC Partioned External TableSpark 结构化流写入流到 Hive ORC 分区外部表
【发布时间】:2019-01-19 02:48:59
【问题描述】:

我正在尝试使用 Spark Structured Streaming - writeStream API 写入外部分区 Hive 表。

CREATE EXTERNAL TABLE `XX`(
`a` string,
`b` string,
`b` string,
`happened` timestamp,
`processed` timestamp,
`d` string,
`e` string,
`f` string )
 PARTITIONED BY (
`year` int, `month` int, `day` int)      
 CLUSTERED BY (d)
INTO 6 BUCKETS
STORED AS ORC 
TBLPROPERTIES (
'orc.compress'='ZLIB',
'orc.compression.strategy'='SPEED',
'orc.create.index'='true',
'orc.encoding.strategy'='SPEED');

在 Spark 代码中,

val hiveOrcWriter:   DataStreamWriter[Row] = event_stream
  .writeStream
  .outputMode("append")
  .format("orc")
  .partitionBy("year","month","day")
  //.option("compression", "zlib")
  .option("path", _table_loc)
  .option("checkpointLocation", _table_checkpoint)

我看到在非分区表上,记录被插入 Hive。但是,在使用分区表时,火花作业不会失败或引发异常,但不会将记录插入 Hive 表。

感谢任何处理过类似问题的人的 cmets。

编辑

刚刚发现.orc文件确实写入了HDFS,分区目录结构正确:例如。 /_table_loc/_table_name/year/month/day/part-0000-0123123.c000.snappy.orc

然而

select * from 'XX' limit 1; (or where year=2018)

不返回任何行。

表“XX”的InputFormatOutputFormatorg.apache.hadoop.hive.ql.io.orc.OrcInputFormatorg.apache.hadoop.hive.ql.io.orc.OrcOutputFormat

【问题讨论】:

    标签: apache-spark hive spark-structured-streaming orc hive-partitions


    【解决方案1】:

    结构化流式传输中未提供开箱即用的此功能。在正常处理中,您将使用 dataset.write.saveAsTable(table_name) ,并且该方法不可用。

    在 HDFS 中处理和保存数据后,您可以手动更新分区(或使用按计划执行此操作的脚本):

    如果你使用 Hive

    MSCK REPAIR TABLE table_name
    

    如果你使用 Impala

    ALTER TABLE table_name RECOVER PARTITIONS
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      • 1970-01-01
      • 2021-10-14
      • 2018-10-06
      • 2019-10-08
      • 2019-12-13
      • 2017-05-04
      相关资源
      最近更新 更多