This is an automated email from the ASF dual-hosted git repository. stoty 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 9f2bff3 PHOENIX-6453 Possible ArrayIndexOutOfBoundsException while preparing scan start key with multiple key range queries(Rajeshbabu) 9f2bff3 is described below commit 9f2bff310d4772622dd343a4084b4777388f6918 Author: Rajeshbabu Chintaguntla <rajeshb...@apache.org> AuthorDate: Tue May 4 13:48:53 2021 +0530 PHOENIX-6453 Possible ArrayIndexOutOfBoundsException while preparing scan start key with multiple key range queries(Rajeshbabu) --- .../java/org/apache/phoenix/end2end/InListIT.java | 35 ++++++++++++++++++++++ .../java/org/apache/phoenix/util/ScanUtil.java | 4 ++- 2 files changed, 38 insertions(+), 1 deletion(-) 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 d2fc9c7..1c1f2da 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 @@ -46,8 +46,10 @@ import org.apache.phoenix.schema.SortOrder; import org.apache.phoenix.schema.TypeMismatchException; import org.apache.phoenix.schema.types.PDataType; import org.apache.phoenix.schema.types.PInteger; +import org.apache.phoenix.util.EnvironmentEdgeManager; import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.SchemaUtil; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -1657,4 +1659,37 @@ public class InListIT extends ParallelStatsDisabledIT { .startsWith(ExplainTable.POINT_LOOKUP_ON_STRING)); } } + + @Test + public void testInListExpressionWithVariableLengthColumnsRanges() throws Exception { + Properties props = new Properties(); + final String schemaName = generateUniqueName(); + final String tableName = generateUniqueName(); + final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName); + String ddl = + "CREATE TABLE " + dataTableFullName + " (a VARCHAR(22) NOT NULL," + + "b CHAR(6) NOT NULL," + + "c VARCHAR(12) NOT NULL,d VARCHAR(200) NOT NULL, " + + "CONSTRAINT PK_TEST_KO PRIMARY KEY (a,b,c,d)) "; + long startTS = EnvironmentEdgeManager.currentTimeMillis(); + try (Connection conn = DriverManager.getConnection(getUrl(), props)) { + conn.createStatement().execute(ddl); + conn.commit(); + conn.createStatement().execute("upsert into "+ dataTableFullName+ + " values('AAAA1234567890','202001','A1','foo')"); + conn.createStatement().execute("upsert into "+ dataTableFullName+ + " values('AAAA1234567892','202002','A1','foo')"); + conn.createStatement().execute("upsert into "+ dataTableFullName+ + " values('AAAA1234567892','202002','B1','foo')"); + conn.createStatement().execute("upsert into "+ dataTableFullName+ + " values('AAAA1234567890','202001','B1','foo')"); + conn.commit(); + String query = "SELECT count(*) FROM "+dataTableFullName+ + " WHERE (a, b) IN (('AAAA1234567890', '202001'), ( 'AAAA1234567892', '202002'))" + + " AND c IN ('A1')"; + ResultSet r = conn.createStatement().executeQuery(query); + r.next(); + assertEquals(2, r.getInt(1)); + } + } } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java index d0b50bc..98caf91 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java @@ -362,10 +362,12 @@ public class ScanUtil { } int[] position = new int[slots.size()]; int maxLength = 0; + int slotEndingFieldPos = -1; for (int i = 0; i < position.length; i++) { position[i] = bound == Bound.LOWER ? 0 : slots.get(i).size()-1; KeyRange range = slots.get(i).get(position[i]); - Field field = schema.getField(i + slotSpan[i]); + slotEndingFieldPos = slotEndingFieldPos + slotSpan[i] + 1; + Field field = schema.getField(slotEndingFieldPos); int keyLength = range.getRange(bound).length; if (!field.getDataType().isFixedWidth()) { keyLength++;