gpt4 book ai didi

apache-spark - Spark 2.3.1 AWS EMR 不返回某些列的数据但适用于 Athena/Presto 和 Spectrum

转载 作者:行者123 更新时间:2023-12-02 02:50:50 26 4
gpt4 key购买 nike

我在 AWS EMR (Python 2.7.14) 上的 Spark 2.3.1 上使用 PySpark

spark = SparkSession \
.builder \
.appName("Python Spark SQL data source example") \
.config("hive.metastore.client.factory.class", "com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory") \
.config("hive.exec.dynamic.partition", "true") \
.config("hive.exec.dynamic.partition.mode", "nonstrict") \
.config("spark.debug.maxToStringFields", 100) \
.enableHiveSupport() \
.getOrCreate()


spark.sql('select `message.country` from datalake.leads_notification where `message.country` is not null').show(10)

这不返回任何数据,找到 0 行。
上表中每一行的每个值都返回 Null。
数据存储在 Parquet 。

当我在 AWS Athena/Presto 或 AWs Redshift Spectrum 上运行相同的 SQL 查询时,我会正确返回所有列数据(大多数列值不为空)。

这是返回正确数据的 Athena SQL 和 Redshift SQL 查询:
select "message.country" from datalake.leads_notification where "message.country" is not null limit 10;

我在所有情况下都使用 AWS Glue 目录。
上面的列没有分区,但表在其他列上分区。我尝试使用修复表,但没有帮助。
即 MSCK 维修表 datalake.leads_notification

我试过 Schema Merge = True 像这样:
spark = SparkSession \
.builder \
.appName("Python Spark SQL data source example") \
.config("hive.metastore.client.factory.class", "com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory") \
.config("hive.exec.dynamic.partition", "true") \
.config("spark.sql.parquet.mergeSchema", "true") \
.config("hive.exec.dynamic.partition.mode", "nonstrict") \
.config("spark.debug.maxToStringFields", 200) \
.enableHiveSupport() \
.getOrCreate()

没有区别,一列的每个值仍然是空值,即使有些值不是空值。

此列作为最后一列添加到表中,因此大多数数据确实为空,但有些行不为空。该列最后列在目录中的列列表中,位于分区列的正上方。

尽管如此,Athena/Presto 可以检索所有非空值,Redshift Spectrum 也是如此,但可惜 EMR Spark 2.3.1 PySpark 将此列的所有值显示为“空”。 Spark 中的所有其他列均已正确检索。

任何人都可以帮我调试这个问题吗?

由于输出格式的原因,Hive Schema 很难在这里剪切和粘贴。
***CREATE TABLE datalake.leads_notification(
message.environment.siteorigin string,
dcpheader.dcploaddateutc string,
message.id int,
message.country string,
message.financepackage.id string,
message.financepackage.version string)
PARTITIONED BY (
partition_year_utc string,
partition_month_utc string,
partition_day_utc string,
job_run_guid string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
's3://blahblah/leads_notification/leads_notification/'
TBLPROPERTIES (
'CrawlerSchemaDeserializerVersion'='1.0',
'CrawlerSchemaSerializerVersion'='1.0',
'UPDATED_BY_CRAWLER'='weekly_datalake_crawler',
'averageRecordSize'='3136',
'classification'='parquet',
'compressionType'='none',
'objectCount'='2',
'recordCount'='897025',
'sizeKey'='1573529662',
'spark.sql.create.version'='2.2 or prior',
'spark.sql.sources.schema.numPartCols'='4',
'spark.sql.sources.schema.numParts'='3',
'spark.sql.sources.schema.partCol.0'='partition_year_utc',
'spark.sql.sources.schema.partCol.1'='partition_month_utc',
'spark.sql.sources.schema.partCol.2'='partition_day_utc',
'spark.sql.sources.schema.partCol.3'='job_run_guid',
'typeOfData'='file')***

最后 3 列在 Spark 中都有相同的问题:
message.country string, 
message.financepackage.id string,
message.financepackage.version string

使用相同的目录在 Athena/Presto 和 Redshift Spectrum 中都返回 OK。

我为我的编辑道歉。

谢谢

最佳答案

做第 5 步模式检查:
http://www.openkb.info/2015/02/how-to-build-and-use-parquet-tools-to.html

我敢打赌,parquet 定义中的这些新列名要么是大写的(而其他列名是小写的),要么是 parquet 定义中的新列名是小写的(而其他列名是大写的)

Spark issues reading parquet files
https://medium.com/@an_chee/why-using-mixed-case-field-names-in-hive-spark-sql-is-a-bad-idea-95da8b6ec1e0

关于apache-spark - Spark 2.3.1 AWS EMR 不返回某些列的数据但适用于 Athena/Presto 和 Spectrum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52308283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com