Skip to content

Commit

Permalink
DRILL-7050 - Testing subqueries in the SELECT statement. (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
denysord88 authored and agirish committed May 14, 2019
1 parent f84ee6a commit 704d6e4
Show file tree
Hide file tree
Showing 53 changed files with 537 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS dfs.drilltestdir.`employee_json_for_subq`;
CREATE TABLE dfs.drilltestdir.`employee_json_for_subq` as SELECT * FROM cp.`employee.json`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
source conf/drillTestConfig.properties

if [ -z "$PASSWORD" ]
then
${DRILL_HOME}/bin/sqlline -n ${USERNAME} -u "jdbc:drill:schema=dfs.drilltestdir;drillbit=${DRILL_STORAGE_PLUGIN_SERVER}" --run=${DRILL_TEST_DATA_DIR}/Datasources/ctas/subqueries/subqueries_select.ddl
else
${DRILL_HOME}/bin/sqlline -n ${USERNAME} -p ${PASSWORD} -u "jdbc:drill:schema=dfs.drilltestdir;drillbit=${DRILL_STORAGE_PLUGIN_SERVER}" --run=${DRILL_TEST_DATA_DIR}/Datasources/ctas/subqueries/subqueries_select.ddl
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 null
5 1.6666666666666667
6 1.75
7 2.0
8 2.3333333333333335
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SET `planner.enable_nljoin_for_scalar_only` = false;
SELECT
m.employee_id,
(
SELECT
AVG(sb.position_id) as avg_position
FROM
cp.`employee.json` as sb
WHERE
sb.employee_id < m.employee_id
) as avg_position
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
RESET `planner.enable_nljoin_for_scalar_only`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Zach Lovell
5 Zach Lovell
6 Zach Lovell
7 Zach Lovell
8 Zach Lovell
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SELECT
m.employee_id,
(
SELECT
MAX(sb.full_name) as max_concat
FROM
cp.`employee.json` as sb
) as max_f_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 A. Joyce Jarvis
5 A. Joyce Jarvis
6 A. Joyce Jarvis
7 A. Joyce Jarvis
8 A. Joyce Jarvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SELECT
m.employee_id,
(
SELECT
MIN(sb.full_name) as min_concat
FROM
cp.`employee.json` as sb
) as min_f_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 null
5 5
6 7
7 10
8 14
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SET `planner.enable_nljoin_for_scalar_only` = false;
SELECT
m.employee_id,
(
SELECT
SUM(sb.position_id) as sum_position
FROM
cp.`employee.json` as sb
WHERE
sb.employee_id < m.employee_id
) as sum_position
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
RESET `planner.enable_nljoin_for_scalar_only`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 1
5 1
6 1
7 1
8 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT
m.employee_id,
(
SELECT
COUNT(sub.position_id) as count_position_id
FROM
dfs.drilltestdir.`employee_json_for_subq` as sub
GROUP BY sub.position_id
LIMIT 1
) as count_position_id
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F'
LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 1
5 1
6 1
7 1
8 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT
m.employee_id,
(
SELECT
COUNT(sub.position_id) as count_position_id
FROM
dfs.drilltestdir.`employee_json_for_subq` as sub
GROUP BY sub.position_id
ORDER BY count_position_id
LIMIT 1
) as count_position_id
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F'
LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 268
5 268
6 268
7 268
8 268
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT
m.employee_id,
(
SELECT
COUNT(sub.position_id) as count_position_id
FROM
dfs.drilltestdir.`employee_json_for_subq` as sub
GROUP BY sub.position_id
ORDER BY count_position_id DESC
LIMIT 1
) as count_position_id
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F'
LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 24
5 24
6 24
7 24
8 24
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT
m.employee_id,
(
SELECT
COUNT(sub.position_id) as count_position_id
FROM
dfs.drilltestdir.`employee_json_for_subq` as sub
WHERE sub.position_id > 7
GROUP BY sub.position_id
LIMIT 1
) as count_position_id
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F'
LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 6
5 6
6 6
7 6
8 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT
m.employee_id,
(
SELECT
COUNT(sub.position_id) as count_position_id
FROM
dfs.drilltestdir.`employee_json_for_subq` as sub
GROUP BY sub.position_id
HAVING COUNT(sub.position_id) > 5
LIMIT 1
) as count_position_id
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F'
LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"testId": "subqueries_in_select_statement",
"type": "group",
"description": "Testing subqueries in the SELECT statement. Initiated by DRILL-7050",
"submit-type": "jdbc",
"categories": [
"functional"
],
"matrices": [
{
"query-file": ".*.sql",
"schema": "dfs.drillTestDir",
"output-format": "tsv",
"expected-file": ".*.e_tsv",
"verification-type": [
"in-memory"
]
}
],
"datasources": [
{
"mode": "gen",
"src": "Datasources/ctas/subqueries/subqueries_select.sh",
"dest": ""
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Sheri Nowmer
5 Maya Gutierrez
6 Roberta Damstra
7 Rebecca Kanagaki
8 Kim Brunner
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT
m.employee_id,
(
SELECT
MAX(sub.full_name) as max_full_name
FROM
cp.`employee.json` as sub
WHERE
sub.employee_id = m.employee_id
) as max_full_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F'
LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Maya Gutierrez
5 Maya Gutierrez
6 Maya Gutierrez
7 Maya Gutierrez
8 Maya Gutierrez
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT
m.employee_id,
(
SELECT
sub.full_name
FROM
cp.`employee.json` as sub
WHERE
sub.full_name = 'Maya Gutierrez'
LIMIT 1
) as full_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Sheri Nowmer
5 Sheri Nowmer
6 Sheri Nowmer
7 Sheri Nowmer
8 Sheri Nowmer
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT
m.employee_id,
(
SELECT
sub.full_name
FROM
cp.`employee.json` as sub
WHERE
sub.employee_id IN (1, 7, 5, 8)
LIMIT 1
) as full_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Roberta Damstra
5 Roberta Damstra
6 Roberta Damstra
7 Roberta Damstra
8 Roberta Damstra
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SELECT
m.employee_id,
(
SELECT
sub.full_name
FROM
cp.`employee.json` as sub
WHERE
sub.full_name IN ('Roberta Damstra', 'Roberta Bozeman') LIMIT 1
) as full_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Brenda Blumberg
5 Brenda Blumberg
6 Brenda Blumberg
7 Brenda Blumberg
8 Brenda Blumberg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SELECT
m.employee_id,
(
SELECT
MIN(sub.full_name) as min_full_name
FROM
cp.`employee.json` as sub
WHERE
sub.employee_id < 10
) as min_full_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Derrick Whelply
5 Roberta Damstra
6 null
7 null
8 null
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SET `planner.enable_nljoin_for_scalar_only` = false;
SELECT
m.employee_id,
(
SELECT
MIN(sub.full_name) as min_full_name
FROM
cp.`employee.json` as sub
WHERE
sub.employee_id < 7
AND sub.employee_id > m.employee_id
) as min_full_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
RESET `planner.enable_nljoin_for_scalar_only`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Derrick Whelply
5 Derrick Whelply
6 Derrick Whelply
7 Derrick Whelply
8 Derrick Whelply
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT
m.employee_id,
(
SELECT
sub.full_name
FROM
cp.`employee.json` as sub
WHERE
sub.full_name <= 'Maya Gutierrez'
LIMIT 1
) as full_name
FROM
cp.`employee.json` as m
WHERE
m.gender LIKE 'F' LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 Derrick Whelply
5 Derrick Whelply
6 Derrick Whelply
7 Derrick Whelply
8 Derrick Whelply
Loading

0 comments on commit 704d6e4

Please sign in to comment.