星火SQL查询得到的数据类型不匹配错误

问题描述 投票:0回答:1

我有工作在SQL非常精小的SQL查询,但相同的查询在蜂巢按预期工作。表有用户信息,下面是查询

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));

我的id和id_proof是整数类型。

apache-spark apache-spark-sql
1个回答
1
投票

尝试使用带()表,它的工作原理。

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>
© www.soinside.com 2019 - 2024. All rights reserved.