You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ri...@apache.org on 2021/09/29 14:49:34 UTC
[phoenix] branch 4.16 updated: PHOENIX-6563 Unable to use
'UPPER'/'LOWER' together with 'IN'
This is an automated email from the ASF dual-hosted git repository.
richardantal pushed a commit to branch 4.16
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.16 by this push:
new e902881 PHOENIX-6563 Unable to use 'UPPER'/'LOWER' together with 'IN'
e902881 is described below
commit e902881d645ab0dcdc6e6213f11f42c59bad102c
Author: Richard Antal <an...@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 d1ebdd2..b16f704 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
@@ -593,6 +593,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();
}