Skip to content

Commit

Permalink
fix(cubesql): Coerce empty subquery result to NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou authored and ovr committed May 16, 2022
1 parent c49c55a commit e59d2fb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
10 changes: 5 additions & 5 deletions rust/cubesql/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/cubesql/cubesql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ documentation = "https://cube.dev/docs"
homepage = "https://cube.dev"

[dependencies]
datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "5ee92140f026524639ed3675942af62b45dc2913", default-features = false, features = ["unicode_expressions"] }
datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "8b6b910152c8bc5dc88e3957c600cf98977d82d8", default-features = false, features = ["unicode_expressions"] }
anyhow = "1.0"
thiserror = "1.0"
cubeclient = { path = "../cubeclient" }
Expand Down
31 changes: 30 additions & 1 deletion rust/cubesql/cubesql/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6792,7 +6792,36 @@ ORDER BY \"COUNT(count)\" DESC"
insta::assert_snapshot!(
"superset_subquery",
execute_query(
"SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod), (SELECT format_type(d.adbin, d.adrelid) FROM pg_catalog.pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS DEFAULT, a.attnotnull, a.attnum, a.attrelid as table_oid, pgd.description as comment, a.attgenerated as generated FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_description pgd ON ( pgd.objoid = a.attrelid AND pgd.objsubid = a.attnum) WHERE a.attrelid = 13449 AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum;".to_string(),
"
SELECT
a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(
SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid)
FROM pg_catalog.pg_attrdef d
WHERE
d.adrelid = a.attrelid AND
d.adnum = a.attnum AND
a.atthasdef
) AS DEFAULT,
a.attnotnull,
a.attnum,
a.attrelid as table_oid,
pgd.description as comment,
a.attgenerated as generated
FROM pg_catalog.pg_attribute a
LEFT JOIN pg_catalog.pg_description pgd ON (
pgd.objoid = a.attrelid AND
pgd.objsubid = a.attnum
)
WHERE
a.attrelid = 18000
AND a.attnum > 0
AND NOT a.attisdropped
ORDER BY a.attnum
;
"
.to_string(),
DatabaseProtocol::PostgreSQL
)
.await?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cubesql/src/compile/mod.rs
assertion_line: 5809
expression: "execute_query(\"EXPLAIN VERBOSE SELECT 1+1;\".to_string(),\n DatabaseProtocol::MySQL).await?"
---
+-------------------------------------------------------+--------------------------------------+
Expand All @@ -25,7 +24,6 @@ expression: "execute_query(\"EXPLAIN VERBOSE SELECT 1+1;\".to_string(),\n
| physical_plan after aggregate_statistics | SAME TEXT AS ABOVE |
| physical_plan after hash_build_probe_order | SAME TEXT AS ABOVE |
| physical_plan after coalesce_batches | SAME TEXT AS ABOVE |
| physical_plan after repartition | SAME TEXT AS ABOVE |
| physical_plan after add_merge_exec | SAME TEXT AS ABOVE |
| physical_plan | ProjectionExec: expr=[2 as Int64(2)] |
| | EmptyExec: produce_one_row=true |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
---
source: cubesql/src/compile/mod.rs
assertion_line: 5341
expression: "execute_query(\"SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod), (SELECT format_type(d.adbin, d.adrelid) FROM pg_catalog.pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS DEFAULT, a.attnotnull, a.attnum, a.attrelid as table_oid, pgd.description as comment, a.attgenerated as generated FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_description pgd ON ( pgd.objoid = a.attrelid AND pgd.objsubid = a.attnum) WHERE a.attrelid = 13449 AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum;\".to_string(),\n DatabaseProtocol::PostgreSQL).await?"
expression: "execute_query(\"\n SELECT\n a.attname,\n pg_catalog.format_type(a.atttypid, a.atttypmod),\n (\n SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid)\n FROM pg_catalog.pg_attrdef d\n WHERE\n d.adrelid = a.attrelid AND\n d.adnum = a.attnum AND\n a.atthasdef\n ) AS DEFAULT,\n a.attnotnull,\n a.attnum,\n a.attrelid as table_oid,\n pgd.description as comment,\n a.attgenerated as generated\n FROM pg_catalog.pg_attribute a\n LEFT JOIN pg_catalog.pg_description pgd ON (\n pgd.objoid = a.attrelid AND\n pgd.objsubid = a.attnum\n )\n WHERE\n a.attrelid = 18000\n AND a.attnum > 0\n AND NOT a.attisdropped\n ORDER BY a.attnum\n ;\n \".to_string(),\n DatabaseProtocol::PostgreSQL).await?"
---
++
++
++
+--------------------+------------------------------------------------+---------+------------+--------+-----------+---------+-----------+
| attname | pg_catalog.format_type(a.atttypid,a.atttypmod) | DEFAULT | attnotnull | attnum | table_oid | comment | generated |
+--------------------+------------------------------------------------+---------+------------+--------+-----------+---------+-----------+
| count | bigint | NULL | true | 1 | 18000 | NULL | |
| maxPrice | numeric | NULL | true | 2 | 18000 | NULL | |
| minPrice | numeric | NULL | true | 3 | 18000 | NULL | |
| avgPrice | numeric | NULL | true | 4 | 18000 | NULL | |
| order_date | timestamp without time zone | NULL | false | 5 | 18000 | NULL | |
| customer_gender | text | NULL | false | 6 | 18000 | NULL | |
| taxful_total_price | numeric | NULL | false | 7 | 18000 | NULL | |
| has_subscription | boolean | NULL | false | 8 | 18000 | NULL | |
| is_male | boolean | NULL | true | 9 | 18000 | NULL | |
| is_female | boolean | NULL | true | 10 | 18000 | NULL | |
+--------------------+------------------------------------------------+---------+------------+--------+-----------+---------+-----------+

0 comments on commit e59d2fb

Please sign in to comment.