Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--
-- 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.
--

CREATE TEMPORARY VIEW t AS SELECT 1.0 as a, 0.0 as b;

-- division, remainder and pmod by 0 return NULL
select a / b from t;
select a % b from t;
select pmod(a, b) from t;

-- arithmetic operations causing an overflow return NULL
select (5e36 + 0.1) + 5e36;
select (-4e36 - 0.1) - 7e36;
select 12345678901234567890.0 * 12345678901234567890.0;
select 1e35 / 0.1;

-- arithmetic operations causing a precision loss return NULL
select 123456789123456789.1234567890 * 1.123456789123456789;
select 0.001 / 9876543210987654321098765432109876543.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--
-- 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.
--

CREATE TEMPORARY VIEW t AS SELECT 'aa' as a;

-- casting to data types which are unable to represent the string input returns NULL
select cast(a as byte) from t;
select cast(a as short) from t;
select cast(a as int) from t;
select cast(a as long) from t;
select cast(a as float) from t;
select cast(a as double) from t;
select cast(a as decimal) from t;
select cast(a as boolean) from t;
select cast(a as timestamp) from t;
select cast(a as date) from t;
-- casting to binary works correctly
select cast(a as binary) from t;
-- casting to array, struct or map throws exception
select cast(a as array<string>) from t;
select cast(a as struct<s:string>) from t;
select cast(a as map<string, string>) from t;

-- all timestamp/date expressions return NULL if bad input strings are provided
select to_timestamp(a) from t;
select to_timestamp('2018-01-01', a) from t;
select to_unix_timestamp(a) from t;
select to_unix_timestamp('2018-01-01', a) from t;
select unix_timestamp(a) from t;
select unix_timestamp('2018-01-01', a) from t;
select from_unixtime(a) from t;
select from_unixtime('2018-01-01', a) from t;
select next_day(a, 'MO') from t;
select next_day('2018-01-01', a) from t;
select trunc(a, 'MM') from t;
select trunc('2018-01-01', a) from t;

-- some functions return NULL if bad input is provided
select unhex('-123');
select sha2(a, a) from t;
select get_json_object(a, a) from t;
select json_tuple(a, a) from t;
select from_json(a, 'a INT') from t;
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 10


-- !query 0
CREATE TEMPORARY VIEW t AS SELECT 1.0 as a, 0.0 as b
-- !query 0 schema
struct<>
-- !query 0 output



-- !query 1
select a / b from t
-- !query 1 schema
struct<(CAST(a AS DECIMAL(2,1)) / CAST(b AS DECIMAL(2,1))):decimal(8,6)>
-- !query 1 output
NULL


-- !query 2
select a % b from t
-- !query 2 schema
struct<(CAST(a AS DECIMAL(2,1)) % CAST(b AS DECIMAL(2,1))):decimal(1,1)>
-- !query 2 output
NULL


-- !query 3
select pmod(a, b) from t
-- !query 3 schema
struct<pmod(CAST(a AS DECIMAL(2,1)), CAST(b AS DECIMAL(2,1))):decimal(1,1)>
-- !query 3 output
NULL


-- !query 4
select (5e36 + 0.1) + 5e36
-- !query 4 schema
struct<(CAST((CAST(5E+36 AS DECIMAL(38,1)) + CAST(0.1 AS DECIMAL(38,1))) AS DECIMAL(38,1)) + CAST(5E+36 AS DECIMAL(38,1))):decimal(38,1)>
-- !query 4 output
NULL


-- !query 5
select (-4e36 - 0.1) - 7e36
-- !query 5 schema
struct<(CAST((CAST(-4E+36 AS DECIMAL(38,1)) - CAST(0.1 AS DECIMAL(38,1))) AS DECIMAL(38,1)) - CAST(7E+36 AS DECIMAL(38,1))):decimal(38,1)>
-- !query 5 output
NULL


-- !query 6
select 12345678901234567890.0 * 12345678901234567890.0
-- !query 6 schema
struct<(12345678901234567890.0 * 12345678901234567890.0):decimal(38,2)>
-- !query 6 output
NULL


-- !query 7
select 1e35 / 0.1
-- !query 7 schema
struct<(CAST(1E+35 AS DECIMAL(37,1)) / CAST(0.1 AS DECIMAL(37,1))):decimal(38,3)>
-- !query 7 output
NULL


-- !query 8
select 123456789123456789.1234567890 * 1.123456789123456789
-- !query 8 schema
struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,28)>
-- !query 8 output
NULL


-- !query 9
select 0.001 / 9876543210987654321098765432109876543.2
-- !query 9 schema
struct<(CAST(0.001 AS DECIMAL(38,3)) / CAST(9876543210987654321098765432109876543.2 AS DECIMAL(38,3))):decimal(38,37)>
-- !query 9 output
NULL
Loading