Spark sql 查询给出数据类型未命中匹配错误



我有一个小的sql查询,它在sql中工作得很好,但同样的查询在hive中按预期工作。表包含用户信息,下面是查询

spark.sql("select * from users where (id,id_proof) not in ((1232,345))").show;

我在火花中低于异常

org.apache.spark.sql.AnalysisException: cannot resolve '(named_struct('age', deleted_inventory.`age`, 'id_proof', deleted_inventory.`id_proof`) IN (named_struct('col1',1232, 'col2', 345)))' due to data type mismatch: Arguments must be same type but were: StructType(StructField(id,IntegerType,true), StructField(id_proof,IntegerType,true)) != StructType(StructField(col1,IntegerType,false), StructField(col2,IntegerType,false));

I id 和 id_proof 是整数类型。

尝试使用 with() 表,它可以工作。

scala> val df = Seq((101,121), (1232,345),(222,2242)).toDF("id","id_proof")
df: org.apache.spark.sql.DataFrame = [id: int, id_proof: int]
scala> df.show(false)
+----+--------+
|id  |id_proof|
+----+--------+
|101 |121     |
|1232|345     |
|222 |2242    |
+----+--------+

scala> df.createOrReplaceTempView("girish")
scala> spark.sql("with t1( select 1232 id,345 id_proof ) select id, id_proof from girish where (id,id_proof) not in (select id,id_proof from t1) ").show(false)
+---+--------+
|id |id_proof|
+---+--------+
|101|121     |
|222|2242    |
+---+--------+

scala>

相关内容

  • 没有找到相关文章

最新更新