Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,8 +46,10 @@
import org.apache.phoenix.thirdparty.com.google.common.base.Function;
import org.apache.phoenix.thirdparty.com.google.common.base.Joiner;
import org.apache.phoenix.thirdparty.com.google.common.collect.Lists;
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;
Expand DownExpand Up@@ -1673,4 +1675,37 @@ public void testBaseTableAndIndexTableHaveRightScan() throws Exception {
.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));
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -363,10 +363,12 @@ private static byte[] getKey(RowKeySchema schema, List<List<KeyRange>> slots, in
}
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++;
Expand Down