我需要帮助。
我有这样的数据:
anum bnum
8661994 8661993
8661994 8661993
8661994 8661993
8661992 8661994
在SQL中,我可以执行以下操作:
SELECT
anum,
(
SELECT COUNT(*)
FROM dataku t2
WHERE t2.anum=t1.anum
),
(
SELECT COUNT(*)
FROM dataku t3
WHERE t3.bnum=t1.anum
)
FROM dataku t1
GROUP BY t1.anum;
结果:
anum count_anum count_anum_on_bnum
8661992 1 0
8661994 3 1
如何在apache演练中实现? (数据在csv中) 我试过了,但是给了我错误
SELECT
anum,
(
SELECT COUNT(*)
FROM hdfs.`/test/*` as t2
WHERE t2.anum=t1.anum
),
(
SELECT COUNT(*)
FROM hdfs.`/test/*` as t3
WHERE t3.anum=t1.anum
)
FROM hdfs.`/test/*` as t1
GROUP BY t1.anum
LIMIT 1000
错误是: org.apache.drill.common.exceptions.UserRemoteException:计划错误:无法将RexNode转换为等效的Drill表达式。 RexNode类:org.apache.calcite.rex.RexCorrelVariable,RexNode摘要:$ cor1 [错误ID:master上的错误7e975eb8-ab37-432f-9387-99126f1f43cf:31010]
HDFS中的csv配置
"csv": {
"type": "text",
"extensions": [
"csv"
],
"delimiter": ","
},
答案 0 :(得分:1)
向您的CSV格式插件添加"extractHeader": true
属性,并使用以下查询:
0: jdbc:drill:zk=local> select t1.anum, t1.count_anum, coalesce(t2.count_bnum, 0) as count_anum_on_bnum from
. . . . . . . . . . . > (select anum, count(anum) as `count_anum` from dfs.`/tmp/test.csv` group by anum) t1
. . . . . . . . . . . > left join
. . . . . . . . . . . > (select bnum, count(bnum) as `count_bnum` from dfs.`/tmp/test.csv` group by bnum) t2
. . . . . . . . . . . > on t1.anum = t2.bnum;
+----------+-------------+---------------------+
| anum | count_anum | count_anum_on_bnum |
+----------+-------------+---------------------+
| 8661992 | 1 | 0 |
| 8661994 | 3 | 1 |
+----------+-------------+---------------------+
2 rows selected (0.167 seconds)
钻探无法计划提供的查询。您可以提交Jira票证来实施它: https://issues.apache.org/jira/projects/DRILL
答案 1 :(得分:0)
我在Drill 1.13上尝试了此操作,并看到了NPE问题。 有几个问题: 这是哪个版本的Drill? 另外,可以将用于“ csv”的配置粘贴到DFS存储插件中。
例如,我有这个:
"csv": {
"type": "text",
"extensions": [
"csv"
],
"extractHeader": true,
"delimiter": ","
}