Repository: phoenix Updated Branches: refs/heads/master c51dc12b0 -> 20c2d9000
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/20c2d900 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/20c2d900 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/20c2d900 Branch: refs/heads/master Commit: 20c2d9000ab593e79c75f892e3a2d310abca7c67 Parents: c51dc12 Author: James Taylor <[email protected]> Authored: Fri Sep 12 18:25:52 2014 -0700 Committer: James Taylor <[email protected]> Committed: Fri Sep 12 18:27:07 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/20c2d900/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 f75a13e..6235d54 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.<String> 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/20c2d900/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 564e150..8972650 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 @@ -47,7 +47,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.trace.util.Tracing; import org.apache.phoenix.util.ByteUtil; @@ -292,7 +291,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<ImmutableBytesPtr,Map<PColumn,byte[]>> rowEntry : entry.getValue().entrySet()) { Map<PColumn,byte[]> valueEntry = rowEntry.getValue();
