/
ParserTest.java
3439 lines (3133 loc) · 156 KB
/
ParserTest.java
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.impala.analysis;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.StringReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.hive.metastore.MetaStoreUtils;
import org.apache.impala.analysis.TimestampArithmeticExpr.TimeUnit;
import org.apache.impala.common.AnalysisException;
import org.apache.impala.common.FrontendTestBase;
import org.apache.impala.testutil.TestUtils;
import org.junit.Test;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
public class ParserTest extends FrontendTestBase {
// Representative operands for testing.
private final static String[] operands_ =
new String[] {"i", "5", "true", "NULL", "'a'", "(1.5 * 8)" };
/**
* Attempts to parse the given select statement, and asserts in case of parser error.
* Also asserts that the first select-list expression is of given class.
*/
public <C extends Expr> Object ParsesOk(String selectStmtSql, Class<C> cl) {
Object parseNode = ParsesOk(selectStmtSql);
if (!(parseNode instanceof SelectStmt)) {
fail(String.format("Statement parsed ok but it is not a select stmt: %s",
selectStmtSql));
}
SelectStmt selectStmt = (SelectStmt) parseNode;
Expr firstExpr = selectStmt.getSelectList().getItems().get(0).getExpr();
// Check the class of the first select-list expression.
assertTrue(String.format(
"Expression is of class '%s'. Expected class '%s'",
firstExpr.getClass().getSimpleName(), cl.getSimpleName()),
firstExpr.getClass().equals(cl));
return parseNode;
}
/**
* Asserts if stmt parses fine or the error string doesn't match and it is non-null.
*/
public void ParserError(String stmt, String expectedErrorString) {
SqlScanner input = new SqlScanner(new StringReader(stmt));
SqlParser parser = new SqlParser(input);
Object result = null; // Save this object to make debugging easier
try {
result = parser.parse().value;
} catch (Exception e) {
if (expectedErrorString != null) {
String errorString = parser.getErrorMsg(stmt);
StringBuilder message = new StringBuilder();
message.append("Got: ");
message.append(errorString).append("\nExpected: ").append(expectedErrorString);
assertTrue(message.toString(), errorString.startsWith(expectedErrorString));
}
return;
}
fail("Stmt didn't result in parsing error: " + stmt);
}
/**
* Asserts if stmt parses fine.
* @param stmt
*/
public void ParserError(String stmt) {
ParserError(stmt, null);
}
@Test
public void TestNoFromClause() {
ParsesOk("select 1 + 1, 'two', f(3), a + b");
ParserError("select 1 + 1 'two' f(3) a + b");
ParserError("select a, 2 where a > 2");
ParserError("select a, 2 group by");
ParserError("select a, 2 order by 1");
ParserError("select a, 2 limit 1");
ParserError("select a, 2 order by 1 limit 1");
}
@Test
public void TestSelect() {
ParsesOk("select a from tbl");
ParsesOk("select a, b, c, d from tbl");
ParsesOk("select true, false, NULL from tbl");
ParsesOk("select all a, b, c from tbl");
ParserError("a from tbl");
ParserError("select a b c from tbl");
ParserError("select all from tbl");
}
/**
* Tests table and column aliases which can specified as
* identifiers (quoted or unquoted) or string literals (single or double quoted).
*/
@Test
public void TestAlias() {
char[] quotes = {'\'', '"', '`', ' '};
for (int i = 0; i < quotes.length; ++i) {
char quote = quotes[i];
// Column aliases.
ParsesOk("select a 'b' from tbl".replace('\'', quote));
ParsesOk("select a as 'b' from tbl".replace('\'', quote));
ParsesOk("select a 'x', b as 'y', c 'z' from tbl".replace('\'', quote));
ParsesOk(
"select a 'x', b as 'y', sum(x) over () 'z' from tbl".replace('\'', quote));
ParsesOk("select a.b 'x' from tbl".replace('\'', quote));
ParsesOk("select a.b as 'x' from tbl".replace('\'', quote));
ParsesOk("select a.b.c.d 'x' from tbl".replace('\'', quote));
ParsesOk("select a.b.c.d as 'x' from tbl".replace('\'', quote));
// Table aliases.
ParsesOk("select a from tbl 'b'".replace('\'', quote));
ParsesOk("select a from tbl as 'b'".replace('\'', quote));
ParsesOk("select a from db.tbl 'b'".replace('\'', quote));
ParsesOk("select a from db.tbl as 'b'".replace('\'', quote));
ParsesOk("select a from db.tbl.col 'b'".replace('\'', quote));
ParsesOk("select a from db.tbl.col as 'b'".replace('\'', quote));
ParsesOk("select a from (select * from tbl) 'b'".replace('\'', quote));
ParsesOk("select a from (select * from tbl) as 'b'".replace('\'', quote));
ParsesOk("select a from (select * from tbl b) as 'b'".replace('\'', quote));
// With-clause view aliases.
ParsesOk("with 't' as (select 1) select * from t".replace('\'', quote));
}
ParserError("a from tbl");
ParserError("select a as a, b c d from tbl");
}
@Test
public void TestStar() {
ParsesOk("select * from tbl");
ParsesOk("select tbl.* from tbl");
ParsesOk("select db.tbl.* from tbl");
ParsesOk("select db.tbl.struct_col.* from tbl");
ParserError("select * + 5 from tbl");
ParserError("select (*) from tbl");
ParserError("select *.id from tbl");
ParserError("select * from tbl.*");
ParserError("select * from tbl where * = 5");
ParsesOk("select * from tbl where f(*) = 5");
ParserError("select * from tbl where tbl.* = 5");
ParserError("select * from tbl where f(tbl.*) = 5");
}
/**
* Various test cases for (multiline) C-style comments.
*/
@Test
public void TestMultilineComment() {
ParserError("/**/");
ParserError("/*****/");
ParserError("/* select 1 */");
ParserError("/*/ select 1");
ParserError("select 1 /*/");
ParsesOk("/**/select 1");
ParsesOk("select/* */1");
ParsesOk("/** */ select 1");
ParsesOk("select 1/* **/");
ParsesOk("/*/*/select 1");
ParsesOk("/*//*/select 1");
ParsesOk("select 1/***/");
ParsesOk("/*****/select 1");
ParsesOk("/**//**/select 1");
ParserError("/**/**/select 1");
ParsesOk("\nselect 1/**/");
ParsesOk("/*\n*/select 1");
ParsesOk("/*\r*/select 1");
ParsesOk("/*\r\n*/select 1");
ParsesOk("/**\n* Doc style\n*/select 1");
ParsesOk("/************\n*\n* Header style\n*\n***********/select 1");
ParsesOk("/* 1 */ select 1 /* 2 */");
ParsesOk("select\n/**/\n1");
ParserError("/**// select 1");
ParserError("/**/*/ select 1");
ParserError("/ **/ select 1");
ParserError("/** / select 1");
ParserError("/\n**/ select 1");
ParserError("/**\n/ select 1");
ParsesOk("/*--*/ select 1");
ParsesOk("/* --foo */ select 1");
ParsesOk("/*\n--foo */ select 1");
ParsesOk("/*\n--foo\n*/ select 1");
ParserError("select 1 /* --bar");
ParserError("select 1 /*--");
ParsesOk("/* select 1; */ select 1");
ParsesOk("/** select 1; */ select 1");
ParsesOk("/* select */ select 1 /* 1 */");
}
/**
* Various test cases for one line comment style (starts with --).
*/
@Test
public void TestSinglelineComment() {
ParserError("--");
ParserError("--select 1");
ParsesOk("select 1--");
ParsesOk("select 1 --foo");
ParsesOk("select 1 --\ncol_name");
ParsesOk("--foo's \nselect 1 --bar");
ParsesOk("--foo\nselect 1 --bar");
ParsesOk("--foo\r\nselect 1 --bar");
ParsesOk("--/* foo */\n select 1");
ParsesOk("select 1 --/**/");
ParsesOk("-- foo /*\nselect 1");
ParserError("-- baz /*\nselect 1*/");
ParsesOk("select -- blah\n 1");
ParsesOk("select -- select 1\n 1");
}
/**
* Parses stmt and checks that the all table refs in stmt have the expected join hints.
* The expectedHints contains the hints of all table refs from left to right (starting
* with the second tableRef because the first one cannot have hints).
*/
private void TestJoinHints(String stmt, String... expectedHints) {
SelectStmt selectStmt = (SelectStmt) ParsesOk(stmt);
Preconditions.checkState(selectStmt.getTableRefs().size() > 1);
List<String> actualHints = Lists.newArrayList();
assertEquals(null, selectStmt.getTableRefs().get(0).getJoinHints());
for (int i = 1; i < selectStmt.getTableRefs().size(); ++i) {
List<String> hints = selectStmt.getTableRefs().get(i).getJoinHints();
if (hints != null) actualHints.addAll(hints);
}
if (actualHints.isEmpty()) actualHints = Lists.newArrayList((String) null);
assertEquals(Lists.newArrayList(expectedHints), actualHints);
}
private void TestTableHints(String stmt, String... expectedHints) {
SelectStmt selectStmt = (SelectStmt) ParsesOk(stmt);
Preconditions.checkState(selectStmt.getTableRefs().size() > 0);
List<String> actualHints = Lists.newArrayList();
for (int i = 0; i < selectStmt.getTableRefs().size(); ++i) {
List<String> hints = selectStmt.getTableRefs().get(i).getTableHints();
if (hints != null) actualHints.addAll(hints);
}
if (actualHints.isEmpty()) actualHints = Lists.newArrayList((String) null);
assertEquals(Lists.newArrayList(expectedHints), actualHints);
}
private void TestTableAndJoinHints(String stmt, String... expectedHints) {
SelectStmt selectStmt = (SelectStmt) ParsesOk(stmt);
Preconditions.checkState(selectStmt.getTableRefs().size() > 0);
List<String> actualHints = Lists.newArrayList();
for (int i = 0; i < selectStmt.getTableRefs().size(); ++i) {
List<String> joinHints = selectStmt.getTableRefs().get(i).getJoinHints();
if (joinHints != null) actualHints.addAll(joinHints);
List<String> tableHints = selectStmt.getTableRefs().get(i).getTableHints();
if (tableHints != null) actualHints.addAll(tableHints);
}
if (actualHints.isEmpty()) actualHints = Lists.newArrayList((String) null);
assertEquals(Lists.newArrayList(expectedHints), actualHints);
}
/**
* Parses stmt and checks that the select-list plan hints in stmt are the
* expected hints.
*/
private void TestSelectListHints(String stmt, String... expectedHints) {
SelectStmt selectStmt = (SelectStmt) ParsesOk(stmt);
List<String> actualHints = selectStmt.getSelectList().getPlanHints();
if (actualHints == null) actualHints = Lists.newArrayList((String) null);
assertEquals(Lists.newArrayList(expectedHints), actualHints);
}
/**
* Parses stmt and checks that the insert hints stmt are the expected hints.
*/
private void TestInsertHints(String stmt, String... expectedHints) {
InsertStmt insertStmt = (InsertStmt) ParsesOk(stmt);
List<String> actualHints = insertStmt.getPlanHints();
if (actualHints == null) actualHints = Lists.newArrayList((String) null);
assertEquals(Lists.newArrayList(expectedHints), actualHints);
}
@Test
public void TestPlanHints() {
// All plan-hint styles embed a comma-separated list of hints.
String[][] hintStyles = new String[][] {
new String[] { "/* +", "*/" }, // traditional commented hint
new String[] { "-- +", "\n" }, // eol commented hint
new String[] { "\n-- +", "\n" }, // eol commented hint
new String[] { "[", "]" } // legacy style
};
String[][] commentStyles = new String[][] {
new String[] { "/*", "*/" }, // traditional comment
new String[] { "--", "\n" } // eol comment
};
for (String[] hintStyle: hintStyles) {
String prefix = hintStyle[0];
String suffix = hintStyle[1];
// Test join hints.
TestJoinHints(String.format(
"select * from functional.alltypes a join %sbroadcast%s " +
"functional.alltypes b", prefix, suffix), "broadcast");
TestJoinHints(String.format(
"select * from functional.alltypes a join %sbroadcast%s " +
"functional.alltypes b using(id)", prefix, suffix), "broadcast");
TestJoinHints(String.format(
"select * from functional.alltypes a join %sbroadcast%s " +
"functional.alltypes b on(a.id = b.id)", prefix, suffix), "broadcast");
TestJoinHints(String.format(
"select * from functional.alltypes a cross join %sbroadcast%s " +
"functional.alltypes b", prefix, suffix), "broadcast");
// Multiple comma-separated hints.
TestJoinHints(String.format(
"select * from functional.alltypes a join " +
"%sbroadcast,shuffle,foo,bar%s " +
"functional.alltypes b using(id)", prefix, suffix),
"broadcast", "shuffle", "foo", "bar");
// Test hints in a multi-way join.
TestJoinHints(String.format(
"select * from functional.alltypes a " +
"join %sbroadcast%s functional.alltypes b using(id) " +
"join %sshuffle%s functional.alltypes c using(int_col) " +
"join %sbroadcast%s functional.alltypes d using(int_col) " +
"join %sshuffle%s functional.alltypes e using(string_col)",
prefix, suffix, prefix, suffix, prefix, suffix, prefix, suffix),
"broadcast", "shuffle", "broadcast", "shuffle");
// Test hints in a multi-way join (flipped prefix/suffix -> bad hint start/ends).
ParserError(String.format(
"select * from functional.alltypes a " +
"join %sbroadcast%s functional.alltypes b using(id) " +
"join %sshuffle%s functional.alltypes c using(int_col) " +
"join %sbroadcast%s functional.alltypes d using(int_col) " +
"join %sshuffle%s functional.alltypes e using(string_col)",
prefix, suffix, suffix, prefix, prefix, suffix, suffix, prefix));
// Test hints in a multi-way join (missing prefixes/suffixes).
ParserError(String.format(
"select * from functional.alltypes a " +
"join %sbroadcast%s functional.alltypes b using(id) " +
"join %sshuffle%s functional.alltypes c using(int_col) " +
"join %sbroadcast%s functional.alltypes d using(int_col) " +
"join %sshuffle%s functional.alltypes e using(string_col)",
suffix, suffix, suffix, suffix, prefix, "", "", ""));
// Test insert hints.
TestInsertHints(String.format(
"insert into t %snoshuffle%s select * from t", prefix, suffix),
"noshuffle");
TestInsertHints(String.format(
"insert overwrite t %snoshuffle%s select * from t", prefix, suffix),
"noshuffle");
TestInsertHints(String.format(
"insert into t partition(x, y) %snoshuffle%s select * from t",
prefix, suffix), "noshuffle");
TestInsertHints(String.format(
"insert into t(a, b) partition(x, y) %sshuffle%s select * from t",
prefix, suffix), "shuffle");
TestInsertHints(String.format(
"insert overwrite t(a, b) partition(x, y) %sfoo,bar,baz%s select * from t",
prefix, suffix), "foo", "bar", "baz");
// Test upsert hints.
ParsesOk(String.format("upsert into t %sshuffle%s select * from t", prefix,
suffix));
ParsesOk(String.format("upsert into t (x, y) %sshuffle%s select * from t", prefix,
suffix));
// Test TableRef hints.
TestTableHints(String.format(
"select * from functional.alltypes %sschedule_disk_local%s", prefix, suffix),
"schedule_disk_local");
TestTableHints(String.format(
"select * from functional.alltypes %sschedule_cache_local," +
"schedule_random_replica%s", prefix, suffix), "schedule_cache_local",
"schedule_random_replica");
TestTableHints(String.format(
"select * from functional.alltypes a %sschedule_cache_local," +
"schedule_random_replica%s", prefix, suffix), "schedule_cache_local",
"schedule_random_replica");
TestTableHints(String.format(
"select * from functional.alltypes a %sschedule_cache_local," +
"schedule_random_replica%s" + ", functional.alltypes b %sschedule_remote%s",
prefix, suffix, prefix, suffix), "schedule_cache_local",
"schedule_random_replica", "schedule_remote");
// Test both TableRef and join hints.
TestTableAndJoinHints(String.format(
"select * from functional.alltypes a %sschedule_cache_local," +
"schedule_random_replica%s join %sbroadcast%s functional.alltypes b " +
"%sschedule_remote%s using(id)", prefix, suffix, prefix, suffix, prefix,
suffix), "schedule_cache_local", "schedule_random_replica", "broadcast",
"schedule_remote");
// Test select-list hints (e.g., straight_join). The legacy-style hint has no
// prefix and suffix.
if (prefix.contains("[")) {
prefix = "";
suffix = "";
}
TestSelectListHints(String.format(
"select %sstraight_join%s * from functional.alltypes a", prefix, suffix),
"straight_join");
// Only the new hint-style is recognized
if (!prefix.equals("")) {
TestSelectListHints(String.format(
"select %sfoo,bar,baz%s * from functional.alltypes a", prefix, suffix),
"foo", "bar", "baz");
}
if (prefix.isEmpty()) continue;
// Test mixing commented hints and comments.
for (String[] commentStyle: commentStyles) {
String commentPrefix = commentStyle[0];
String commentSuffix = commentStyle[1];
String queryTemplate =
"$1comment$2 select $1comment$2 $3straight_join$4 $1comment$2 * " +
"from $1comment$2 functional.alltypes a join $1comment$2 $3shuffle$4 " +
"$1comment$2 functional.alltypes b $1comment$2 on $1comment$2 " +
"(a.id = b.id)";
String query = queryTemplate.replaceAll("\\$1", commentPrefix)
.replaceAll("\\$2", commentSuffix).replaceAll("\\$3", prefix)
.replaceAll("\\$4", suffix);
TestSelectListHints(query, "straight_join");
TestJoinHints(query, "shuffle");
}
}
// No "+" at the beginning so the comment is not recognized as a hint.
TestJoinHints("select * from functional.alltypes a join /* comment */" +
"functional.alltypes b using (int_col)", (String) null);
TestSelectListHints("select /* comment */ * from functional.alltypes",
(String) null);
TestInsertHints("insert into t(a, b) partition(x, y) /* comment */ select 1",
(String) null);
TestSelectListHints("select /* -- +straight_join */ * from functional.alltypes",
(String) null);
TestSelectListHints("select /* abcdef +straight_join */ * from functional.alltypes",
(String) null);
TestSelectListHints("select \n-- abcdef +straight_join\n * from functional.alltypes",
(String) null);
TestSelectListHints("select \n-- /*+straight_join\n * from functional.alltypes",
(String) null);
// Commented hints cannot span lines (recognized as comments instead).
TestSelectListHints("select /*\n +straight_join */ * from functional.alltypes",
(String) null);
TestSelectListHints("select /* +straight_join \n*/ * from functional.alltypes",
(String) null);
TestSelectListHints("select /* +straight_\njoin */ * from functional.alltypes",
(String) null);
ParserError("select -- +straight_join * from functional.alltypes");
ParserError("select \n-- +straight_join * from functional.alltypes");
// Missing "/*" or "/*"
ParserError("select * from functional.alltypes a join + */" +
"functional.alltypes b using (int_col)");
ParserError("select * from functional.alltypes a join /* + " +
"functional.alltypes b using (int_col)");
// Test empty hint tokens.
TestSelectListHints("select /* +straight_join, ,, */ * from functional.alltypes",
"straight_join");
// Traditional commented hints are not parsed inside a comment.
ParserError("select /* /* +straight_join */ */ * from functional.alltypes");
}
@Test
public void TestFromClause() {
String tblRefs[] = new String[] { "tbl", "db.tbl", "db.tbl.col", "db.tbl.col.fld" };
for (String tbl: tblRefs) {
ParsesOk(
("select * from $TBL src1 " +
"left outer join $TBL src2 on " +
" src1.key = src2.key and src1.key < 10 and src2.key > 10 " +
"right outer join $TBL src3 on " +
" src2.key = src3.key and src3.key < 10 " +
"full outer join $TBL src3 on " +
" src2.key = src3.key and src3.key < 10 " +
"left semi join $TBL src3 on " +
" src2.key = src3.key and src3.key < 10 " +
"left anti join $TBL src3 on " +
" src2.key = src3.key and src3.key < 10 " +
"right semi join $TBL src3 on " +
" src2.key = src3.key and src3.key < 10 " +
"right anti join $TBL src3 on " +
" src2.key = src3.key and src3.key < 10 " +
"join $TBL src3 on " +
" src2.key = src3.key and src3.key < 10 " +
"inner join $TBL src3 on " +
" src2.key = src3.key and src3.key < 10 ").replace("$TBL", tbl));
ParsesOk(
("select * from $TBL src1 " +
"left outer join $TBL src2 using (a, b, c) " +
"right outer join $TBL src3 using (d, e, f) " +
"full outer join $TBL src4 using (d, e, f) " +
"left semi join $TBL src5 using (d, e, f) " +
"left anti join $TBL src6 using (d, e, f) " +
"right semi join $TBL src7 using (d, e, f) " +
"right anti join $TBL src8 using (d, e, f) " +
"join $TBL src9 using (d, e, f) " +
"inner join $TBL src10 using (d, e, f) ").replace("$TBL", tbl));
// Test cross joins
ParsesOk("select * from $TBL cross join $TBL".replace("$TBL", tbl));
}
// Test NULLs in on clause.
ParsesOk("select * from src src1 " +
"left outer join src src2 on NULL " +
"right outer join src src3 on (NULL) " +
"full outer join src src3 on NULL " +
"left semi join src src3 on (NULL) " +
"left anti join src src3 on (NULL) " +
"right semi join src src3 on (NULL) " +
"right anti join src src3 on (NULL) " +
"join src src3 on NULL " +
"inner join src src3 on (NULL) " +
"where src2.bla = src3.bla " +
"order by src1.key, src1.value, src2.key, src2.value, src3.key, src3.value");
// Arbitrary exprs in on clause parse ok.
ParsesOk("select * from src src1 join src src2 on ('a')");
ParsesOk("select * from src src1 join src src2 on (f(a, b))");
ParserError("select * from src src1 " +
"left outer join src src2 on (src1.key = src2.key and)");
// Using clause requires SlotRef.
ParserError("select * from src src1 join src src2 using (1)");
ParserError("select * from src src1 join src src2 using (f(id))");
// Using clause required parenthesis.
ParserError("select * from src src1 join src src2 using id");
// Cross joins do not accept on/using
ParserError("select * from a cross join b on (a.id = b.id)");
ParserError("select * from a cross join b using (id)");
}
@Test
public void TestWhereClause() {
ParsesOk("select a, b from t where a > 15");
ParsesOk("select a, b from t where true");
ParsesOk("select a, b from t where NULL");
// Non-predicate exprs that return boolean.
ParsesOk("select a, b from t where case a when b then true else false end");
ParsesOk("select a, b from t where if (a > b, true, false)");
ParsesOk("select a, b from t where bool_col");
// Arbitrary non-predicate exprs parse ok but are semantically incorrect.
ParsesOk("select a, b from t where 10.5");
ParsesOk("select a, b from t where trim('abc')");
ParsesOk("select a, b from t where s + 20");
ParserError("select a, b from t where a > 15 from test");
ParserError("select a, b where a > 15");
ParserError("select where a, b from t");
}
@Test
public void TestGroupBy() {
ParsesOk("select a, b, count(c) from test group by 1, 2");
ParsesOk("select a, b, count(c) from test group by a, b");
ParsesOk("select a, b, count(c) from test group by true, false, NULL");
// semantically wrong but parses fine
ParsesOk("select a, b, count(c) from test group by 1, b");
ParserError("select a, b, count(c) from test group 1, 2");
ParserError("select a, b, count(c) from test group by order by a");
}
@Test
public void TestOrderBy() {
ParsesOk("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col, 15.7 * float_col, int_col + bigint_col");
ParsesOk("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col asc, 15.7 * float_col desc, int_col + bigint_col asc");
ParsesOk("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col asc, float_col desc, int_col + bigint_col " +
"asc nulls first");
ParsesOk("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col asc, float_col desc, int_col + bigint_col " +
"desc nulls last");
ParsesOk("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col asc, float_col desc, int_col + bigint_col " +
"nulls first");
ParsesOk("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col asc, float_col desc nulls last, int_col + bigint_col " +
"nulls first");
ParsesOk("select int_col from alltypes order by true, false, NULL");
ParserError("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by by string_col asc desc");
ParserError("select int_col, string_col, bigint_col, count(*) from alltypes " +
"nulls first");
ParserError("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col nulls");
ParserError("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col nulls first asc");
ParserError("select int_col, string_col, bigint_col, count(*) from alltypes " +
"order by string_col nulls first last");
}
@Test
public void TestHaving() {
ParsesOk("select a, b, count(c) from test group by a, b having count(*) > 5");
ParsesOk("select a, b, count(c) from test group by a, b having NULL");
ParsesOk("select a, b, count(c) from test group by a, b having true");
ParsesOk("select a, b, count(c) from test group by a, b having false");
// Non-predicate exprs that return boolean.
ParsesOk("select count(c) from test group by a having if (a > b, true, false)");
ParsesOk("select count(c) from test group by a " +
"having case a when b then true else false end");
// Arbitrary non-predicate exprs parse ok but are semantically incorrect.
ParsesOk("select a, b, count(c) from test group by a, b having 5");
ParserError("select a, b, count(c) from test group by a, b having order by 5");
ParserError("select a, b, count(c) from test having count(*) > 5 group by a, b");
}
@Test
public void TestLimit() {
ParsesOk("select a, b, c from test inner join test2 using(a) limit 10");
ParsesOk("select a, b, c from test inner join test2 using(a) limit 10 + 10");
// The following will parse because limit takes an expr, though they will fail in
// analysis
ParsesOk("select a, b, c from test inner join test2 using(a) limit 'a'");
ParsesOk("select a, b, c from test inner join test2 using(a) limit a");
ParsesOk("select a, b, c from test inner join test2 using(a) limit true");
ParsesOk("select a, b, c from test inner join test2 using(a) limit false");
ParsesOk("select a, b, c from test inner join test2 using(a) limit NULL");
// Not an expr, will not parse
ParserError("select a, b, c from test inner join test2 using(a) limit 10 " +
"where a > 10");
}
@Test
public void TestOffset() {
ParsesOk("select a from test order by a limit 10 offset 5");
ParsesOk("select a from test order by a limit 10 offset 0");
ParsesOk("select a from test order by a limit 10 offset 0 + 5 / 2");
ParsesOk("select a from test order by a asc limit 10 offset 5");
ParsesOk("select a from test order by a offset 5");
ParsesOk("select a from test limit 10 offset 5"); // Parses OK, doesn't analyze
ParsesOk("select a from test offset 5"); // Parses OK, doesn't analyze
ParsesOk("select a from (select a from test offset 5) A"); // Doesn't analyze
ParsesOk("select a from (select a from test order by a offset 5) A");
ParserError("select a from test order by a limit offset");
ParserError("select a from test order by a limit offset 5");
}
@Test
public void TestUnion() {
// Single union test.
ParsesOk("select a from test union select a from test");
ParsesOk("select a from test union all select a from test");
ParsesOk("select a from test union distinct select a from test");
// Chained union test.
ParsesOk("select a from test union select a from test " +
"union select a from test union select a from test");
ParsesOk("select a from test union all select a from test " +
"union all select a from test union all select a from test");
ParsesOk("select a from test union distinct select a from test " +
"union distinct select a from test union distinct select a from test ");
// Mixed union with all and distinct.
ParsesOk("select a from test union select a from test " +
"union all select a from test union distinct select a from test");
// No from clause.
ParsesOk("select sin() union select cos()");
ParsesOk("select sin() union all select cos()");
ParsesOk("select sin() union distinct select cos()");
// All select blocks in parenthesis.
ParsesOk("(select a from test) union (select a from test) " +
"union (select a from test) union (select a from test)");
// Union with order by,
ParsesOk("(select a from test) union (select a from test) " +
"union (select a from test) union (select a from test) order by a");
ParsesOk("(select a from test) union (select a from test) " +
"union (select a from test) union (select a from test) order by a nulls first");
// Union with limit.
ParsesOk("(select a from test) union (select a from test) " +
"union (select a from test) union (select a from test) limit 10");
// Union with order by, offset and limit.
ParsesOk("(select a from test) union (select a from test) " +
"union (select a from test) union (select a from test) order by a limit 10");
ParsesOk("(select a from test) union (select a from test) " +
"union (select a from test) union (select a from test) order by a " +
"nulls first limit 10");
ParsesOk("(select a from test) union (select a from test) " +
"union (select a from test) union (select a from test) order by a " +
"nulls first offset 10");
ParserError("select a from test union (select a from test) " +
"union (select a from test) union (select a from test) offset 10");
// Union with some select blocks in parenthesis, and others not.
ParsesOk("(select a from test) union select a from test " +
"union (select a from test) union select a from test");
ParsesOk("select a from test union (select a from test) " +
"union select a from test union (select a from test)");
// Union with order by, offset and limit binding to last select.
ParsesOk("(select a from test) union (select a from test) " +
"union select a from test union select a from test order by a limit 10");
ParsesOk("(select a from test) union (select a from test) " +
"union select a from test union select a from test order by a offset 10");
ParsesOk("(select a from test) union (select a from test) " +
"union select a from test union select a from test order by a");
// Union with order by and limit.
// Last select with order by and limit is in parenthesis.
ParsesOk("select a from test union (select a from test) " +
"union select a from test union (select a from test order by a limit 10) " +
"order by a limit 1");
ParsesOk("select a from test union (select a from test) " +
"union select a from test union (select a from test order by a offset 10) " +
"order by a limit 1");
ParsesOk("select a from test union (select a from test) " +
"union select a from test union (select a from test order by a) " +
"order by a limit 1");
// Union with order by, offset in first operand.
ParsesOk("select a from test order by a union select a from test");
ParsesOk("select a from test order by a offset 5 union select a from test");
ParsesOk("select a from test offset 5 union select a from test");
// Union with order by and limit.
// Last select with order by and limit is not in parenthesis.
ParsesOk("select a from test union select a from test " +
"union select a from test union select a from test order by a limit 10 " +
"order by a limit 1");
// Nested unions with order by and limit.
ParsesOk("select a union " +
"((select b) union (select c) order by 1 limit 1)");
ParsesOk("select a union " +
"((select b) union " +
" ((select c) union (select d) " +
" order by 1 limit 1) " +
" order by 1 limit 1)");
// Union in insert query.
ParsesOk("insert into table t select a from test union select a from test");
ParsesOk("insert into table t select a from test union select a from test " +
"union select a from test union select a from test");
ParsesOk("insert overwrite table t select a from test union select a from test");
ParsesOk("insert overwrite table t select a from test union select a from test " +
"union select a from test union select a from test");
// Union in upsert query.
ParsesOk("upsert into table t select a from test union select a from test");
ParsesOk("upsert into table t select a from test union select a from test " +
"union select a from test union select a from test");
// No complete select statement on lhs.
ParserError("a from test union select a from test");
// No complete select statement on rhs.
ParserError("select a from test union a from test");
// Union cannot be a column or table since it's a keyword.
ParserError("select union from test");
ParserError("select a from union");
}
@Test
public void TestValuesStmt() throws AnalysisException {
// Values stmt with a single row.
ParsesOk("values(1, 'a', abc, 1.0, *)");
ParsesOk("select * from (values(1, 'a', abc, 1.0, *)) as t");
ParsesOk("values(1, 'a', abc, 1.0, *) union all values(1, 'a', abc, 1.0, *)");
ParsesOk("insert into t values(1, 'a', abc, 1.0, *)");
ParsesOk("upsert into t values(1, 'a', abc, 1.0, *)");
// Values stmt with multiple rows.
ParsesOk("values(1, abc), ('x', cde), (2), (efg, fgh, ghi)");
ParsesOk("select * from (values(1, abc), ('x', cde), (2), (efg, fgh, ghi)) as t");
ParsesOk("values(1, abc), ('x', cde), (2), (efg, fgh, ghi) " +
"union all values(1, abc), ('x', cde), (2), (efg, fgh, ghi)");
ParsesOk("insert into t values(1, abc), ('x', cde), (2), (efg, fgh, ghi)");
ParsesOk("upsert into t values(1, abc), ('x', cde), (2), (efg, fgh, ghi)");
// Test additional parenthesis.
ParsesOk("(values(1, abc), ('x', cde), (2), (efg, fgh, ghi))");
ParsesOk("values((1, abc), ('x', cde), (2), (efg, fgh, ghi))");
ParsesOk("(values((1, abc), ('x', cde), (2), (efg, fgh, ghi)))");
// Test alias inside select list to assign column names.
ParsesOk("values(1 as x, 2 as y, 3 as z)");
// Test order by and limit.
ParsesOk("values(1, 'a') limit 10");
ParsesOk("values(1, 'a') order by 1");
ParsesOk("values(1, 'a') order by 1 limit 10");
ParsesOk("values(1, 'a') order by 1 offset 10");
ParsesOk("values(1, 'a') offset 10");
ParsesOk("values(1, 'a'), (2, 'b') order by 1 limit 10");
ParsesOk("values((1, 'a'), (2, 'b')) order by 1 limit 10");
ParserError("values()");
ParserError("values 1, 'a', abc, 1.0");
ParserError("values(1, 'a') values(1, 'a')");
ParserError("select values(1, 'a')");
ParserError("select * from values(1, 'a', abc, 1.0) as t");
ParserError("values((1, 2, 3), values(1, 2, 3))");
ParserError("values((1, 'a'), (1, 'a') order by 1)");
ParserError("values((1, 'a'), (1, 'a') limit 10)");
}
@Test
public void TestWithClause() throws AnalysisException {
ParsesOk("with t as (select 1 as a) select a from t");
ParsesOk("with t(x) as (select 1 as a) select x from t");
ParsesOk("with t as (select c from tab) select * from t");
ParsesOk("with t(x, y) as (select * from tab) select * from t");
ParsesOk("with t as (values(1, 2, 3), (4, 5, 6)) select * from t");
ParsesOk("with t(x, y, z) as (values(1, 2, 3), (4, 5, 6)) select * from t");
ParsesOk("with t1 as (select 1 as a), t2 as (select 2 as a) select a from t1");
ParsesOk("with t1 as (select c from tab), t2 as (select c from tab)" +
"select c from t2");
ParsesOk("with t1(x) as (select c from tab), t2(x) as (select c from tab)" +
"select x from t2");
// With clause and union statement.
ParsesOk("with t1 as (select 1 as a), t2 as (select 2 as a)" +
"select a from t1 union all select a from t2");
// With clause and join.
ParsesOk("with t1 as (select 1 as a), t2 as (select 2 as a)" +
"select a from t1 inner join t2 on t1.a = t2.a");
// With clause in inline view.
ParsesOk("select * from (with t as (select 1 as a) select * from t) as a");
ParsesOk("select * from (with t(x) as (select 1 as a) select * from t) as a");
// With clause in query statement of insert statement.
ParsesOk("insert into x with t as (select * from tab) select * from t");
ParsesOk("insert into x with t(x, y) as (select * from tab) select * from t");
ParsesOk("insert into x with t as (values(1, 2, 3)) select * from t");
ParsesOk("insert into x with t(x, y) as (values(1, 2, 3)) select * from t");
// With clause before insert statement.
ParsesOk("with t as (select 1) insert into x select * from t");
ParsesOk("with t(x) as (select 1) insert into x select * from t");
// With clause in query statement of upsert statement.
ParsesOk("upsert into x with t as (select * from tab) select * from t");
ParsesOk("upsert into x with t(x, y) as (select * from tab) select * from t");
ParsesOk("upsert into x with t as (values(1, 2, 3)) select * from t");
ParsesOk("upsert into x with t(x, y) as (values(1, 2, 3)) select * from t");
// With clause before upsert statement.
ParsesOk("with t as (select 1) upsert into x select * from t");
ParsesOk("with t(x) as (select 1) upsert into x select * from t");
// Test quoted identifier or string literal as table alias.
ParsesOk("with `t1` as (select 1 a), 't2' as (select 2 a), \"t3\" as (select 3 a)" +
"select a from t1 union all select a from t2 union all select a from t3");
// Multiple with clauses. Operands must be in parenthesis to
// have their own with clause.
ParsesOk("with t as (select 1) " +
"(with t as (select 2) select * from t) union all " +
"(with t as (select 3) select * from t)");
ParsesOk("with t as (select 1) " +
"(with t as (select 2) select * from t) union all " +
"(with t as (select 3) select * from t) order by 1 limit 1");
// Multiple with clauses. One before the insert and one inside the query statement.
ParsesOk("with t as (select 1) insert into x with t as (select 2) select * from t");
ParsesOk("with t(c1) as (select 1) " +
"insert into x with t(c2) as (select 2) select * from t");
// Multiple with clauses. One before the upsert and one inside the query statement.
ParsesOk("with t as (select 1) upsert into x with t as (select 2) select * from t");
ParsesOk("with t(c1) as (select 1) " +
"upsert into x with t(c2) as (select 2) select * from t");
// Empty with clause.
ParserError("with t as () select 1");
ParserError("with t(x) as () select 1");
// No labels inside parenthesis.
ParserError("with t() as (select 1 as a) select a from t");
// Missing select, union or insert statement after with clause.
ParserError("select * from (with t as (select 1 as a)) as a");
ParserError("with t as (select 1)");
// Missing parenthesis around with query statement.
ParserError("with t as select 1 as a select a from t");
ParserError("with t as select 1 as a union all select a from t");
ParserError("with t1 as (select 1 as a), t2 as select 2 as a select a from t");
ParserError("with t as select 1 as a select a from t");
// Missing parenthesis around column labels.
ParserError("with t c1 as (select 1 as a) select c1 from t");
// Insert in with clause is not valid.
ParserError("with t as (insert into x select * from tab) select * from t");
ParserError("with t(c1) as (insert into x select * from tab) select * from t");
// Upsert in with clause is not valid.
ParserError("with t as (upsert into x select * from tab) select * from t");
ParserError("with t(c1) as (upsert into x select * from tab) select * from t");
// Union operands need to be parenthesized to have their own with clause.
ParserError("select * from t union all with t as (select 2) select * from t");
}
@Test
public void TestNumericLiteralMinMaxValues() {
// Test integer types.
ParsesOk(String.format("select %s", Byte.toString(Byte.MIN_VALUE)));
ParsesOk(String.format("select %s", Byte.toString(Byte.MAX_VALUE)));
ParsesOk(String.format("select %s", Short.toString(Short.MIN_VALUE)));
ParsesOk(String.format("select %s", Short.toString(Short.MAX_VALUE)));
ParsesOk(String.format("select %s", Integer.toString(Integer.MIN_VALUE)));
ParsesOk(String.format("select %s", Integer.toString(Integer.MAX_VALUE)));
ParsesOk(String.format("select %s", Long.toString(Long.MIN_VALUE)));
ParsesOk(String.format("select %s", Long.toString(Long.MAX_VALUE)));
// Overflowing long integers parse ok. Analysis will handle it.
ParsesOk(String.format("select %s1", Long.toString(Long.MIN_VALUE)));
ParsesOk(String.format("select %s1", Long.toString(Long.MAX_VALUE)));
// Test min int64-1.
BigInteger minMinusOne = BigInteger.valueOf(Long.MAX_VALUE);
minMinusOne = minMinusOne.add(BigInteger.ONE);
ParsesOk(String.format("select %s", minMinusOne.toString()));
// Test max int64+1.
BigInteger maxPlusOne = BigInteger.valueOf(Long.MAX_VALUE);
maxPlusOne = maxPlusOne.add(BigInteger.ONE);
ParsesOk(String.format("select %s", maxPlusOne.toString()));
// Test floating-point types.
ParsesOk(String.format("select %s", Float.toString(Float.MIN_VALUE)));
ParsesOk(String.format("select %s", Float.toString(Float.MAX_VALUE)));
ParsesOk(String.format("select -%s", Float.toString(Float.MIN_VALUE)));
ParsesOk(String.format("select -%s", Float.toString(Float.MAX_VALUE)));
ParsesOk(String.format("select %s", Double.toString(Double.MIN_VALUE)));
ParsesOk(String.format("select %s", Double.toString(Double.MAX_VALUE)));
ParsesOk(String.format("select -%s", Double.toString(Double.MIN_VALUE)));
ParsesOk(String.format("select -%s", Double.toString(Double.MAX_VALUE)));
// Test overflow and underflow
ParsesOk(String.format("select %s1", Double.toString(Double.MIN_VALUE)));
ParsesOk(String.format("select %s1", Double.toString(Double.MAX_VALUE)));
}
@Test
public void TestIdentQuoting() {
ParsesOk("select a from `t`");
ParsesOk("select a from default.`t`");
ParsesOk("select a from default.t");
ParsesOk("select a from default.`t`");
ParsesOk("select 01a from default.`01_t`");
ParsesOk("select `a` from default.t");
ParsesOk("select `tbl`.`a` from default.t");
ParsesOk("select `db`.`tbl`.`a` from default.t");
ParsesOk("select `12db`.`tbl`.`12_a` from default.t");
// Make sure quoted float literals are identifiers.
ParsesOk("select `8e6`", SlotRef.class);
ParsesOk("select `4.5e2`", SlotRef.class);
ParsesOk("select `.7e9`", SlotRef.class);
// Mixed quoting
ParsesOk("select `db`.tbl.`a` from default.t");
ParsesOk("select `db.table.a` from default.t");
// Identifiers consisting of only whitespace not allowed.
ParserError("select a from ` `");
ParserError("select a from ` `");
// Empty quoted identifier doesn't parse.
ParserError("select a from ``");
// Whitespace can be interspersed with other characters.
// Whitespace is trimmed from the beginning and end of an identifier.
ParsesOk("select a from `a a a `");
ParsesOk("select a from ` a a a`");
ParsesOk("select a from ` a a a `");
// Quoted identifiers can contain any characters except "`".
ParsesOk("select a from `all types`");
ParsesOk("select a from default.`all types`");
ParsesOk("select a from `~!@#$%^&*()-_=+|;:'\",<.>/?`");
// Quoted identifiers do not unescape escape sequences.
ParsesOk("select a from `ab\rabc`");
ParsesOk("select a from `ab\tabc`");
ParsesOk("select a from `ab\fabc`");
ParsesOk("select a from `ab\babc`");
ParsesOk("select a from `ab\nabc`");
// Test non-printable control characters inside quoted identifiers.
ParsesOk("select a from `abc\u0000abc`");
ParsesOk("select a from `abc\u0019abc`");
ParsesOk("select a from `abc\u007fabc`");
// Quoted identifiers can contain keywords.
ParsesOk("select `select`, `insert`, `upsert` from `table` where `where` = 10");
// Quoted identifiers cannot contain "`"
ParserError("select a from `abcde`abcde`");
ParserError("select a from `abc\u0060abc`");
// Wrong quotes
ParserError("select a from 'default'.'t'");
// Lots of quoting
ParsesOk(
"select `db`.`tbl`.`a` from `default`.`t` `alias` where `alias`.`col` = 'string'"
+ " group by `alias`.`col`");
}
@Test
public void TestLiteralExprs() {
// negative integer literal
ParsesOk("select -1 from t where -1", NumericLiteral.class);
ParsesOk("select - 1 from t where - 1", NumericLiteral.class);
ParsesOk("select a - - 1 from t where a - - 1", ArithmeticExpr.class);
ParsesOk("select a - - - 1 from t where a - - - 1", ArithmeticExpr.class);