【发布时间】:2019-04-21 17:08:34
【问题描述】:
我正在使用 spark 2.3 并且已经使用 pyspark 中的数据帧写入器类方法编写了一个数据帧来创建配置单元分区表。
newdf.coalesce(1).write.format('orc').partitionBy('veh_country').mode("overwrite").saveAsTable('emp.partition_Load_table')
这是我的表结构和分区信息。
hive> desc emp.partition_Load_table;
OK
veh_code varchar(17)
veh_flag varchar(1)
veh_model smallint
veh_country varchar(3)
# Partition Information
# col_name data_type comment
veh_country varchar(3)
hive> show partitions partition_Load_table;
OK
veh_country=CHN
veh_country=USA
veh_country=RUS
现在我正在数据框内的 pyspark 中读取此表。
df2_data = spark.sql("""
SELECT *
from udb.partition_Load_table
""");
df2_data.show() --> is working
但我无法使用分区键列对其进行过滤
from pyspark.sql.functions import col
newdf = df2_data.where(col("veh_country")=='CHN')
我收到以下错误消息:
: java.lang.RuntimeException: Caught Hive MetaException attempting to get partition metadata by filter from Hive.
You can set the Spark configuration setting spark.sql.hive.manageFilesourcePartitions to false to work around this problem,
however this will result in degraded performance. Please report a bug: https://issues.apache.org/jira/browse/SPARK
Caused by: MetaException(message:Filtering is supported only on partition keys of type string)
而当我通过指定表的 hdfs 绝对路径来创建数据框时。 filter 和 where 子句按预期工作。
newdataframe = spark.read.format("orc").option("header","false").load("hdfs/path/emp.db/partition_load_table")
下面是工作
newdataframe.where(col("veh_country")=='CHN').show()
我的问题是为什么它不能首先过滤数据框。以及为什么它会抛出错误消息“仅对字符串类型的分区键支持过滤”,即使我的 veh_country 被定义为字符串或 varchar 数据类型。
【问题讨论】:
标签: hive pyspark partitioning