Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 与Dataframe相比,Spark的数据集api给出了不同的结果_Java_Scala_Apache Spark_Apache Spark Sql_Spark Dataframe - Fatal编程技术网

Java 与Dataframe相比,Spark的数据集api给出了不同的结果

Java 与Dataframe相比,Spark的数据集api给出了不同的结果,java,scala,apache-spark,apache-spark-sql,spark-dataframe,Java,Scala,Apache Spark,Apache Spark Sql,Spark Dataframe,我使用Spark 2.1,有一个orc格式的配置单元表,下面是模式 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 st

我使用Spark 2.1,有一个orc格式的配置单元表,下面是模式

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
当我使用partition列在这个表的顶部应用filter时,它可以正常工作,并且只读取特定的分区

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)]
但当我使用下面的代码时,它会将整个数据读入spark

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
==物理计划==
*过滤,应用
+-HiveTableScan[tuid#1058,puid#1059,ts#1060,dt#1055,source#1056,peer#1057],元存储关系nis,dmp#puid#

注意:-DmpPuidTuid是java bean类

当您将Scala函数传递给
过滤器
时,您会阻止Spark优化器查看实际使用的数据集列(因为优化器不会尝试查看函数的编译代码)。如果传递列表达式,例如
col(“peer”)==“AggregateKnowledge”&&col(“dt”).cast(IntegerType)>=20170403
然后优化器将能够看到实际需要哪些列,并相应地调整计划。

谢谢@joe是否有其他方法来实现dataset的typesefe功能或将来的任何支持。如果你是指编译时类型检查,我只知道项目。不过我不是这方面的专家。