From commits-return-23555-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Wed Oct 17 21:40:08 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id D50451807AC for ; Wed, 17 Oct 2018 21:40:06 +0200 (CEST) Received: (qmail 51699 invoked by uid 500); 17 Oct 2018 19:40:01 -0000 Mailing-List: contact commits-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list commits@phoenix.apache.org Received: (qmail 50999 invoked by uid 99); 17 Oct 2018 19:40:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Oct 2018 19:40:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 15EE6E11D2; Wed, 17 Oct 2018 19:40:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pboado@apache.org To: commits@phoenix.apache.org Date: Wed, 17 Oct 2018 19:40:26 -0000 Message-Id: In-Reply-To: <5b2ef51309dd406893ad7cfcf81942c5@git.apache.org> References: <5b2ef51309dd406893ad7cfcf81942c5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [28/32] phoenix git commit: PHOENIX-4933 DELETE FROM throws NPE when a local index is present. PHOENIX-4933 DELETE FROM throws NPE when a local index is present. Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/81d679e3 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/81d679e3 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/81d679e3 Branch: refs/heads/4.14-cdh5.13 Commit: 81d679e38c47e2944a9b2fe4296fd8456a898ea6 Parents: a606065 Author: Lars Hofhansl Authored: Mon Oct 1 19:57:44 2018 +0100 Committer: Pedro Boado Committed: Wed Oct 17 20:38:39 2018 +0100 ---------------------------------------------------------------------- .../phoenix/end2end/index/LocalIndexIT.java | 22 +++++++++++++++++ .../tuple/EncodedColumnQualiferCellsList.java | 25 +++++++++++++------- 2 files changed, 39 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/81d679e3/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java ---------------------------------------------------------------------- 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 0dcf1d5..796d5a2 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 @@ -78,7 +78,29 @@ public class LocalIndexIT extends BaseLocalIndexIT { public LocalIndexIT(boolean isNamespaceMapped) { super(isNamespaceMapped); } + + @Test + public void testDeleteFromLocalIndex() throws Exception { + String tableName = schemaName + "." + generateUniqueName(); + String indexName = "IDX_" + generateUniqueName(); + Connection conn = getConnection(); + conn.setAutoCommit(true); + if (isNamespaceMapped) { + conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + schemaName); + } + + conn.createStatement().execute("CREATE TABLE " + tableName + " (pk INTEGER PRIMARY KEY, v1 FLOAT, v2 FLOAT)"); + conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES(1, rand(), rand())"); + // This would fail with an NPE before PHOENIX-4933 + conn.createStatement().execute("DELETE FROM " + tableName + " WHERE v1 < 1"); + ResultSet rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM "+tableName); + rs.next(); + assertEquals(0, rs.getInt(1)); + rs.close(); + } + @Test public void testLocalIndexRoundTrip() throws Exception { String tableName = schemaName + "." + generateUniqueName(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/81d679e3/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java index 10329fb..db3647d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java @@ -175,14 +175,7 @@ public class EncodedColumnQualiferCellsList implements List { firstNonNullElementIdx = -1; } else if (firstNonNullElementIdx == i) { // the element being removed was the first non-null element we knew - while (i < array.length && (array[i]) == null) { - i++; - } - if (i < array.length) { - firstNonNullElementIdx = i; - } else { - firstNonNullElementIdx = -1; - } + adjustFirstNonNullElement(); } modCount++; return true; @@ -383,6 +376,18 @@ public class EncodedColumnQualiferCellsList implements List { return getCellForColumnQualifier(columnQualifier); } + private void adjustFirstNonNullElement() { + int i = firstNonNullElementIdx; + while (i < array.length && (array[i]) == null) { + i++; + } + if (i < array.length) { + firstNonNullElementIdx = i; + } else { + firstNonNullElementIdx = -1; + } + + } private Cell getCellForColumnQualifier(int columnQualifier) { checkQualifierRange(columnQualifier); int idx = getArrayIndex(columnQualifier); @@ -461,6 +466,10 @@ public class EncodedColumnQualiferCellsList implements List { } checkForCoModification(); array[lastRet] = null; + if (firstNonNullElementIdx == lastRet) { + // the element being removed was the first non-null element we knew + adjustFirstNonNullElement(); + } lastRet = -1; numNonNullElements--; modCount++;