This is an automated email from the ASF dual-hosted git repository.
larsh 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 08f45ac PHOENIX-6421 Selecting an indexed array value from an
uncovered column with local index returns NULL.
08f45ac is described below
commit 08f45acfd44b513b1ce0bb8c3e2e3c49b0b269e1
Author: Lars <[email protected]>
AuthorDate: Fri Mar 19 19:00:17 2021 -0700
PHOENIX-6421 Selecting an indexed array value from an uncovered column with
local index returns NULL.
---
.../apache/phoenix/end2end/index/LocalIndexIT.java | 30 ++++++++++++++++++++++
.../apache/phoenix/compile/ProjectionCompiler.java | 6 +++++
.../phoenix/iterate/RegionScannerFactory.java | 18 +++++--------
3 files changed, 43 insertions(+), 11 deletions(-)
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index 279c2e7..64a85eb 100644
---
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -84,6 +84,36 @@ public class LocalIndexIT extends BaseLocalIndexIT {
}
@Test
+ public void testSelectFromIndexWithUncoveredArrayIndex() throws Exception {
+ if (isNamespaceMapped) {
+ return;
+ }
+ String tableName = schemaName + "." + generateUniqueName();
+ String indexName = "IDX_" + generateUniqueName();
+
+ Connection conn = getConnection();
+ conn.setAutoCommit(true);
+
+ conn.createStatement().execute("CREATE TABLE " + tableName + " (pk
INTEGER PRIMARY KEY, v1 FLOAT, v2 FLOAT[])");
+ conn.createStatement().execute("UPSERT INTO " + tableName + "
VALUES(1, 2, ARRAY[3,4])");
+
+ conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + "
ON " + tableName + "(v1)");
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT v2[1] FROM
"+tableName+" WHERE v1 < 3");
+ rs.next();
+ assertEquals(3, rs.getInt(1));
+ rs.close();
+
+ conn.createStatement().execute("DROP INDEX " + indexName + " ON " +
tableName);
+ conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + "
ON " + tableName + "(v2[2])");
+
+ rs = conn.createStatement().executeQuery("SELECT v2[1] FROM
"+tableName+" WHERE v2[2] < 5");
+ rs.next();
+ assertEquals(3, rs.getInt(1));
+ rs.close();
+ }
+
+ @Test
public void testSelectFromIndexWithAdditionalWhereClause() throws
Exception {
if (isNamespaceMapped) {
return;
diff --git
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
index bae0f0c..c13f383 100644
---
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
+++
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
@@ -81,6 +81,7 @@ import
org.apache.phoenix.schema.PTable.ImmutableStorageScheme;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.ProjectedColumn;
import org.apache.phoenix.schema.RowKeySchema;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.schema.TableRef;
@@ -699,6 +700,11 @@ public class ProjectionCompiler {
if (expression.getDataType().isArrayType()) {
indexProjectedColumns.add(expression);
PColumn col = expression.getColumn();
+ // hack'ish... For covered columns with local
indexes we defer to the server.
+ if (col instanceof ProjectedColumn &&
((ProjectedColumn) col)
+ .getSourceColumnRef() instanceof
LocalIndexDataColumnRef) {
+ return null;
+ }
PTable table =
context.getCurrentTable().getTable();
KeyValueColumnExpression keyValueColumnExpression;
if (table.getImmutableStorageScheme() !=
ImmutableStorageScheme.ONE_CELL_PER_COLUMN) {
diff --git
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerFactory.java
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerFactory.java
index 8d70ab0..a313fe7 100644
---
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerFactory.java
+++
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerFactory.java
@@ -212,18 +212,13 @@ public abstract class RegionScannerFactory {
if (isDummy(result)) {
return true;
}
- Cell arrayElementCell = null;
if (result.size() == 0) {
return next;
}
- if (arrayFuncRefs != null && arrayFuncRefs.length > 0 &&
arrayKVRefs.size() > 0) {
- int arrayElementCellPosition =
replaceArrayIndexElement(arrayKVRefs, arrayFuncRefs, result);
- arrayElementCell = result.get(arrayElementCellPosition);
- }
if (ScanUtil.isLocalIndex(scan) && !ScanUtil.isAnalyzeTable(scan)) {
if(actualStartKey!=null) {
next = scanTillScanStartRow(s, arrayKVRefs, arrayFuncRefs,
result,
- null, arrayElementCell);
+ null);
if (result.isEmpty() || isDummy(result)) {
return next;
}
@@ -246,6 +241,11 @@ public abstract class RegionScannerFactory {
}
}
}
+ Cell arrayElementCell = null;
+ if (arrayFuncRefs != null && arrayFuncRefs.length > 0 &&
arrayKVRefs.size() > 0) {
+ int arrayElementCellPosition =
replaceArrayIndexElement(arrayKVRefs, arrayFuncRefs, result);
+ arrayElementCell = result.get(arrayElementCellPosition);
+ }
if (projector != null) {
Tuple toProject = useQualifierAsListIndex ? new
PositionBasedResultTuple(result) :
new ResultTuple(Result.create(result));
@@ -343,7 +343,7 @@ public abstract class RegionScannerFactory {
private boolean scanTillScanStartRow(final RegionScanner s,
final Set<KeyValueColumnExpression> arrayKVRefs,
final Expression[] arrayFuncRefs, List<Cell> result,
- ScannerContext scannerContext, Cell arrayElementCell) throws
IOException {
+ ScannerContext scannerContext) throws IOException {
boolean next = true;
Cell firstCell = result.get(0);
long startTime = EnvironmentEdgeManager.currentTimeMillis();
@@ -367,10 +367,6 @@ public abstract class RegionScannerFactory {
if (isDummy(result)) {
return true;
}
- if (arrayFuncRefs != null && arrayFuncRefs.length > 0 &&
arrayKVRefs.size() > 0) {
- int arrayElementCellPosition =
replaceArrayIndexElement(arrayKVRefs, arrayFuncRefs, result);
- arrayElementCell = result.get(arrayElementCellPosition);
- }
firstCell = result.get(0);
}
return next;