From 2f9c67c2f799184aea667419fafd52ef1fe1a4a4 Mon Sep 17 00:00:00 2001 From: maryannxue Date: Wed, 25 Oct 2017 15:09:58 -0700 Subject: [PATCH 1/2] PHOENIX-4322 DESC primary key column with variable length does not work in SkipScanFilter --- .../it/java/org/apache/phoenix/end2end/SortOrderIT.java | 9 +++++++++ .../src/main/java/org/apache/phoenix/util/ScanUtil.java | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java index 655dbb13dc4..58bbabb6d86 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java @@ -167,6 +167,15 @@ public void inDescCompositePK2() throws Exception { runQueryTest(ddl, upsert("oid", "code"), insertedRows, new Object[][]{{"o2", 2}}, new WhereCondition("oid", "IN", "('o2')"), table); } + + @Test + public void inDescCompositePK3() throws Exception { + String table = generateUniqueName(); + String ddl = "CREATE table " + table + " (oid INTEGER NOT NULL, code VARCHAR NOT NULL constraint pk primary key (oid DESC, code DESC))"; + Object[][] insertedRows = new Object[][]{{1, "o1"}, {2, "o2"}, {3, "o3"}}; + runQueryTest(ddl, upsert("oid", "code"), insertedRows, new Object[][]{{2, "o2"}, {1, "o1"}}, + new WhereCondition("(oid, code)", "IN", "((1, 'o1'), (2, 'o2'))"), table); + } @Test public void likeDescCompositePK1() throws Exception { 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 a8442268a6c..8ab4f20a909 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 @@ -431,8 +431,11 @@ public static int setKey(RowKeySchema schema, List> slots, int[] anyInclusiveUpperRangeKey |= !range.isSingleKey() && inclusiveUpper; // A null or empty byte array is always represented as a zero byte byte sepByte = SchemaUtil.getSeparatorByte(schema.rowKeyOrderOptimizable(), bytes.length == 0, field); - - if ( !isFixedWidth && ( sepByte == QueryConstants.DESC_SEPARATOR_BYTE + // The result of an RVC evaluation can come with a trailing separator already, so we + // should avoid adding another one. + if ( !isFixedWidth + && ( bytes.length == 0 || key[offset - 1] != sepByte ) + && ( sepByte == QueryConstants.DESC_SEPARATOR_BYTE || ( !exclusiveUpper && (fieldIndex < schema.getMaxFields() || inclusiveUpper || exclusiveLower) ) ) ) { key[offset++] = sepByte; From 30f8a5cf7f64e6b6984939ccbb8dd5c7f9a7ea63 Mon Sep 17 00:00:00 2001 From: maryannxue Date: Mon, 30 Oct 2017 22:35:11 -0700 Subject: [PATCH 2/2] PHOENIX-4322 DESC primary key column with variable length does not work in SkipScanFilter (fix test failures) --- .../src/main/java/org/apache/phoenix/util/ScanUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8ab4f20a909..3fe8ad36d34 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 @@ -434,7 +434,7 @@ public static int setKey(RowKeySchema schema, List> slots, int[] // The result of an RVC evaluation can come with a trailing separator already, so we // should avoid adding another one. if ( !isFixedWidth - && ( bytes.length == 0 || key[offset - 1] != sepByte ) + && ( bytes.length == 0 || slotSpan[i] == 0 || key[offset - 1] != sepByte ) && ( sepByte == QueryConstants.DESC_SEPARATOR_BYTE || ( !exclusiveUpper && (fieldIndex < schema.getMaxFields() || inclusiveUpper || exclusiveLower) ) ) ) {