V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
linuxchild
V2EX  ›  问与答

spark 中当列的类型为 Array 或者 Map 的时候,如何判断两列是否相等

  •  
  •   linuxchild · 2017-11-24 11:01:00 +08:00 · 2390 次点击
    这是一个创建于 2338 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Schema 如下:

     |-- list: array (nullable = true)
     |    |-- element: map (containsNull = true)
     |    |    |-- key: string
     |    |    |-- value: array (valueContainsNull = true)
     |    |    |    |-- element: struct (containsNull = true)
     |    |    |    |    |-- Date: integer (nullable = true)
     |    |    |    |    |-- Name: string (nullable = true)
     |-- list2: array (nullable = true)
     |    |-- element: map (containsNull = true)
     |    |    |-- key: string
     |    |    |-- value: array (valueContainsNull = true)
     |    |    |    |-- element: struct (containsNull = true)
     |    |    |    |    |-- Date: integer (nullable = true)
     |    |    |    |    |-- Name: string (nullable = true)
    

    想过滤出来 list 和 list2 相等的数据,该如何判断?

    使用filter($"list" === $"list2")判断会提示错误:

    org.apache.spark.sql.AnalysisException: cannot resolve '(`list` = `list2`)' due to data type mismatch: Cannot use map type in EqualTo, but the actual input type is array<map<string,array<str
    uct<Date:int,Name:string>>>>.;;
    

    以上,感谢~

    4 条回复    2017-11-24 15:55:35 +08:00
    linuxchild
        1
    linuxchild  
    OP
       2017-11-24 11:40:40 +08:00
    木有人搞么
    MasterC
        2
    MasterC  
       2017-11-24 11:43:26 +08:00
    自己写 function 进行遍历比较
    czheo
        3
    czheo  
       2017-11-24 11:45:35 +08:00
    udf
    linuxchild
        4
    linuxchild  
    OP
       2017-11-24 15:55:35 +08:00
    @MasterC 嗯,刚刚搞出来了,貌似只能自己写 UDF 了


    @czheo 嗯,的确只能这样,感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   981 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:41 · PVG 06:41 · LAX 15:41 · JFK 18:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.