Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
179 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-- | ||
-- 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. | ||
-- | ||
|
||
-- test for interacting with intervals | ||
|
||
-- using SQL_STANDARD output style | ||
set spark.sql.IntervalOutputStyle=SQL_STANDARD; | ||
select interval 4 month 2 weeks 3 microseconds; | ||
select interval '1 year 20 month'; | ||
select interval '-1 year -20 month'; | ||
select interval '20 month 30 days -21 hours 10 minutes 999 milliseconds'; | ||
select date'2019-10-15' - timestamp'2019-10-15 10:11:12.001002'; | ||
|
||
-- using MULTI_UNITS (which is default) output style | ||
set spark.sql.IntervalOutputStyle=MULTI_UNITS; | ||
|
||
-- interval operations | ||
select 3 * (timestamp'2019-10-15 10:11:12.001002' - date'2019-10-15'); | ||
select interval 4 month 2 weeks 3 microseconds * 1.5; | ||
select (timestamp'2019-10-15' - timestamp'2019-10-14') / 1.5; | ||
|
||
-- interval operation with null and zero case | ||
select interval '2 seconds' / 0; | ||
select interval '2 seconds' / null; | ||
select interval '2 seconds' * null; | ||
select null * interval '2 seconds'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
sql/core/src/test/resources/sql-tests/results/interval.sql.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
-- Automatically generated by SQLQueryTestSuite | ||
-- Number of queries: 14 | ||
|
||
|
||
-- !query 0 | ||
set spark.sql.IntervalOutputStyle=SQL_STANDARD | ||
-- !query 0 schema | ||
struct<key:string,value:string> | ||
-- !query 0 output | ||
spark.sql.IntervalOutputStyle SQL_STANDARD | ||
|
||
|
||
-- !query 1 | ||
select interval 4 month 2 weeks 3 microseconds | ||
-- !query 1 schema | ||
struct<4 months 14 days 0.000003 seconds:interval> | ||
-- !query 1 output | ||
0-4 14 0:00:00.000003 | ||
|
||
|
||
-- !query 2 | ||
select interval '1 year 20 month' | ||
-- !query 2 schema | ||
struct<2 years 8 months:interval> | ||
-- !query 2 output | ||
2-8 | ||
|
||
|
||
-- !query 3 | ||
select interval '-1 year -20 month' | ||
-- !query 3 schema | ||
struct<-2 years -8 months:interval> | ||
-- !query 3 output | ||
-2-8 | ||
|
||
|
||
-- !query 4 | ||
select interval '20 month 30 days -21 hours 10 minutes 999 milliseconds' | ||
-- !query 4 schema | ||
struct<1 years 8 months 30 days -20 hours -49 minutes -59.001 seconds:interval> | ||
-- !query 4 output | ||
1-8 30 -20:49:59.001 | ||
|
||
|
||
-- !query 5 | ||
select date'2019-10-15' - timestamp'2019-10-15 10:11:12.001002' | ||
-- !query 5 schema | ||
struct<subtracttimestamps(CAST(DATE '2019-10-15' AS TIMESTAMP), TIMESTAMP('2019-10-15 10:11:12.001002')):interval> | ||
-- !query 5 output | ||
-10:11:12.001002 | ||
|
||
|
||
-- !query 6 | ||
set spark.sql.IntervalOutputStyle=MULTI_UNITS | ||
-- !query 6 schema | ||
struct<key:string,value:string> | ||
-- !query 6 output | ||
spark.sql.IntervalOutputStyle MULTI_UNITS | ||
|
||
|
||
-- !query 7 | ||
select 3 * (timestamp'2019-10-15 10:11:12.001002' - date'2019-10-15') | ||
-- !query 7 schema | ||
struct<multiply_interval(subtracttimestamps(TIMESTAMP('2019-10-15 10:11:12.001002'), CAST(DATE '2019-10-15' AS TIMESTAMP)), CAST(3 AS DOUBLE)):interval> | ||
-- !query 7 output | ||
30 hours 33 minutes 36.003006 seconds | ||
|
||
|
||
-- !query 8 | ||
select interval 4 month 2 weeks 3 microseconds * 1.5 | ||
-- !query 8 schema | ||
struct<multiply_interval(4 months 14 days 0.000003 seconds, CAST(1.5 AS DOUBLE)):interval> | ||
-- !query 8 output | ||
6 months 21 days 0.000005 seconds | ||
|
||
|
||
-- !query 9 | ||
select (timestamp'2019-10-15' - timestamp'2019-10-14') / 1.5 | ||
-- !query 9 schema | ||
struct<divide_interval(subtracttimestamps(TIMESTAMP('2019-10-15 00:00:00'), TIMESTAMP('2019-10-14 00:00:00')), CAST(1.5 AS DOUBLE)):interval> | ||
-- !query 9 output | ||
16 hours | ||
|
||
|
||
-- !query 10 | ||
select interval '2 seconds' / 0 | ||
-- !query 10 schema | ||
struct<divide_interval(2 seconds, CAST(0 AS DOUBLE)):interval> | ||
-- !query 10 output | ||
NULL | ||
|
||
|
||
-- !query 11 | ||
select interval '2 seconds' / null | ||
-- !query 11 schema | ||
struct<divide_interval(2 seconds, CAST(NULL AS DOUBLE)):interval> | ||
-- !query 11 output | ||
NULL | ||
|
||
|
||
-- !query 12 | ||
select interval '2 seconds' * null | ||
-- !query 12 schema | ||
struct<multiply_interval(2 seconds, CAST(NULL AS DOUBLE)):interval> | ||
-- !query 12 output | ||
NULL | ||
|
||
|
||
-- !query 13 | ||
select null * interval '2 seconds' | ||
-- !query 13 schema | ||
struct<multiply_interval(2 seconds, CAST(NULL AS DOUBLE)):interval> | ||
-- !query 13 output | ||
NULL |