Spark Hive SQL返回空数据框

问题描述 投票:0回答:2

我正在使用Glue作为我的蜂巢元存储。我有一个小时工作,每小时将文件写入一个已注册的分区。

表定义:

CREATE EXTERNAL TABLE table_name (
column_1 STRING,
column_2 STRING
)
PARTITIONED BY (process_date DATE)
STORED AS PARQUET
LOCATION "s3://bucket/table_name/";
spark.sql("ALTER TABLE table_name ADD IF NOT EXISTS partition(process_date='2019-11-13') 
LOCATION 's3://bucket/table_name/process_date=2019-11-13'")

该分区和零件文件的s3位置是

s3://bucket/table_name/process_date=2019-11-13/hour=00/part-01.parquet
s3://bucket/table_name/process_date=2019-11-13/hour=00/part-02.parquet
s3://bucket/table_name/process_date=2019-11-13/hour=01/part-01.parquet
s3://bucket/table_name/process_date=2019-11-13/hour=01/part-02.parquet

我知道如果将hour=00hour=01添加到分区位置,它将在spark sql中起作用。但是通过这种方式,可以通过Hive而不是Spark sql来查询数据。

我也尝试过将这些conf添加到我的spark-shell中,但是没有运气。

"spark.hadoop.mapreduce.input.fileinputformat.input.dir.recursive=true"
"spark.hadoop.hive.mapred.supports.subdirectories=true"
apache-spark hive amazon-emr aws-glue
2个回答
1
投票

通过创建与您的表类似的表对场景进行了测试,以下配置对我有用:

第一组: sqlContext.setConf("spark.sql.hive.convertMetastoreParquet", "false")

然后这: sqlContext.setConf("mapred.input.dir.recursive","true"); sqlContext.setConf("spark.sql.parquet.binaryAsString", "true")

您可以在此处阅读更多信息:[1] https://home.apache.org/~pwendell/spark-nightly/spark-branch-2.2-docs/latest/sql-programming-guide.html#hive-metastore-parquet-table-conversion


0
投票

我认为您所做的是在hive-site.xml中启用了Glue目录,但在spark-hive-site.xml中未启用。

您的分类还应该包含以下部分:

[ { "Classification": "spark-hive-site", "Properties": { "hive.metastore.client.factory.class": "com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory" } }, ]

ref:[1] https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-spark-glue.html

© www.soinside.com 2019 - 2024. All rights reserved.