Spark DF查询语句报错 extraneous input ''`t`'' expecting {, ',', 'FROM', 'WHERE', 'GROUP', '

Spark DF查询语句报错 extraneous input ''`t`'' expecting {, ',', 'FROM', 'WHERE', 'GROUP', '_第1张图片
在SQLyog测试语句测试是正常的

SELECT username, SUBSTR(DATE,1,13) AS t ,COUNT(username) FROM abc GROUP BY username,t

在spark里测试
val df = sqc.createDataFrame(readyData).toDF(“username”,“date”,“ip”,“inbody”,“outbody”)
df.registerTempTable(“abc”)
sqc.sql(“SELECT username, SUBSTR(DATE,1,13) AS hour ,COUNT(username) FROM abc GROUP BY username,t”).show

结果报出:
19/04/12 08:52:21 INFO SparkSqlParser: Parsing command: SELECT username, SUBSTR(DATE,1,13) AS hour ,COUNT(username) FROM abc GROUP BY username,t
Exception in thread “main” org.apache.spark.sql.AnalysisException: cannot resolve ‘t’ given input columns: [ip, inbody, date, username, outbody]; line 1 pos 87;
'Aggregate [username#11, 't], [username#11, substring(DATE#12, 1, 13) AS hour#23, count(username#11) AS count(username)#25L]
± SubqueryAlias abc
± Project [_1#0 AS username#11, _2#1 AS date#12, _3#2 AS ip#13, _4#3 AS inbody#14, _5#4 AS outbody#15]
± LogicalRDD [_1#0, _2#1, _3#2, _4#3, _5#4]

发现是groupby后不能直接跟别名, 用了一个很简单的方法
解决:
就是将别名 t 直接修改成: SUBSTR(DATE,1,13)
就可以直接运行了。详细还在琢磨中。

你可能感兴趣的:(Bug集合)