This is an automated email from the ASF dual-hosted git repository.
rameshkumar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 676cbf1491f HIVE-28431 Fix RexLiteral to ExprNode conversion if the
literal is an empty string (Ramesh Kumar reviewed by Soumyakanti Das)
676cbf1491f is described below
commit 676cbf1491f6e032709e3e4d10fffa247083e41d
Author: Ramesh Kumar <[email protected]>
AuthorDate: Wed Aug 7 14:12:05 2024 -0700
HIVE-28431 Fix RexLiteral to ExprNode conversion if the literal is an empty
string (Ramesh Kumar reviewed by Soumyakanti Das)
---
.../calcite/translator/ExprNodeConverter.java | 3 ++
.../queries/clientpositive/filter_emptyliteral.q | 4 +++
.../clientpositive/llap/filter_emptyliteral.q.out | 34 ++++++++++++++++++++++
3 files changed, 41 insertions(+)
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java
index 62c132545fd..d559a8745f4 100644
---
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java
+++
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java
@@ -361,6 +361,9 @@ public class ExprNodeConverter extends
RexVisitorImpl<ExprNodeDesc> {
"char values must use NlsString for correctness");
int precision = lType.getPrecision();
HiveChar value = new HiveChar((String) literal.getValue3(), precision);
+ if (value.getCharacterLength() == 0) {
+ return new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo,
null);
+ }
return new ExprNodeConstantDesc(new CharTypeInfo(precision), value);
}
case VARCHAR: {
diff --git a/ql/src/test/queries/clientpositive/filter_emptyliteral.q
b/ql/src/test/queries/clientpositive/filter_emptyliteral.q
new file mode 100644
index 00000000000..6b8cd80b4ba
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/filter_emptyliteral.q
@@ -0,0 +1,4 @@
+create table employee(firstname varchar(255), lastname char(25), id int);
+
+explain cbo SELECT id FROM employee where firstname = '';
+explain cbo SELECT id FROM employee where lastname = '';
diff --git a/ql/src/test/results/clientpositive/llap/filter_emptyliteral.q.out
b/ql/src/test/results/clientpositive/llap/filter_emptyliteral.q.out
new file mode 100644
index 00000000000..c30b5e152ee
--- /dev/null
+++ b/ql/src/test/results/clientpositive/llap/filter_emptyliteral.q.out
@@ -0,0 +1,34 @@
+PREHOOK: query: create table employee(firstname varchar(255), lastname
char(25), id int)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@employee
+POSTHOOK: query: create table employee(firstname varchar(255), lastname
char(25), id int)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@employee
+PREHOOK: query: explain cbo SELECT id FROM employee where firstname = ''
+PREHOOK: type: QUERY
+PREHOOK: Input: default@employee
+#### A masked pattern was here ####
+POSTHOOK: query: explain cbo SELECT id FROM employee where firstname = ''
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@employee
+#### A masked pattern was here ####
+CBO PLAN:
+HiveProject(id=[$2])
+ HiveFilter(condition=[=($0, _UTF-16LE'')])
+ HiveTableScan(table=[[default, employee]], table:alias=[employee])
+
+PREHOOK: query: explain cbo SELECT id FROM employee where lastname = ''
+PREHOOK: type: QUERY
+PREHOOK: Input: default@employee
+#### A masked pattern was here ####
+POSTHOOK: query: explain cbo SELECT id FROM employee where lastname = ''
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@employee
+#### A masked pattern was here ####
+CBO PLAN:
+HiveProject(id=[$2])
+ HiveFilter(condition=[=($1, _UTF-16LE' ')])
+ HiveTableScan(table=[[default, employee]], table:alias=[employee])
+