GitHub user wangyum opened a pull request:
https://github.com/apache/spark/pull/18853
[SPARK-21646][SQL] BinaryComparison shouldn't auto cast string to int/long
## What changes were proposed in this pull request?
How to reproduce:
hive:
```:sql
$ hive -S
hive> create table spark_21646(c1 string, c2 string);
hive> insert into spark_21646 values('92233720368547758071', 'a');
hive> insert into spark_21646 values('21474836471', 'b');
hive> insert into spark_21646 values('10', 'c');
hive> select * from spark_21646 where c1 > 0;
92233720368547758071 a
10 c
21474836471 b
hive>
```
spark-sql:
```:sql
$ spark-sql -S
spark-sql> select * from spark_21646 where c1 > 0;
10 c
spark-sql> select * from spark_21646 where c1 > 0L;
21474836471 b
10 c
spark-sql> explain select * from spark_21646 where c1 > 0;
== Physical Plan ==
*Project [c1#14, c2#15]
+- *Filter (isnotnull(c1#14) && (cast(c1#14 as int) > 0))
+- *FileScan parquet spark_21646[c1#14,c2#15] Batched: true, Format:
Parquet, Location:
InMemoryFileIndex[viewfs://cluster4/user/hive/warehouse/spark_21646],
PartitionFilters: [], PushedFilters: [IsNotNull(c1)], ReadSchema:
struct<c1:string,c2:string>
spark-sql>
```
As you can see, spark auto cast c1 to int type, if this value out of
integer range, the result is different from Hive. This PR makes Literal' s type
keeps pace with AttributeReference's type.
## How was this patch tested?
unit tests
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/wangyum/spark SPARK-21646
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/18853.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #18853
----
commit f59a213027968f5fe157376db51d0e15b68b47db
Author: Yuming Wang <[email protected]>
Date: 2017-08-05T09:20:17Z
BinaryComparison shouldn't auto cast string to int/long
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]