2017-06-02 81 views
0

我使用的是Spark 2.1,并且具有一个配有orc格式的配置单元表,以下是模式。Spark的数据集api给出与Dataframe相比不同的结果

col_name data_type 
tuid  string 
puid  string 
ts   string 
dt   string 
source  string 
peer  string 
# Partition Information 
# col_name data_type 
dt   string 
source  string 
peer  string 

# Detailed Table Information  
Database:   test 
Owner:    test 
Create Time:  Tue Nov 22 15:25:53 GMT 2016 
Last Access Time: Thu Jan 01 00:00:00 GMT 1970 
Location:   hdfs://apps/hive/warehouse/nis.db/dmp_puid_tuid 
Table Type:   MANAGED 
Table Parameters: 
    transient_lastDdlTime 1479828353 
    SORTBUCKETCOLSPREFIX TRUE 

# Storage Information 
SerDe Library: org.apache.hadoop.hive.ql.io.orc.OrcSerde 
InputFormat: org.apache.hadoop.hive.ql.io.orc.OrcInputFormat 
OutputFormat: org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat 
Compressed: No 
Storage Desc Parameters:  
    serialization.format 1 

当我在此表上使用分区列的过滤器,其工作正常,只读取特定的分区。

val puid = spark.read.table("nis.dmp_puid_tuid") 
    .as(Encoders.bean(classOf[DmpPuidTuid])) 
    .filter("""peer = "AggregateKnowledge" and dt = "20170403"""") 

,这是我对这个查询

== Physical Plan == 
HiveTableScan [tuid#1025, puid#1026, ts#1027, dt#1022, source#1023, peer#1024], MetastoreRelation nis, dmp_puid_tuid, [isnotnull(peer#1024), isnotnull(dt#1022), 
(peer#1024 = AggregateKnowledge), (dt#1022 = 20170403)] 

但物理计划时,我使用下面的代码,它读取整个数据到火花

val puid = spark.read.table("nis.dmp_puid_tuid") 
    .as(Encoders.bean(classOf[DmpPuidTuid])) 
    .filter(tp => tp.getPeer().equals("AggregateKnowledge") && Integer.valueOf(tp.getDt()) >= 20170403) 

以上数据帧

物理计划
== Physical Plan == 
*Filter <function1>.apply 
+- HiveTableScan [tuid#1058, puid#1059, ts#1060, dt#1055, source#1056, peer#1057], MetastoreRelation nis, dmp_puid_tuid 

注: -DmpPuidTuid是Java bean类

回答

0

当您通过Scala的功能filter,可以防止从看到星火优化,这是实际使用的数据集的列(因为优化器不尝试一下该函数的编译的代码的内部)。如果你传递一个列表达式,如col("peer") === "AggregateKnowledge" && col("dt").cast(IntegerType) >= 20170403那么优化器将能够看到它实际上是必需列,并相应地调整计划。

+0

感谢@joe是否有任何其他方式来实现或数据集的typesefe功能在未来的任何支持。 – Kaushal

+0

如果你的意思编译时类型检查,我所知道的唯一的事情就是[无框](https://github.com/typelevel/frameless)项目。我不是这个东西的专家,虽然。 –

相关问题