You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by la...@apache.org on 2021/03/22 16:44:01 UTC
[phoenix] branch 4.x updated: PHOENIX-6421 Selecting an indexed
array value from an uncovered column with local index returns NULL.
This is an automated email from the ASF dual-hosted git repository.
larsh pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x by this push:
new 410f738 PHOENIX-6421 Selecting an indexed array value from an uncovered column with local index returns NULL.
410f738 is described below
commit 410f738f6f3824feb7fec5b5486b2993be15a5ef
Author: Lars <la...@apache.org>
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 9f79107..2910322 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
@@ -83,6 +83,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 799b667..13ca41b 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 414f294..2dd37a8 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
@@ -214,18 +214,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;
}
@@ -248,6 +243,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));
@@ -345,7 +345,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();
@@ -369,10 +369,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;