This is an automated email from the ASF dual-hosted git repository. richardantal pushed a commit to branch 5.1 in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/5.1 by this push: new 5e92f26 PHOENIX-6563 Unable to use 'UPPER'/'LOWER' together with 'IN' 5e92f26 is described below commit 5e92f26145eb69e8435556b9e8a119b86333128a Author: Richard Antal <antal97rich...@gmail.com> AuthorDate: Tue Sep 28 13:49:44 2021 +0200 PHOENIX-6563 Unable to use 'UPPER'/'LOWER' together with 'IN' --- .../java/org/apache/phoenix/end2end/InListIT.java | 52 ++++++++++++++++++++++ .../phoenix/expression/function/LowerFunction.java | 7 ++- .../phoenix/expression/function/UpperFunction.java | 7 ++- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java index d71400c..c64426c 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java @@ -592,6 +592,58 @@ public class InListIT extends ParallelStatsDisabledIT { } } + @Test + public void testUpperWithInChar() throws Exception { + String baseTable = generateUniqueName(); + try (Connection conn = DriverManager.getConnection(getUrl()); + Statement stmt = conn.createStatement()) { + stmt.execute("CREATE TABLE " + baseTable + + " (ID BIGINT NOT NULL primary key, A CHAR(2))"); + PreparedStatement pstmt = conn.prepareStatement("UPSERT INTO " + baseTable + + " VALUES (?, ?)"); + pstmt.setInt(1, 1); + pstmt.setString(2, "a"); + pstmt.executeUpdate(); + conn.commit(); + pstmt.setInt(1, 2); + pstmt.setString(2, "b"); + pstmt.executeUpdate(); + conn.commit(); + + ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + baseTable + + " WHERE UPPER(A) IN ('A', 'C')"); + assertTrue(rs.next()); + assertEquals(rs.getString(2), "a"); + assertFalse(rs.next()); + } + } + + @Test + public void testLowerWithInChar() throws Exception { + String baseTable = generateUniqueName(); + try (Connection conn = DriverManager.getConnection(getUrl()); + Statement stmt = conn.createStatement()) { + stmt.execute("CREATE TABLE " + baseTable + + " (ID BIGINT NOT NULL primary key, A CHAR(2))"); + PreparedStatement pstmt = conn.prepareStatement("UPSERT INTO " + baseTable + + " VALUES (?, ?)"); + pstmt.setInt(1, 1); + pstmt.setString(2, "A"); + pstmt.executeUpdate(); + conn.commit(); + pstmt.setInt(1, 2); + pstmt.setString(2, "B"); + pstmt.executeUpdate(); + conn.commit(); + + ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + baseTable + + " WHERE LOWER(A) IN ('a', 'c')"); + assertTrue(rs.next()); + assertEquals(rs.getString(2), "A"); + assertFalse(rs.next()); + } + } + @Test(expected = TypeMismatchException.class) public void testInListExpressionWithNotValidElements() throws Exception { try (Connection conn = DriverManager.getConnection(getUrl())) { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java index 8d468b3..f444d36 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java @@ -50,7 +50,7 @@ public class LowerFunction extends ScalarFunction { } private void initialize() { - if(children.size() > 1) { + if (children.size() > 1) { String localeISOCode = getLiteralValue(1, String.class); locale = LocaleUtils.get().getLocaleByIsoCode(localeISOCode); } @@ -89,6 +89,11 @@ public class LowerFunction extends ScalarFunction { } @Override + public Integer getMaxLength() { + return getStrExpression().getMaxLength(); + } + + @Override public boolean isNullable() { return getStrExpression().isNullable(); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java index c8e7096..0969269 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java @@ -52,7 +52,7 @@ public class UpperFunction extends ScalarFunction { } private void initialize() { - if(children.size() > 1) { + if (children.size() > 1) { String localeISOCode = getLiteralValue(1, String.class); locale = LocaleUtils.get().getLocaleByIsoCode(localeISOCode); } @@ -87,6 +87,11 @@ public class UpperFunction extends ScalarFunction { } @Override + public Integer getMaxLength() { + return getStrExpression().getMaxLength(); + } + + @Override public boolean isNullable() { return getStrExpression().isNullable(); }