Return-Path: X-Original-To: apmail-phoenix-commits-archive@minotaur.apache.org Delivered-To: apmail-phoenix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6D9D711180 for ; Sat, 13 Sep 2014 01:31:00 +0000 (UTC) Received: (qmail 72164 invoked by uid 500); 13 Sep 2014 01:31:00 -0000 Delivered-To: apmail-phoenix-commits-archive@phoenix.apache.org Received: (qmail 72121 invoked by uid 500); 13 Sep 2014 01:31:00 -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 72111 invoked by uid 99); 13 Sep 2014 01:31:00 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 Sep 2014 01:31:00 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 059C7A12C2E; Sat, 13 Sep 2014 01:30:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamestaylor@apache.org To: commits@phoenix.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: PHOENIX-1213 Upsert and delete do not work for multi-tenant tables using tenant-specific connections (Karel Vervaeke) Date: Sat, 13 Sep 2014 01:30:59 +0000 (UTC) Repository: phoenix Updated Branches: refs/heads/3.0 f22dffc13 -> 7a9fd9981 PHOENIX-1213 Upsert and delete do not work for multi-tenant tables using tenant-specific connections (Karel Vervaeke) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/7a9fd998 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/7a9fd998 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/7a9fd998 Branch: refs/heads/3.0 Commit: 7a9fd998126daebab14f0ecda683d85c36ebc799 Parents: f22dffc Author: James Taylor Authored: Fri Sep 12 18:25:52 2014 -0700 Committer: James Taylor Committed: Fri Sep 12 18:28:52 2014 -0700 ---------------------------------------------------------------------- .../phoenix/end2end/CSVCommonsLoaderIT.java | 51 +++++++++++++++++++- .../apache/phoenix/execute/MutationState.java | 3 +- 2 files changed, 51 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/7a9fd998/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java index b280be4..9f36b93 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java @@ -41,7 +41,6 @@ import org.apache.phoenix.util.DateUtil; import org.apache.phoenix.util.PhoenixRuntime; import org.junit.Test; import org.junit.experimental.categories.Category; - @Category(HBaseManagedTimeTest.class) public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { @@ -50,6 +49,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { + "KEY1,A,2147483647,1.1,0,TRUE,9223372036854775807,0,1990-12-31 10:59:59,1999-12-31 23:59:59\n" + "KEY2,B,-2147483648,-1.1,2147483647,FALSE,-9223372036854775808,9223372036854775807,2000-01-01 00:00:01,2012-02-29 23:59:59\n"; private static final String STOCK_TABLE = "STOCK_SYMBOL"; + private static final String STOCK_TABLE_MULTI = "STOCK_SYMBOL_MULTI"; private static final String STOCK_CSV_VALUES = "AAPL,APPLE Inc.\n" + "CRM,SALESFORCE\n" + "GOOG,Google\n" + "HOG,Harlet-Davidson Inc.\n" + "HPQ,Hewlett Packard\n" @@ -140,6 +140,55 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { } @Test + public void testCSVCommonsUpsert_MultiTenant() throws Exception { + CSVParser parser = null; + PhoenixConnection globalConn = null; + PhoenixConnection tenantConn = null; + try { + + // Create table using the global connection + String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE_MULTI + + "(TENANT_ID VARCHAR NOT NULL, SYMBOL VARCHAR NOT NULL, COMPANY VARCHAR," + + " CONSTRAINT PK PRIMARY KEY(TENANT_ID,SYMBOL)) MULTI_TENANT = true;"; + globalConn = DriverManager.getConnection(getUrl()).unwrap( + PhoenixConnection.class); + PhoenixRuntime.executeStatements(globalConn, + new StringReader(statements), null); + globalConn.close(); + + tenantConn = DriverManager.getConnection(getUrl() + ";TenantId=acme").unwrap( + PhoenixConnection.class); + + // Upsert CSV file + CSVCommonsLoader csvUtil = new CSVCommonsLoader(tenantConn, STOCK_TABLE_MULTI, + Collections. emptyList(), true); + csvUtil.upsert(new StringReader(STOCK_CSV_VALUES_WITH_HEADER)); + + // Compare Phoenix ResultSet with CSV file content + PreparedStatement statement = tenantConn + .prepareStatement("SELECT SYMBOL, COMPANY FROM " + + STOCK_TABLE_MULTI); + ResultSet phoenixResultSet = statement.executeQuery(); + parser = new CSVParser(new StringReader( + STOCK_CSV_VALUES_WITH_HEADER), csvUtil.getFormat()); + for (CSVRecord record : parser) { + assertTrue(phoenixResultSet.next()); + int i = 0; + for (String value : record) { + assertEquals(value, phoenixResultSet.getString(i + 1)); + i++; + } + } + assertFalse(phoenixResultSet.next()); + } finally { + if (parser != null) + parser.close(); + if (tenantConn != null) + tenantConn.close(); + } + } + + @Test public void testTDVCommonsUpsert() throws Exception { CSVParser parser = null; PhoenixConnection conn = null; http://git-wip-us.apache.org/repos/asf/phoenix/blob/7a9fd998/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java index 532255f..768785b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java @@ -46,7 +46,6 @@ import org.apache.phoenix.schema.PColumn; import org.apache.phoenix.schema.PName; import org.apache.phoenix.schema.PRow; import org.apache.phoenix.schema.PTable; -import org.apache.phoenix.schema.PTableKey; import org.apache.phoenix.schema.TableRef; import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.IndexUtil; @@ -288,7 +287,7 @@ public class MutationState implements SQLCloseable { serverTimeStamp = timestamp; if (result.wasUpdated()) { // TODO: use bitset? - table = connection.getMetaDataCache().getTable(new PTableKey(tenantId, table.getName().getString())); + table = result.getTable(); PColumn[] columns = new PColumn[table.getColumns().size()]; for (Map.Entry> rowEntry : entry.getValue().entrySet()) { Map valueEntry = rowEntry.getValue();