Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-22726] [TEST] Basic tests for Binary Comparison and ImplicitTypeCasts #19918

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,287 @@
--
-- 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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the test cases are based on Apache Derby, I keep Apache license here.

--

-- Binary Comparison

CREATE TEMPORARY VIEW t AS SELECT 1;

SELECT cast(1 as binary) = '1' FROM t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems binary comparison without <=>.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea <=> is missed. Do Derby tests also miss it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be OK as <=> should have same type coercion rule as =

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=== is consistent with <=>

I think we can skip it. Then, we can run the whole suite to Hive with minor changes.

SELECT cast(1 as binary) > '2' FROM t;
SELECT cast(1 as binary) >= '2' FROM t;
SELECT cast(1 as binary) < '2' FROM t;
SELECT cast(1 as binary) <= '2' FROM t;
SELECT cast(1 as binary) <> '2' FROM t;
SELECT cast(1 as binary) = cast(null as string) FROM t;
SELECT cast(1 as binary) > cast(null as string) FROM t;
SELECT cast(1 as binary) >= cast(null as string) FROM t;
SELECT cast(1 as binary) < cast(null as string) FROM t;
SELECT cast(1 as binary) <= cast(null as string) FROM t;
SELECT cast(1 as binary) <> cast(null as string) FROM t;
SELECT '1' = cast(1 as binary) FROM t;
SELECT '2' > cast(1 as binary) FROM t;
SELECT '2' >= cast(1 as binary) FROM t;
SELECT '2' < cast(1 as binary) FROM t;
SELECT '2' <= cast(1 as binary) FROM t;
SELECT '2' <> cast(1 as binary) FROM t;
SELECT cast(null as string) = cast(1 as binary) FROM t;
SELECT cast(null as string) > cast(1 as binary) FROM t;
SELECT cast(null as string) >= cast(1 as binary) FROM t;
SELECT cast(null as string) < cast(1 as binary) FROM t;
SELECT cast(null as string) <= cast(1 as binary) FROM t;
SELECT cast(null as string) <> cast(1 as binary) FROM t;
SELECT cast(1 as tinyint) = '1' FROM t;
SELECT cast(1 as tinyint) > '2' FROM t;
SELECT cast(1 as tinyint) >= '2' FROM t;
SELECT cast(1 as tinyint) < '2' FROM t;
SELECT cast(1 as tinyint) <= '2' FROM t;
SELECT cast(1 as tinyint) <> '2' FROM t;
SELECT cast(1 as tinyint) = cast(null as string) FROM t;
SELECT cast(1 as tinyint) > cast(null as string) FROM t;
SELECT cast(1 as tinyint) >= cast(null as string) FROM t;
SELECT cast(1 as tinyint) < cast(null as string) FROM t;
SELECT cast(1 as tinyint) <= cast(null as string) FROM t;
SELECT cast(1 as tinyint) <> cast(null as string) FROM t;
SELECT '1' = cast(1 as tinyint) FROM t;
SELECT '2' > cast(1 as tinyint) FROM t;
SELECT '2' >= cast(1 as tinyint) FROM t;
SELECT '2' < cast(1 as tinyint) FROM t;
SELECT '2' <= cast(1 as tinyint) FROM t;
SELECT '2' <> cast(1 as tinyint) FROM t;
SELECT cast(null as string) = cast(1 as tinyint) FROM t;
SELECT cast(null as string) > cast(1 as tinyint) FROM t;
SELECT cast(null as string) >= cast(1 as tinyint) FROM t;
SELECT cast(null as string) < cast(1 as tinyint) FROM t;
SELECT cast(null as string) <= cast(1 as tinyint) FROM t;
SELECT cast(null as string) <> cast(1 as tinyint) FROM t;
SELECT cast(1 as smallint) = '1' FROM t;
SELECT cast(1 as smallint) > '2' FROM t;
SELECT cast(1 as smallint) >= '2' FROM t;
SELECT cast(1 as smallint) < '2' FROM t;
SELECT cast(1 as smallint) <= '2' FROM t;
SELECT cast(1 as smallint) <> '2' FROM t;
SELECT cast(1 as smallint) = cast(null as string) FROM t;
SELECT cast(1 as smallint) > cast(null as string) FROM t;
SELECT cast(1 as smallint) >= cast(null as string) FROM t;
SELECT cast(1 as smallint) < cast(null as string) FROM t;
SELECT cast(1 as smallint) <= cast(null as string) FROM t;
SELECT cast(1 as smallint) <> cast(null as string) FROM t;
SELECT '1' = cast(1 as smallint) FROM t;
SELECT '2' > cast(1 as smallint) FROM t;
SELECT '2' >= cast(1 as smallint) FROM t;
SELECT '2' < cast(1 as smallint) FROM t;
SELECT '2' <= cast(1 as smallint) FROM t;
SELECT '2' <> cast(1 as smallint) FROM t;
SELECT cast(null as string) = cast(1 as smallint) FROM t;
SELECT cast(null as string) > cast(1 as smallint) FROM t;
SELECT cast(null as string) >= cast(1 as smallint) FROM t;
SELECT cast(null as string) < cast(1 as smallint) FROM t;
SELECT cast(null as string) <= cast(1 as smallint) FROM t;
SELECT cast(null as string) <> cast(1 as smallint) FROM t;
SELECT cast(1 as int) = '1' FROM t;
SELECT cast(1 as int) > '2' FROM t;
SELECT cast(1 as int) >= '2' FROM t;
SELECT cast(1 as int) < '2' FROM t;
SELECT cast(1 as int) <= '2' FROM t;
SELECT cast(1 as int) <> '2' FROM t;
SELECT cast(1 as int) = cast(null as string) FROM t;
SELECT cast(1 as int) > cast(null as string) FROM t;
SELECT cast(1 as int) >= cast(null as string) FROM t;
SELECT cast(1 as int) < cast(null as string) FROM t;
SELECT cast(1 as int) <= cast(null as string) FROM t;
SELECT cast(1 as int) <> cast(null as string) FROM t;
SELECT '1' = cast(1 as int) FROM t;
SELECT '2' > cast(1 as int) FROM t;
SELECT '2' >= cast(1 as int) FROM t;
SELECT '2' < cast(1 as int) FROM t;
SELECT '2' <> cast(1 as int) FROM t;
SELECT '2' <= cast(1 as int) FROM t;
SELECT cast(null as string) = cast(1 as int) FROM t;
SELECT cast(null as string) > cast(1 as int) FROM t;
SELECT cast(null as string) >= cast(1 as int) FROM t;
SELECT cast(null as string) < cast(1 as int) FROM t;
SELECT cast(null as string) <> cast(1 as int) FROM t;
SELECT cast(null as string) <= cast(1 as int) FROM t;
SELECT cast(1 as bigint) = '1' FROM t;
SELECT cast(1 as bigint) > '2' FROM t;
SELECT cast(1 as bigint) >= '2' FROM t;
SELECT cast(1 as bigint) < '2' FROM t;
SELECT cast(1 as bigint) <= '2' FROM t;
SELECT cast(1 as bigint) <> '2' FROM t;
SELECT cast(1 as bigint) = cast(null as string) FROM t;
SELECT cast(1 as bigint) > cast(null as string) FROM t;
SELECT cast(1 as bigint) >= cast(null as string) FROM t;
SELECT cast(1 as bigint) < cast(null as string) FROM t;
SELECT cast(1 as bigint) <= cast(null as string) FROM t;
SELECT cast(1 as bigint) <> cast(null as string) FROM t;
SELECT '1' = cast(1 as bigint) FROM t;
SELECT '2' > cast(1 as bigint) FROM t;
SELECT '2' >= cast(1 as bigint) FROM t;
SELECT '2' < cast(1 as bigint) FROM t;
SELECT '2' <= cast(1 as bigint) FROM t;
SELECT '2' <> cast(1 as bigint) FROM t;
SELECT cast(null as string) = cast(1 as bigint) FROM t;
SELECT cast(null as string) > cast(1 as bigint) FROM t;
SELECT cast(null as string) >= cast(1 as bigint) FROM t;
SELECT cast(null as string) < cast(1 as bigint) FROM t;
SELECT cast(null as string) <= cast(1 as bigint) FROM t;
SELECT cast(null as string) <> cast(1 as bigint) FROM t;
SELECT cast(1 as decimal(10, 0)) = '1' FROM t;
SELECT cast(1 as decimal(10, 0)) > '2' FROM t;
SELECT cast(1 as decimal(10, 0)) >= '2' FROM t;
SELECT cast(1 as decimal(10, 0)) < '2' FROM t;
SELECT cast(1 as decimal(10, 0)) <> '2' FROM t;
SELECT cast(1 as decimal(10, 0)) <= '2' FROM t;
SELECT cast(1 as decimal(10, 0)) = cast(null as string) FROM t;
SELECT cast(1 as decimal(10, 0)) > cast(null as string) FROM t;
SELECT cast(1 as decimal(10, 0)) >= cast(null as string) FROM t;
SELECT cast(1 as decimal(10, 0)) < cast(null as string) FROM t;
SELECT cast(1 as decimal(10, 0)) <> cast(null as string) FROM t;
SELECT cast(1 as decimal(10, 0)) <= cast(null as string) FROM t;
SELECT '1' = cast(1 as decimal(10, 0)) FROM t;
SELECT '2' > cast(1 as decimal(10, 0)) FROM t;
SELECT '2' >= cast(1 as decimal(10, 0)) FROM t;
SELECT '2' < cast(1 as decimal(10, 0)) FROM t;
SELECT '2' <= cast(1 as decimal(10, 0)) FROM t;
SELECT '2' <> cast(1 as decimal(10, 0)) FROM t;
SELECT cast(null as string) = cast(1 as decimal(10, 0)) FROM t;
SELECT cast(null as string) > cast(1 as decimal(10, 0)) FROM t;
SELECT cast(null as string) >= cast(1 as decimal(10, 0)) FROM t;
SELECT cast(null as string) < cast(1 as decimal(10, 0)) FROM t;
SELECT cast(null as string) <= cast(1 as decimal(10, 0)) FROM t;
SELECT cast(null as string) <> cast(1 as decimal(10, 0)) FROM t;
SELECT cast(1 as double) = '1' FROM t;
SELECT cast(1 as double) > '2' FROM t;
SELECT cast(1 as double) >= '2' FROM t;
SELECT cast(1 as double) < '2' FROM t;
SELECT cast(1 as double) <= '2' FROM t;
SELECT cast(1 as double) <> '2' FROM t;
SELECT cast(1 as double) = cast(null as string) FROM t;
SELECT cast(1 as double) > cast(null as string) FROM t;
SELECT cast(1 as double) >= cast(null as string) FROM t;
SELECT cast(1 as double) < cast(null as string) FROM t;
SELECT cast(1 as double) <= cast(null as string) FROM t;
SELECT cast(1 as double) <> cast(null as string) FROM t;
SELECT '1' = cast(1 as double) FROM t;
SELECT '2' > cast(1 as double) FROM t;
SELECT '2' >= cast(1 as double) FROM t;
SELECT '2' < cast(1 as double) FROM t;
SELECT '2' <= cast(1 as double) FROM t;
SELECT '2' <> cast(1 as double) FROM t;
SELECT cast(null as string) = cast(1 as double) FROM t;
SELECT cast(null as string) > cast(1 as double) FROM t;
SELECT cast(null as string) >= cast(1 as double) FROM t;
SELECT cast(null as string) < cast(1 as double) FROM t;
SELECT cast(null as string) <= cast(1 as double) FROM t;
SELECT cast(null as string) <> cast(1 as double) FROM t;
SELECT cast(1 as float) = '1' FROM t;
SELECT cast(1 as float) > '2' FROM t;
SELECT cast(1 as float) >= '2' FROM t;
SELECT cast(1 as float) < '2' FROM t;
SELECT cast(1 as float) <= '2' FROM t;
SELECT cast(1 as float) <> '2' FROM t;
SELECT cast(1 as float) = cast(null as string) FROM t;
SELECT cast(1 as float) > cast(null as string) FROM t;
SELECT cast(1 as float) >= cast(null as string) FROM t;
SELECT cast(1 as float) < cast(null as string) FROM t;
SELECT cast(1 as float) <= cast(null as string) FROM t;
SELECT cast(1 as float) <> cast(null as string) FROM t;
SELECT '1' = cast(1 as float) FROM t;
SELECT '2' > cast(1 as float) FROM t;
SELECT '2' >= cast(1 as float) FROM t;
SELECT '2' < cast(1 as float) FROM t;
SELECT '2' <= cast(1 as float) FROM t;
SELECT '2' <> cast(1 as float) FROM t;
SELECT cast(null as string) = cast(1 as float) FROM t;
SELECT cast(null as string) > cast(1 as float) FROM t;
SELECT cast(null as string) >= cast(1 as float) FROM t;
SELECT cast(null as string) < cast(1 as float) FROM t;
SELECT cast(null as string) <= cast(1 as float) FROM t;
SELECT cast(null as string) <> cast(1 as float) FROM t;
-- the following queries return 1 if the search condition is satisfied
-- and returns nothing if the search condition is not satisfied
SELECT '1996-09-09' = date('1996-09-09') FROM t;
SELECT '1996-9-10' > date('1996-09-09') FROM t;
SELECT '1996-9-10' >= date('1996-09-09') FROM t;
SELECT '1996-9-10' < date('1996-09-09') FROM t;
SELECT '1996-9-10' <= date('1996-09-09') FROM t;
SELECT '1996-9-10' <> date('1996-09-09') FROM t;
SELECT cast(null as string) = date('1996-09-09') FROM t;
SELECT cast(null as string)> date('1996-09-09') FROM t;
SELECT cast(null as string)>= date('1996-09-09') FROM t;
SELECT cast(null as string)< date('1996-09-09') FROM t;
SELECT cast(null as string)<= date('1996-09-09') FROM t;
SELECT cast(null as string)<> date('1996-09-09') FROM t;
SELECT date('1996-09-09') = '1996-09-09' FROM t;
SELECT date('1996-9-10') > '1996-09-09' FROM t;
SELECT date('1996-9-10') >= '1996-09-09' FROM t;
SELECT date('1996-9-10') < '1996-09-09' FROM t;
SELECT date('1996-9-10') <= '1996-09-09' FROM t;
SELECT date('1996-9-10') <> '1996-09-09' FROM t;
SELECT date('1996-09-09') = cast(null as string) FROM t;
SELECT date('1996-9-10') > cast(null as string) FROM t;
SELECT date('1996-9-10') >= cast(null as string) FROM t;
SELECT date('1996-9-10') < cast(null as string) FROM t;
SELECT date('1996-9-10') <= cast(null as string) FROM t;
SELECT date('1996-9-10') <> cast(null as string) FROM t;
SELECT '1996-09-09 12:12:12.4' = timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT '1996-09-09 12:12:12.5' > timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT '1996-09-09 12:12:12.5' >= timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT '1996-09-09 12:12:12.5' < timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT '1996-09-09 12:12:12.5' <= timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT '1996-09-09 12:12:12.5' <> timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT cast(null as string) = timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT cast(null as string) > timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT cast(null as string) >= timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT cast(null as string) < timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT cast(null as string) <= timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT cast(null as string) <> timestamp('1996-09-09 12:12:12.4') FROM t;
SELECT timestamp('1996-09-09 12:12:12.4' )= '1996-09-09 12:12:12.4' FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )> '1996-09-09 12:12:12.4' FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )>= '1996-09-09 12:12:12.4' FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )< '1996-09-09 12:12:12.4' FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )<= '1996-09-09 12:12:12.4' FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )<> '1996-09-09 12:12:12.4' FROM t;
SELECT timestamp('1996-09-09 12:12:12.4' )= cast(null as string) FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )> cast(null as string) FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )>= cast(null as string) FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )< cast(null as string) FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )<= cast(null as string) FROM t;
SELECT timestamp('1996-09-09 12:12:12.5' )<> cast(null as string) FROM t;
SELECT ' ' = X'0020' FROM t;
SELECT ' ' > X'001F' FROM t;
SELECT ' ' >= X'001F' FROM t;
SELECT ' ' < X'001F' FROM t;
SELECT ' ' <= X'001F' FROM t;
SELECT ' ' <> X'001F' FROM t;
SELECT cast(null as string) = X'0020' FROM t;
SELECT cast(null as string) > X'001F' FROM t;
SELECT cast(null as string) >= X'001F' FROM t;
SELECT cast(null as string) < X'001F' FROM t;
SELECT cast(null as string) <= X'001F' FROM t;
SELECT cast(null as string) <> X'001F' FROM t;
SELECT X'0020' = ' ' FROM t;
SELECT X'001F' > ' ' FROM t;
SELECT X'001F' >= ' ' FROM t;
SELECT X'001F' < ' ' FROM t;
SELECT X'001F' <= ' ' FROM t;
SELECT X'001F' <> ' ' FROM t;
SELECT X'0020' = cast(null as string) FROM t;
SELECT X'001F' > cast(null as string) FROM t;
SELECT X'001F' >= cast(null as string) FROM t;
SELECT X'001F' < cast(null as string) FROM t;
SELECT X'001F' <= cast(null as string) FROM t;
SELECT X'001F' <> cast(null as string) FROM t;
@@ -0,0 +1,72 @@
--
-- 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.
--

