1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
SELECT a, m FROM z LATERAL VIEW EXPLODE([1, 2]) q AS m;
SELECT
"z"."a" AS "a",
"q"."m" AS "m"
FROM "z" AS "z"
LATERAL VIEW
EXPLODE(ARRAY(1, 2)) q AS "m";
SELECT x FROM UNNEST([1, 2]) AS q(x, y);
SELECT
"q"."x" AS "x"
FROM UNNEST(ARRAY(1, 2)) AS "q"("x", "y");
WITH cte AS (
(
SELECT
a
FROM
x
)
UNION ALL
(
SELECT
a
FROM
y
)
)
SELECT
*
FROM
cte;
WITH "cte" AS (
(
SELECT
"x"."a" AS "a"
FROM "x" AS "x"
)
UNION ALL
(
SELECT
"y"."a" AS "a"
FROM "y" AS "y"
)
)
SELECT
"cte"."a" AS "a"
FROM "cte";
WITH cte1 AS (
SELECT a
FROM x
), cte2 AS (
SELECT a + 1 AS a
FROM cte1
)
SELECT
a
FROM cte1
UNION ALL
SELECT
a
FROM cte2;
WITH "cte1" AS (
SELECT
"x"."a" AS "a"
FROM "x" AS "x"
)
SELECT
"cte1"."a" AS "a"
FROM "cte1"
UNION ALL
SELECT
"cte1"."a" + 1 AS "a"
FROM "cte1";
SELECT a, SUM(b)
FROM (
SELECT x.a, y.b
FROM x, y
WHERE (SELECT max(b) FROM y WHERE x.a = y.a) >= 0 AND x.a = y.a
) d
WHERE (TRUE AND TRUE OR 'a' = 'b') AND a > 1
GROUP BY a;
WITH "_u_0" AS (
SELECT
MAX("y"."b") AS "_col_0",
"y"."a" AS "_u_1"
FROM "y" AS "y"
GROUP BY
"y"."a"
)
SELECT
"x"."a" AS "a",
SUM("y"."b") AS "_col_1"
FROM "x" AS "x"
LEFT JOIN "_u_0" AS "_u_0"
ON "x"."a" = "_u_0"."_u_1"
JOIN "y" AS "y"
ON "x"."a" = "y"."a"
WHERE
"_u_0"."_col_0" >= 0
AND "x"."a" > 1
AND NOT "_u_0"."_u_1" IS NULL
GROUP BY
"x"."a";
(SELECT a FROM x) LIMIT 1;
(
SELECT
"x"."a" AS "a"
FROM "x" AS "x"
)
LIMIT 1;
(SELECT b FROM x UNION SELECT b FROM y) LIMIT 1;
(
SELECT
"x"."b" AS "b"
FROM "x" AS "x"
UNION
SELECT
"y"."b" AS "b"
FROM "y" AS "y"
)
LIMIT 1;
# dialect: spark
SELECT /*+ BROADCAST(y) */ x.b FROM x JOIN y ON x.b = y.b;
SELECT /*+ BROADCAST(`y`) */
`x`.`b` AS `b`
FROM `x` AS `x`
JOIN `y` AS `y`
ON `x`.`b` = `y`.`b`;
SELECT AGGREGATE(ARRAY(x.a, x.b), 0, (x, acc) -> x + acc + a) AS sum_agg FROM x;
SELECT
AGGREGATE(ARRAY("x"."a", "x"."b"), 0, ("x", "acc") -> "x" + "acc" + "x"."a") AS "sum_agg"
FROM "x" AS "x";
|