You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2019/08/22 06:02:42 UTC
[impala] branch master updated: IMPALA-7027: fix
StringLiteral.localEquals()
This is an automated email from the ASF dual-hosted git repository.
tarmstrong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
The following commit(s) were added to refs/heads/master by this push:
new a85b185 IMPALA-7027: fix StringLiteral.localEquals()
a85b185 is described below
commit a85b18503f430acbf7f0bd285b67c3eecc7ac377
Author: Yongzhi Chen <yc...@cloudera.com>
AuthorDate: Tue Aug 20 15:01:50 2019 -0400
IMPALA-7027: fix StringLiteral.localEquals()
String literals with the same value but different types
are not interchangeable. localEquals() should check
the type, similar to a cast expression.
Testing:
- Added String literals tests.
- Passed exhaustive tests.
Change-Id: I6a9dff514c2c4cc422343d1dfbd881917acca138
Reviewed-on: http://gerrit.cloudera.org:8080/14096
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
.../org/apache/impala/analysis/StringLiteral.java | 3 +-
.../queries/QueryTest/string-literals.test | 41 ++++++++++++++++++++++
tests/query_test/test_chars.py | 3 ++
3 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/fe/src/main/java/org/apache/impala/analysis/StringLiteral.java b/fe/src/main/java/org/apache/impala/analysis/StringLiteral.java
index 09a542f..3cf2ab2 100644
--- a/fe/src/main/java/org/apache/impala/analysis/StringLiteral.java
+++ b/fe/src/main/java/org/apache/impala/analysis/StringLiteral.java
@@ -64,7 +64,8 @@ public class StringLiteral extends LiteralExpr {
public boolean localEquals(Expr that) {
if (!super.localEquals(that)) return false;
StringLiteral other = (StringLiteral) that;
- return needsUnescaping_ == other.needsUnescaping_ && value_.equals(other.value_);
+ return needsUnescaping_ == other.needsUnescaping_ && type_.equals(other.type_)
+ && value_.equals(other.value_);
}
@Override
diff --git a/testdata/workloads/functional-query/queries/QueryTest/string-literals.test b/testdata/workloads/functional-query/queries/QueryTest/string-literals.test
new file mode 100644
index 0000000..816fe44
--- /dev/null
+++ b/testdata/workloads/functional-query/queries/QueryTest/string-literals.test
@@ -0,0 +1,41 @@
+====
+---- QUERY
+SELECT DISTINCT CAST('' as VARCHAR(101)) as CL_COMMENTS,CAST('' as VARCHAR(100)) as
+ CL_USER_ID FROM chars_formats limit 1;
+---- TYPES
+string, string
+---- HS2_TYPES
+varchar, varchar
+---- RESULTS
+'',''
+====
+---- QUERY
+SELECT DISTINCT CAST('' as CHAR(3)) as CL_COMMENTS,CAST('' as CHAR(2)) as CL_USER_ID FROM
+ chars_formats limit 1;
+---- TYPES
+char, char
+---- RESULTS
+' ',' '
+====
+---- QUERY
+SELECT vc from chars_formats where vc = cast ("abc" as varchar(210)) limit 1;
+---- RESULTS
+'abc'
+====
+---- QUERY
+SELECT vc from chars_formats where cast ("abc" as varchar(210)) = vc limit 1;
+---- RESULTS
+'abc'
+====
+---- QUERY
+SELECT 1 from chars_formats WHERE CAST('' as VARCHAR(101)) = CAST('' as VARCHAR(100))
+ limit 1;
+---- RESULTS
+1
+====
+---- QUERY
+SELECT 1 from chars_formats WHERE CAST('' as VARCHAR(100)) = CAST('' as VARCHAR(101))
+ limit 1;
+---- RESULTS
+1
+====
diff --git a/tests/query_test/test_chars.py b/tests/query_test/test_chars.py
index 939e07e..6473065 100644
--- a/tests/query_test/test_chars.py
+++ b/tests/query_test/test_chars.py
@@ -73,3 +73,6 @@ class TestCharFormats(ImpalaTestSuite):
def test_char_format(self, vector):
self.run_test_case('QueryTest/chars-formats', vector)
+
+ def test_string_literal(self, vector):
+ self.run_test_case('QueryTest/string-literals', vector)