首页 > 解决方案 > 在 DataFrame 中不能有调用集合操作的地图类型列

问题描述

:org.apache.spark.sql.AnalysisException:不能在调用集合操作(​​相交,除外等)的DataFrame中有地图类型列,但列map_col的类型是地图

我有一个带有类型列的配置单元表 - MAP<Float, Float>。当我尝试在 spark 上下文中对该表进行插入时,出现上述错误。没有'distinct',插入工作正常。

create table test_insert2(`test_col` string, `map_col` MAP<INT,INT>) 
location 's3://mybucket/test_insert2';

insert into test_insert2 
select distinct 'a' as test_col, map(0,0) as map_col

标签: hivepysparkapache-spark-sqlamazon-emr

解决方案


尝试将数据框转换为.rdd然后应用.distinct函数。

例子:

spark.sql("select 'a'test_col,map(0,0)map_col 
              union all 
          select 'a'test_col,map(0,0)map_col").rdd.distinct.collect

结果:

Array[org.apache.spark.sql.Row] = Array([a,Map(0 -> 0)])

推荐阅读