我有一个Hive表,其定义如下:
create table testforerror (
my_column MAP<BIGINT, ARRAY<String>>
);
该表具有以下记录
hive> select * from testforerror;
OK
{16001:["0034000000a4WDAAA2"]}
{16001:["0034000000orWiFAAU"]}
{16001:["","0034000000VgrHdAAJ"]}
{16001:["0034000000cS4tDAAS"]}
{15001:["0037000001a7ofgAAA"]}
Time taken: 0.067 seconds, Fetched: 5 row(s)
我有一个查询,它使用my_column的键过滤记录。查询如下
select * from testforerror where my_column[16001] is not null;
此查询从hive / beeline shell执行正常并生成以下记录:
hive> select * from testforerror where my_column[16001] is not null;
OK
{16001:["0034000000a4WDAAA2"]}
{16001:["0034000000orWiFAAU"]}
{16001:["","0034000000VgrHdAAJ"]}
{16001:["0034000000cS4tDAAS"]}
Time taken: 2.224 seconds, Fetched: 4 row(s)
但是我尝试从spark sqlContext执行时遇到错误。以下是错误消息:
scala> val errorquery = "select * from testforerror where my_column[16001] is not null"
errorquery: String = select * from testforerror where my_column[16001] is not null
scala> sqlContext.sql(errorquery).show()
org.apache.spark.sql.AnalysisException: cannot resolve 'my_column[16001]' due to data type mismatch: argument 2 requires bigint type, however, '16001' is of int type.; line 1 pos 43
at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42)
at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1$$anonfun$apply$2.applyOrElse(CheckAnalysis.scala:65)
at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1$$anonfun$apply$2.applyOrElse(CheckAnalysis.scala:57)
at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$transformUp$1.apply(TreeNode.scala:335)
at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$transformUp$1.apply(TreeNode.scala:335)
at org.apache.spark.sql.catalyst.trees.CurrentOrigin$.withOrigin(TreeNode.scala:69)
at org.apache.spark.sql.catalyst.trees.TreeNode.transformUp(TreeNode.scala:334)
at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$5.apply(TreeNode.scala:332)
at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$5.apply(TreeNode.scala:332)
at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$4.apply(TreeNode.scala:281)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
任何指针都非常有用,谢谢。
答案 0 :(得分:0)
您可以使用DSL和getItem
方法代替SQL和括号表示法:
sqlContext.table("testforerror").where($"mycolumn".getItem(1L).isNotNull)