-- ImplicitTypeCasts

CREATE TEMPORARY VIEW t AS SELECT 1;

SELECT 1 + '2' FROM t;
SELECT 1 - '2' FROM t;
SELECT 1 * '2' FROM t;
SELECT 4 / '2' FROM t;
SELECT 1.1 + '2' FROM t;
SELECT 1.1 - '2' FROM t;
SELECT 1.1 * '2' FROM t;
SELECT 4.4 / '2' FROM t;
SELECT 1.1 + '2.2' FROM t;
SELECT 1.1 - '2.2' FROM t;
SELECT 1.1 * '2.2' FROM t;
SELECT 4.4 / '2.2' FROM t;

-- concatentation
SELECT '$' || cast(1 as smallint) || '$' FROM t;
SELECT '$' || 1 || '$' FROM t;
SELECT '$' || cast(1 as bigint) || '$' FROM t;
SELECT '$' || cast(1.1 as float) || '$' FROM t;
SELECT '$' || cast(1.1 as double) || '$' FROM t;
SELECT '$' || 1.1 || '$' FROM t;
SELECT '$' || cast(1.1 as decimal(8,3)) || '$' FROM t;
SELECT '$' || 'abcd' || '$' FROM t;
SELECT '$' || date('1996-09-09') || '$' FROM t;
SELECT '$' || timestamp('1996-09-09 10:11:12.4' )|| '$' FROM t;

