Spark-不从scala中的映射值获取int
我有一个对象被定义为Spark-不从scala中的映射值获取int,scala,apache-spark,pyspark,spark-dataframe,Scala,Apache Spark,Pyspark,Spark Dataframe,我有一个对象被定义为 pLinkGroupsByP: Map[String, Set[(String, Int)]] 我试图在要返回的对象中获取Int,如果它存在,否则返回0,因此.getOrElse(0) (Doc.productType.id)用于访问键 (Doc.Group.id)用于访问值的1st部分 (container.containerDoc.GroupOrder)用于访问值的第二部分,这是我需要分配给结果的部分 但是,无论发生什么情况,我都只能得到地图中第一个值的第一个数字
pLinkGroupsByP: Map[String, Set[(String, Int)]]
我试图在要返回的对象中获取Int,如果它存在,否则返回0
,因此.getOrElse(0)
用于访问键(Doc.productType.id)
用于访问值的1st部分(Doc.Group.id)
用于访问值的第二部分,这是我需要分配给结果的部分(container.containerDoc.GroupOrder)
Map["pro-ucw32, Set[(PRD-1292, 5)]]
我想你可以用简单的if-else得到结果
val result:Int = if(pLinkGroupsByP(Doc.productType.id).contains(Doc.Group.id,container.containerDoc.GroupOrder)) container.containerDoc.GroupOrder else 0
“元组到映射”转换值被分配一个元组到映射
relatedDoc.linkGroup.id is a key being mapped and retunred if its a number greater than 1 it will be returned and then a 0
因此,要么您的数据都是0,要么您有一个异常。@Marcin我超过了零,现在我添加了这个
(Doc.Group.id,container.containerDoc.GroupOrder)。\u 2
它将返回数字,但只返回值的第一个数字。i、 它只给了我7
,即使是3008
,甚至认为它应该是5
。请看一下样品的图片data@dedpo你能把单据的申报单包括进去吗?谢谢,您是否考虑过简化数据结构,使用带有复合键的简单映射,并将int作为值?
val tupleToMap = pLinkGroupsByP(Doc.productType.id).toMap
tupleToMap(relatedDoc.lkGroup.id).GetorElse(0)
relatedDoc.linkGroup.id is a key being mapped and retunred if its a number greater than 1 it will be returned and then a 0