I need help.
I have data like this:
anum bnum
8661994 8661993
8661994 8661993
8661994 8661993
8661992 8661994
In SQL I can do something like this:
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;
result:
anum count_anum count_anum_on_bnum
8661992 1 0
8661994 3 1
how can I achieve that in apache drill? (data is in csv) I tried this, but gave me error
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
the error is: org.apache.drill.common.exceptions.UserRemoteException: PLAN ERROR: Cannot convert RexNode to equivalent Drill expression. RexNode Class: org.apache.calcite.rex.RexCorrelVariable, RexNode Digest: $cor1 [Error Id: 7e975eb8-ab37-432f-9387-99126f1f43cf on master:31010]
csv configuration in hdfs
"csv": {
"type": "text",
"extensions": [
"csv"
],
"delimiter": ","
},
Add "extractHeader": true
property to your CSV format plugin and use the following query:
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)
Drill can't plan the query provided by. You can submit a Jira ticket to implement it: https://issues.apache.org/jira/projects/DRILL