2017-06-02 86 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)項目。我不是這個東西的專家,雖然。 –

相關問題