You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: wren-core/core/src/mdl/mod.rs
+23-19
Original file line number
Diff line number
Diff line change
@@ -560,13 +560,13 @@ mod test {
560
560
sql,
561
561
)
562
562
.await?;
563
-
let expected = "SELECT profile.totalcost FROM (SELECT totalcost.totalcost FROM \
563
+
let expected = "SELECT \"profile\".totalcost FROM (SELECT totalcost.totalcost FROM \
564
564
(SELECT __relation__2.p_custkey AS p_custkey, sum(CAST(__relation__2.o_totalprice AS BIGINT)) AS totalcost FROM \
565
565
(SELECT __relation__1.c_custkey, orders.o_custkey, orders.o_totalprice, __relation__1.p_custkey FROM \
566
566
(SELECT __source.o_custkey AS o_custkey, __source.o_totalprice AS o_totalprice FROM orders AS __source) AS orders RIGHT JOIN \
567
-
(SELECT customer.c_custkey, profile.p_custkey FROM (SELECT __source.c_custkey AS c_custkey FROM customer AS __source) AS customer RIGHT JOIN \
568
-
(SELECT __source.p_custkey AS p_custkey FROM profile AS __source) AS profile ON customer.c_custkey = profile.p_custkey) AS __relation__1 \
569
-
ON orders.o_custkey = __relation__1.c_custkey) AS __relation__2 GROUP BY __relation__2.p_custkey) AS totalcost) AS profile";
567
+
(SELECT customer.c_custkey, \"profile\".p_custkey FROM (SELECT __source.c_custkey AS c_custkey FROM customer AS __source) AS customer RIGHT JOIN \
568
+
(SELECT __source.p_custkey AS p_custkey FROM \"profile\" AS __source) AS \"profile\" ON customer.c_custkey = \"profile\".p_custkey) AS __relation__1 \
569
+
ON orders.o_custkey = __relation__1.c_custkey) AS __relation__2 GROUP BY __relation__2.p_custkey) AS totalcost) AS \"profile\"";
570
570
assert_eq!(result, expected);
571
571
572
572
let sql = "select totalcost from profile where p_sex = 'M'";
@@ -578,16 +578,16 @@ mod test {
578
578
)
579
579
.await?;
580
580
assert_eq!(result,
581
-
"SELECT profile.totalcost FROM (SELECT __relation__1.p_sex, __relation__1.totalcost FROM \
582
-
(SELECT totalcost.p_custkey, profile.p_sex, totalcost.totalcost FROM (SELECT __relation__2.p_custkey AS p_custkey, \
581
+
"SELECT \"profile\".totalcost FROM (SELECT __relation__1.p_sex, __relation__1.totalcost FROM \
582
+
(SELECT totalcost.p_custkey, \"profile\".p_sex, totalcost.totalcost FROM (SELECT __relation__2.p_custkey AS p_custkey, \
583
583
sum(CAST(__relation__2.o_totalprice AS BIGINT)) AS totalcost FROM (SELECT __relation__1.c_custkey, orders.o_custkey, \
584
584
orders.o_totalprice, __relation__1.p_custkey FROM (SELECT __source.o_custkey AS o_custkey, __source.o_totalprice AS o_totalprice \
585
-
FROM orders AS __source) AS orders RIGHT JOIN (SELECT customer.c_custkey, profile.p_custkey FROM \
585
+
FROM orders AS __source) AS orders RIGHT JOIN (SELECT customer.c_custkey, \"profile\".p_custkey FROM \
586
586
(SELECT __source.c_custkey AS c_custkey FROM customer AS __source) AS customer RIGHT JOIN \
587
-
(SELECT __source.p_custkey AS p_custkey FROM profile AS __source) AS profile ON customer.c_custkey = profile.p_custkey) AS __relation__1 \
587
+
(SELECT __source.p_custkey AS p_custkey FROM \"profile\" AS __source) AS \"profile\" ON customer.c_custkey = \"profile\".p_custkey) AS __relation__1 \
588
588
ON orders.o_custkey = __relation__1.c_custkey) AS __relation__2 GROUP BY __relation__2.p_custkey) AS totalcost RIGHT JOIN \
589
-
(SELECT __source.p_custkey AS p_custkey, __source.p_sex AS p_sex FROM profile AS __source) AS profile \
590
-
ON totalcost.p_custkey = profile.p_custkey) AS __relation__1) AS profile WHERE profile.p_sex = 'M'");
589
+
(SELECT __source.p_custkey AS p_custkey, __source.p_sex AS p_sex FROM \"profile\" AS __source) AS \"profile\"\
590
+
ON totalcost.p_custkey = \"profile\".p_custkey) AS __relation__1) AS \"profile\" WHERE \"profile\".p_sex = 'M'");
591
591
Ok(())
592
592
}
593
593
@@ -618,7 +618,7 @@ mod test {
618
618
assert_eq!(actual,
619
619
"SELECT \"Customer\".\"Custkey\", \"Customer\".\"Name\" FROM \
620
620
(SELECT __source.\"Custkey\" AS \"Custkey\", __source.\"Name\" AS \"Name\" FROM \
621
-
datafusion.public.customer AS __source) AS \"Customer\"");
621
+
datafusion.\"public\".customer AS __source) AS \"Customer\"");
622
622
Ok(())
623
623
}
624
624
@@ -655,7 +655,7 @@ mod test {
655
655
)
656
656
.await?;
657
657
assert_eq!(actual,"SELECT add_two(\"Customer\".\"Custkey\") FROM (SELECT \"Customer\".\"Custkey\"\
658
-
FROM (SELECT __source.\"Custkey\" AS \"Custkey\" FROM datafusion.public.customer AS __source) AS \"Customer\") AS \"Customer\"");
658
+
FROM (SELECT __source.\"Custkey\" AS \"Custkey\" FROM datafusion.\"public\".customer AS __source) AS \"Customer\") AS \"Customer\"");
659
659
660
660
let actual = transform_sql_with_ctx(
661
661
&ctx,
@@ -665,7 +665,7 @@ mod test {
665
665
)
666
666
.await?;
667
667
assert_eq!(actual,"SELECT median(\"Customer\".\"Custkey\") FROM (SELECT \"Customer\".\"Custkey\", \"Customer\".\"Name\"\
668
-
FROM (SELECT __source.\"Custkey\" AS \"Custkey\", __source.\"Name\" AS \"Name\" FROM datafusion.public.customer AS __source) AS \"Customer\") AS \"Customer\"\
668
+
FROM (SELECT __source.\"Custkey\" AS \"Custkey\", __source.\"Name\" AS \"Name\" FROM datafusion.\"public\".customer AS __source) AS \"Customer\") AS \"Customer\"\
assert_eq!(actual,"SELECT count(*) FROM (SELECT 1)");
928
+
// TODO: BigQuery doesn't support the alias include invalid characters (e.g. `*`, `()`).
929
+
// We should remove the invalid characters for the alias.
930
+
assert_eq!(actual,"SELECT count(1) AS \"count(*)\" FROM (SELECT 1)");
929
931
Ok(())
930
932
}
931
933
@@ -1062,7 +1064,9 @@ mod test {
1062
1064
)
1063
1065
.await?;
1064
1066
assert_eq!(actual,
1065
-
"SELECT count(*) FROM (SELECT artist.cast_timestamptz FROM \
1067
+
// TODO: BigQuery doesn't support the alias include invalid characters (e.g. `*`, `()`).
1068
+
// We should remove the invalid characters for the alias.
1069
+
"SELECT count(1) AS \"count(*)\" FROM (SELECT artist.cast_timestamptz FROM \
1066
1070
(SELECT CAST(__source.\"出道時間\" AS TIMESTAMP WITH TIME ZONE) AS cast_timestamptz \
1067
1071
FROM artist AS __source) AS artist) AS artist WHERE CAST(artist.cast_timestamptz AS TIMESTAMP) > CAST('2011-01-01 21:00:00' AS TIMESTAMP)");
1068
1072
Ok(())
@@ -1148,7 +1152,7 @@ mod test {
1148
1152
"SELECT CAST(timestamp_table.timestamp_col AS TIMESTAMP WITH TIME ZONE) = timestamp_table.timestamptz_col \
1149
1153
FROM (SELECT timestamp_table.timestamp_col, timestamp_table.timestamptz_col FROM \
1150
1154
(SELECT __source.timestamp_col AS timestamp_col, __source.timestamptz_col AS timestamptz_col \
1151
-
FROM datafusion.public.timestamp_table AS __source) AS timestamp_table) AS timestamp_table");
1155
+
FROM datafusion.\"public\".timestamp_table AS __source) AS timestamp_table) AS timestamp_table");
1152
1156
1153
1157
let sql = r#"select timestamptz_col > cast('2011-01-01 18:00:00' as TIMESTAMP WITH TIME ZONE) from wren.test.timestamp_table"#;
1154
1158
let actual = transform_sql_with_ctx(
@@ -1160,7 +1164,7 @@ mod test {
1160
1164
.await?;
1161
1165
// assert the simplified literal will be casted to the timestamp tz
1162
1166
assert_eq!(actual,
1163
-
"SELECT timestamp_table.timestamptz_col > CAST(CAST('2011-01-01 18:00:00' AS TIMESTAMP) AS TIMESTAMP WITH TIME ZONE) FROM (SELECT timestamp_table.timestamptz_col FROM (SELECT __source.timestamptz_col AS timestamptz_col FROM datafusion.public.timestamp_table AS __source) AS timestamp_table) AS timestamp_table"
1167
+
"SELECT timestamp_table.timestamptz_col > CAST(CAST('2011-01-01 18:00:00' AS TIMESTAMP) AS TIMESTAMP WITH TIME ZONE) FROM (SELECT timestamp_table.timestamptz_col FROM (SELECT __source.timestamptz_col AS timestamptz_col FROM datafusion.\"public\".timestamp_table AS __source) AS timestamp_table) AS timestamp_table"
1164
1168
);
1165
1169
1166
1170
let sql = r#"select timestamptz_col > '2011-01-01 18:00:00' from wren.test.timestamp_table"#;
@@ -1175,7 +1179,7 @@ mod test {
1175
1179
assert_eq!(actual,
1176
1180
"SELECT timestamp_table.timestamptz_col > CAST('2011-01-01 18:00:00' AS TIMESTAMP WITH TIME ZONE) \
1177
1181
FROM (SELECT timestamp_table.timestamptz_col FROM (SELECT __source.timestamptz_col AS timestamptz_col \
1178
-
FROM datafusion.public.timestamp_table AS __source) AS timestamp_table) AS timestamp_table");
1182
+
FROM datafusion.\"public\".timestamp_table AS __source) AS timestamp_table) AS timestamp_table");
1179
1183
1180
1184
let sql = r#"select timestamp_col > cast('2011-01-01 18:00:00' as TIMESTAMP WITH TIME ZONE) from wren.test.timestamp_table"#;
1181
1185
let actual = transform_sql_with_ctx(
@@ -1189,7 +1193,7 @@ mod test {
1189
1193
assert_eq!(actual,
1190
1194
"SELECT timestamp_table.timestamp_col > CAST('2011-01-01 18:00:00' AS TIMESTAMP) \
1191
1195
FROM (SELECT timestamp_table.timestamp_col FROM (SELECT __source.timestamp_col AS timestamp_col \
1192
-
FROM datafusion.public.timestamp_table AS __source) AS timestamp_table) AS timestamp_table");
1196
+
FROM datafusion.\"public\".timestamp_table AS __source) AS timestamp_table) AS timestamp_table");
0 commit comments