Skip to content

Commit 17a3c77

Browse files
committed
address comment from Wenchen
1 parent 6d978c6 commit 17a3c77

9 files changed

Lines changed: 63 additions & 76 deletions

File tree

docs/sql-keywords.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ license: |
1919
limitations under the License.
2020
---
2121

22-
When `spark.sql.dialect.spark.ansi.enabled` is true, Spark SQL will use the ANSI mode parser.
22+
When `spark.sql.ansi.enabled` is true, Spark SQL will use the ANSI mode parser.
2323
In this mode, Spark SQL has two kinds of keywords:
2424
* Reserved keywords: Keywords that are reserved and can't be used as identifiers for table, view, column, function, alias, etc.
2525
* Non-reserved keywords: Keywords that have a special meaning only in particular contexts and can be used as identifiers in other contexts. For example, `SELECT 1 WEEK` is an interval literal, but WEEK can be used as identifiers in other places.

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,7 @@ class Analyzer(
286286
case (_, CalendarIntervalType) => Cast(TimeSub(l, r), l.dataType)
287287
case (TimestampType, _) => SubtractTimestamps(l, r)
288288
case (_, TimestampType) => SubtractTimestamps(l, r)
289-
case (_, DateType) => if (conf.ansiEnabled) {
290-
DateDiff(l, r)
291-
} else {
292-
SubtractDates(l, r)
293-
}
289+
case (_, DateType) => SubtractDates(l, r)
294290
case (DateType, _) => DateSub(l, r)
295291
case _ => s
296292
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,7 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
11311131
checkEvaluation(SubtractDates(Literal(end), epochDate),
11321132
IntervalUtils.stringToInterval(UTF8String.fromString("interval 49 years 9 months 4 days")))
11331133
checkEvaluation(SubtractDates(epochDate, Literal(end)),
1134-
IntervalUtils.stringToInterval(UTF8String.fromString(
1135-
"interval -49 years -9 months -4 days")))
1134+
IntervalUtils.stringToInterval(UTF8String.fromString("interval -49 years -9 months -4 days")))
11361135
checkEvaluation(
11371136
SubtractDates(
11381137
Literal(LocalDate.of(10000, 1, 1)),

sql/core/src/test/resources/sql-tests/inputs/postgreSQL/boolean.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ SELECT false AS `false`;
2222

2323
SELECT boolean('t') AS true;
2424

25-
-- [SPARK-27931] Trim the string when cast string type to boolean type
2625
SELECT boolean(' f ') AS `false`;
2726

2827
SELECT boolean('true') AS true;
@@ -49,12 +48,10 @@ SELECT boolean('no') AS `false`;
4948
-- [SPARK-27923] PostgreSQL does not accept 'nay' but Spark SQL accepts it and sets it to NULL
5049
SELECT boolean('nay') AS error;
5150

52-
-- [SPARK-27931] Accept 'on' and 'off' as input for boolean data type
5351
SELECT boolean('on') AS true;
5452

5553
SELECT boolean('off') AS `false`;
5654

57-
-- [SPARK-27931] Accept unique prefixes thereof
5855
SELECT boolean('of') AS `false`;
5956

6057
-- [SPARK-27923] PostgreSQL does not accept 'o' but Spark SQL accepts it and sets it to NULL
@@ -101,7 +98,6 @@ SELECT boolean('f') <= boolean('t') AS true;
10198

10299
-- explicit casts to/from text
103100
SELECT boolean(string('TrUe')) AS true, boolean(string('fAlse')) AS `false`;
104-
-- [SPARK-27931] Trim the string when cast to boolean type
105101
SELECT boolean(string(' true ')) AS true,
106102
boolean(string(' FALSE')) AS `false`;
107103
SELECT string(boolean(true)) AS true, string(boolean(false)) AS `false`;

sql/core/src/test/resources/sql-tests/inputs/postgreSQL/int2.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ WHERE f1 > -32767;
9292

9393
SELECT '' AS five, i.f1, i.f1 - int('2') AS x FROM INT2_TBL i;
9494

95-
-- PostgreSQL `/` is the same with Spark `div` since SPARK-2659.
96-
SELECT '' AS five, i.f1, i.f1 div smallint('2') AS x FROM INT2_TBL i;
95+
SELECT '' AS five, i.f1, i.f1 / smallint('2') AS x FROM INT2_TBL i;
9796

98-
-- PostgreSQL `/` is the same with Spark `div` since SPARK-2659.
99-
SELECT '' AS five, i.f1, i.f1 div int('2') AS x FROM INT2_TBL i;
97+
SELECT '' AS five, i.f1, i.f1 / int('2') AS x FROM INT2_TBL i;
10098

10199
-- corner cases
102100
SELECT string(shiftleft(smallint(-1), 15));

sql/core/src/test/resources/sql-tests/inputs/postgreSQL/int4.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ SELECT int('1000') < int('999') AS `false`;
138138

139139
SELECT 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS ten;
140140

141-
-- [SPARK-2659] HiveQL: Division operator should always perform fractional division
142141
SELECT 2 + 2 / 2 AS three;
143142

144143
SELECT (2 + 2) / 2 AS two;

sql/core/src/test/resources/sql-tests/inputs/postgreSQL/int8.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ SELECT 37 - q1 AS minus4 FROM INT8_TBL;
8787
SELECT '' AS five, 2 * q1 AS `twice int4` FROM INT8_TBL;
8888
SELECT '' AS five, q1 * 2 AS `twice int4` FROM INT8_TBL;
8989

90-
-- [SPARK-2659] HiveQL: Division operator should always perform fractional division
9190
-- int8 op int4
9291
SELECT q1 + int(42) AS `8plus4`, q1 - int(42) AS `8minus4`, q1 * int(42) AS `8mul4`, q1 / int(42) AS `8div4` FROM INT8_TBL;
9392
-- int4 op int8

sql/core/src/test/resources/sql-tests/results/postgreSQL/date.sql.out

100644100755
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -482,93 +482,93 @@ SELECT date '5874898-01-01'
482482
-- !query 46
483483
SELECT f1 - date '2000-01-01' AS `Days From 2K` FROM DATE_TBL
484484
-- !query 46 schema
485-
struct<Days From 2K:int>
485+
struct<Days From 2K:interval>
486486
-- !query 46 output
487-
-1035
488-
-1036
489-
-1037
490-
-1400
491-
-1401
492-
-1402
493-
-1403
494-
-15542
495-
-15607
496-
13977
497-
14343
498-
14710
499-
91
500-
92
501-
93
487+
-2 years -10 months
488+
-2 years -10 months -1 days
489+
-2 years -9 months -30 days
490+
-3 years -10 months
491+
-3 years -10 months -1 days
492+
-3 years -10 months -2 days
493+
-3 years -9 months -30 days
494+
-42 years -6 months -18 days
495+
-42 years -8 months -22 days
496+
3 months
497+
3 months 1 days
498+
3 months 2 days
499+
38 years 3 months 7 days
500+
39 years 3 months 8 days
501+
40 years 3 months 9 days
502502

503503

504504
-- !query 47
505505
SELECT f1 - date 'epoch' AS `Days From Epoch` FROM DATE_TBL
506506
-- !query 47 schema
507-
struct<Days From Epoch:int>
507+
struct<Days From Epoch:interval>
508508
-- !query 47 output
509-
-4585
510-
-4650
511-
11048
512-
11049
513-
11050
514-
24934
515-
25300
516-
25667
517-
9554
518-
9555
519-
9556
520-
9557
521-
9920
522-
9921
523-
9922
509+
-12 years -6 months -18 days
510+
-12 years -8 months -22 days
511+
26 years 1 months 27 days
512+
26 years 1 months 28 days
513+
26 years 2 months
514+
26 years 2 months 1 days
515+
27 years 1 months 27 days
516+
27 years 2 months
517+
27 years 2 months 1 days
518+
30 years 3 months
519+
30 years 3 months 1 days
520+
30 years 3 months 2 days
521+
68 years 3 months 7 days
522+
69 years 3 months 8 days
523+
70 years 3 months 9 days
524524

525525

526526
-- !query 48
527527
SELECT date 'yesterday' - date 'today' AS `One day`
528528
-- !query 48 schema
529-
struct<One day:int>
529+
struct<One day:interval>
530530
-- !query 48 output
531-
-1
531+
-1 days
532532

533533

534534
-- !query 49
535535
SELECT date 'today' - date 'tomorrow' AS `One day`
536536
-- !query 49 schema
537-
struct<One day:int>
537+
struct<One day:interval>
538538
-- !query 49 output
539-
-1
539+
-1 days
540540

541541

542542
-- !query 50
543543
SELECT date 'yesterday' - date 'tomorrow' AS `Two days`
544544
-- !query 50 schema
545-
struct<Two days:int>
545+
struct<Two days:interval>
546546
-- !query 50 output
547-
-2
547+
-2 days
548548

549549

550550
-- !query 51
551551
SELECT date 'tomorrow' - date 'today' AS `One day`
552552
-- !query 51 schema
553-
struct<One day:int>
553+
struct<One day:interval>
554554
-- !query 51 output
555-
1
555+
1 days
556556

557557

558558
-- !query 52
559559
SELECT date 'today' - date 'yesterday' AS `One day`
560560
-- !query 52 schema
561-
struct<One day:int>
561+
struct<One day:interval>
562562
-- !query 52 output
563-
1
563+
1 days
564564

565565

566566
-- !query 53
567567
SELECT date 'tomorrow' - date 'yesterday' AS `Two days`
568568
-- !query 53 schema
569-
struct<Two days:int>
569+
struct<Two days:interval>
570570
-- !query 53 output
571-
2
571+
2 days
572572

573573

574574
-- !query 54

sql/core/src/test/resources/sql-tests/results/postgreSQL/int2.sql.out

100644100755
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,27 +266,27 @@ struct<five:string,f1:smallint,x:int>
266266

267267

268268
-- !query 27
269-
SELECT '' AS five, i.f1, i.f1 div smallint('2') AS x FROM INT2_TBL i
269+
SELECT '' AS five, i.f1, i.f1 / smallint('2') AS x FROM INT2_TBL i
270270
-- !query 27 schema
271-
struct<five:string,f1:smallint,x:smallint>
271+
struct<five:string,f1:smallint,x:double>
272272
-- !query 27 output
273-
-1234 -617
274-
-32767 -16383
275-
0 0
276-
1234 617
277-
32767 16383
273+
-1234 -617.0
274+
-32767 -16383.5
275+
0 0.0
276+
1234 617.0
277+
32767 16383.5
278278

279279

280280
-- !query 28
281-
SELECT '' AS five, i.f1, i.f1 div int('2') AS x FROM INT2_TBL i
281+
SELECT '' AS five, i.f1, i.f1 / int('2') AS x FROM INT2_TBL i
282282
-- !query 28 schema
283-
struct<five:string,f1:smallint,x:int>
283+
struct<five:string,f1:smallint,x:double>
284284
-- !query 28 output
285-
-1234 -617
286-
-32767 -16383
287-
0 0
288-
1234 617
289-
32767 16383
285+
-1234 -617.0
286+
-32767 -16383.5
287+
0 0.0
288+
1234 617.0
289+
32767 16383.5
290290

291291

292292
-- !query 29

0 commit comments

Comments
 (0)