Skip to content

Commit bd6be16

Browse files
committed
reduce scope
1 parent 94e2fce commit bd6be16

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ class Analyzer(
295295
case (CalendarIntervalType, CalendarIntervalType) => a
296296
case (_, CalendarIntervalType) => Cast(TimeAdd(l, r), l.dataType)
297297
case (CalendarIntervalType, _) => Cast(TimeAdd(r, l), r.dataType)
298-
case (DateType, _) => DateAdd(l, r)
299-
case (_, DateType) => DateAdd(r, l)
298+
case (DateType, dt) if dt != StringType => DateAdd(l, r)
299+
case (dt, DateType) if dt != StringType => DateAdd(r, l)
300300
case _ => a
301301
}
302302
case s @ Subtract(l, r) if s.childrenResolved => (l.dataType, r.dataType) match {
@@ -305,7 +305,7 @@ class Analyzer(
305305
case (TimestampType, _) => SubtractTimestamps(l, r)
306306
case (_, TimestampType) => SubtractTimestamps(l, r)
307307
case (_, DateType) => SubtractDates(l, r)
308-
case (DateType, _) => DateSub(l, r)
308+
case (DateType, dt) if dt != StringType => DateSub(l, r)
309309
case _ => s
310310
}
311311
case m @ Multiply(l, r) if m.childrenResolved => (l.dataType, r.dataType) match {

sql/core/src/test/resources/sql-tests/inputs/datetime.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ select date_sub(timestamp'2011-11-11', 1);
6868
select date_sub(null, 1);
6969
select date_sub(date'2011-11-11', null);
7070
select date'2011-11-11' + 1E1;
71+
select date'2011-11-11' + '1';
7172
select null + date '2001-09-28';
7273
select date '2001-09-28' + 7Y;
7374
select 7S + date '2001-09-28';
7475
select date '2001-10-01' - 7;
76+
select date '2001-10-01' - '7';
7577
select date '2001-09-28' + null;
7678
select date '2001-09-28' - null;
7779

sql/core/src/test/resources/sql-tests/results/datetime.sql.out

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Automatically generated by SQLQueryTestSuite
2-
-- Number of queries: 83
2+
-- Number of queries: 85
33

44

55
-- !query
@@ -354,6 +354,15 @@ org.apache.spark.sql.AnalysisException
354354
cannot resolve 'date_add(DATE '2011-11-11', 10.0D)' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, '10.0D' is of double type.; line 1 pos 7
355355

356356

357+
-- !query
358+
select date'2011-11-11' + '1'
359+
-- !query schema
360+
struct<>
361+
-- !query output
362+
org.apache.spark.sql.AnalysisException
363+
cannot resolve 'date_add(DATE '2011-11-11', CAST('1' AS DOUBLE))' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, 'CAST('1' AS DOUBLE)' is of double type.; line 1 pos 7
364+
365+
357366
-- !query
358367
select null + date '2001-09-28'
359368
-- !query schema
@@ -386,6 +395,15 @@ struct<date_sub(DATE '2001-10-01', 7):date>
386395
2001-09-24
387396

388397

398+
-- !query
399+
select date '2001-10-01' - '7'
400+
-- !query schema
401+
struct<>
402+
-- !query output
403+
org.apache.spark.sql.AnalysisException
404+
cannot resolve 'date_sub(DATE '2001-10-01', CAST('7' AS DOUBLE))' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, 'CAST('7' AS DOUBLE)' is of double type.; line 1 pos 7
405+
406+
389407
-- !query
390408
select date '2001-09-28' + null
391409
-- !query schema

sql/core/src/test/resources/sql-tests/results/typeCoercion/native/promoteStrings.sql.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ SELECT '1' + cast('2017-12-11 09:30:00' as date) FROM t
107107
struct<>
108108
-- !query output
109109
org.apache.spark.sql.AnalysisException
110-
cannot resolve 'date_add(CAST('2017-12-11 09:30:00' AS DATE), '1')' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, ''1'' is of string type.; line 1 pos 7
110+
cannot resolve 'date_add(CAST('2017-12-11 09:30:00' AS DATE), CAST('1' AS DOUBLE))' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, 'CAST('1' AS DOUBLE)' is of double type.; line 1 pos 7
111111

112112

113113
-- !query
@@ -698,7 +698,7 @@ SELECT cast('2017-12-11 09:30:00' as date) + '1' FROM t
698698
struct<>
699699
-- !query output
700700
org.apache.spark.sql.AnalysisException
701-
cannot resolve 'date_add(CAST('2017-12-11 09:30:00' AS DATE), '1')' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, ''1'' is of string type.; line 1 pos 7
701+
cannot resolve 'date_add(CAST('2017-12-11 09:30:00' AS DATE), CAST('1' AS DOUBLE))' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, 'CAST('1' AS DOUBLE)' is of double type.; line 1 pos 7
702702

703703

704704
-- !query
@@ -790,7 +790,7 @@ SELECT cast('2017-12-11 09:30:00' as date) - '1' FROM t
790790
struct<>
791791
-- !query output
792792
org.apache.spark.sql.AnalysisException
793-
cannot resolve 'date_sub(CAST('2017-12-11 09:30:00' AS DATE), '1')' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, ''1'' is of string type.; line 1 pos 7
793+
cannot resolve 'date_sub(CAST('2017-12-11 09:30:00' AS DATE), CAST('1' AS DOUBLE))' due to data type mismatch: argument 2 requires (int or smallint or tinyint) type, however, 'CAST('1' AS DOUBLE)' is of double type.; line 1 pos 7
794794

795795

796796
-- !query

0 commit comments

Comments
 (0)