-- length functions
SELECT length(cast(1 as smallint)) FROM t;
SELECT length(cast(1 as int)) FROM t;
SELECT length(cast(1 as bigint)) FROM t;
SELECT length(cast(1.1 as float)) FROM t;
SELECT length(cast(1.1 as double)) FROM t;
SELECT length(1.1) FROM t;
SELECT length(cast(1.1 as decimal(8,3))) FROM t;
SELECT length('four') FROM t;
SELECT length(date('1996-09-10')) FROM t;
SELECT length(timestamp('1996-09-10 10:11:12.4')) FROM t;

-- extract
SELECT year( '1996-01-10') FROM t;
SELECT month( '1996-01-10') FROM t;
SELECT day( '1996-01-10') FROM t;
SELECT hour( '10:11:12') FROM t;
SELECT minute( '10:11:12') FROM t;
SELECT second( '10:11:12') FROM t;

-- like
select 1 like '%' FROM t;
select date('1996-09-10') like '19%' FROM t;
select '1' like 1 FROM t;
select '1 ' like 1 FROM t;
select '1996-09-10' like date('1996-09-10') FROM t;
Expand Up @@ -44,6 +44,7 @@ struct<>
-- !query 4 output



-- !query 5
select current_date, current_timestamp from ttf1
-- !query 5 schema
Expand All @@ -63,6 +64,7 @@ struct<>
-- !query 6 output



-- !query 7
select current_date = current_date(), current_timestamp = current_timestamp(), a, b from ttf2
-- !query 7 schema
Expand Down