You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2017/01/25 18:50:28 UTC
[1/2] phoenix git commit: PHOENIX-3519 Specify
QualifierEncodingScheme in CREATE TABLE statement
Repository: phoenix
Updated Branches:
refs/heads/encodecolumns2 c004c6ea2 -> 61d9035cd
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
index 9a5e412..752ace0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
@@ -40,6 +40,10 @@ import java.util.Random;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
@@ -58,6 +62,7 @@ import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -68,20 +73,46 @@ import com.google.common.collect.Maps;
@RunWith(Parameterized.class)
public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
private final String tableDDLOptions;
+ private final boolean columnEncoded;
private String tableName;
private String schemaName;
private String fullTableName;
private String physicalTableName;
private final boolean userTableNamespaceMapped;
+ private final boolean mutable;
- public StatsCollectorIT(boolean transactional, boolean userTableNamespaceMapped) {
- this.tableDDLOptions= transactional ? " TRANSACTIONAL=true" : "";
+ public StatsCollectorIT(boolean mutable, boolean transactional, boolean userTableNamespaceMapped, boolean columnEncoded) {
+ StringBuilder sb = new StringBuilder();
+ if (transactional) {
+ sb.append("TRANSACTIONAL=true");
+ }
+ if (columnEncoded) {
+ if (sb.length()>0) {
+ sb.append(",");
+ }
+ sb.append("COLUMN_ENCODED_BYTES=4");
+ }
+ if (!mutable) {
+ if (sb.length()>0) {
+ sb.append(",");
+ }
+ sb.append("IMMUTABLE_ROWS=true");
+ }
+ this.tableDDLOptions = sb.toString();
this.userTableNamespaceMapped = userTableNamespaceMapped;
+ this.columnEncoded = columnEncoded;
+ this.mutable = mutable;
}
- @Parameters(name="transactional = {0}, isUserTableNamespaceMapped = {1}")
+ @Parameters(name="columnEncoded = {0}, mutable = {1}, transactional = {2}, isUserTableNamespaceMapped = {3}")
public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {{false,true}, {false, false}, {true, false}, {true, true}});
+ return Arrays.asList(new Boolean[][] {
+ { false, false, false, false }, { false, false, false, true }, { false, false, true, false }, { false, false, true, true },
+ // no need to test non column encoded mutable case and this is the same as non column encoded immutable
+ //{ false, true, false, false }, { false, true, false, true }, { false, true, true, false }, { false, true, true, true },
+ { true, false, false, false }, { true, false, false, true }, { true, false, true, false }, { true, false, true, true },
+ { true, true, false, false }, { true, true, false, true }, { true, true, true, false }, { true, true, true, true }
+ });
}
@BeforeClass
@@ -147,25 +178,28 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
"CREATE TABLE " + fullTableName +" ( k VARCHAR PRIMARY KEY, a.v1 VARCHAR, b.v2 VARCHAR ) " + tableDDLOptions + (tableDDLOptions.isEmpty() ? "" : ",") + "SALT_BUCKETS = 3");
conn.createStatement().execute("UPSERT INTO " + fullTableName + "(k,v1) VALUES('a','123456789')");
conn.createStatement().execute("UPDATE STATISTICS " + fullTableName);
+
ResultSet rs;
String explainPlan;
rs = conn.createStatement().executeQuery("EXPLAIN SELECT v2 FROM " + fullTableName + " WHERE v2='foo'");
explainPlan = QueryUtil.getExplainPlan(rs);
+ // if we are using the ONE_CELL_PER_COLUMN_FAMILY storage scheme, we will have the single kv even though there are no values for col family v2
+ String stats = columnEncoded && !mutable ? "4-CHUNK 1 ROWS 58 BYTES" : "3-CHUNK 0 ROWS 0 BYTES";
assertEquals(
- "CLIENT 3-CHUNK 0 ROWS 0 BYTES PARALLEL 3-WAY FULL SCAN OVER " + physicalTableName + "\n" +
+ "CLIENT " + stats + " PARALLEL 3-WAY FULL SCAN OVER " + physicalTableName + "\n" +
" SERVER FILTER BY B.V2 = 'foo'\n" +
"CLIENT MERGE SORT",
explainPlan);
rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM " + fullTableName);
explainPlan = QueryUtil.getExplainPlan(rs);
assertEquals(
- "CLIENT 4-CHUNK 1 ROWS 28 BYTES PARALLEL 3-WAY FULL SCAN OVER " + physicalTableName + "\n" +
+ "CLIENT 4-CHUNK 1 ROWS " + (columnEncoded ? "28" : "34") + " BYTES PARALLEL 3-WAY FULL SCAN OVER " + physicalTableName + "\n" +
"CLIENT MERGE SORT",
explainPlan);
rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM " + fullTableName + " WHERE k = 'a'");
explainPlan = QueryUtil.getExplainPlan(rs);
assertEquals(
- "CLIENT 1-CHUNK 1 ROWS 204 BYTES PARALLEL 1-WAY POINT LOOKUP ON 1 KEY OVER " + physicalTableName + "\n" +
+ "CLIENT 1-CHUNK 1 ROWS " + (columnEncoded ? "204" : "202") + " BYTES PARALLEL 1-WAY POINT LOOKUP ON 1 KEY OVER " + physicalTableName + "\n" +
"CLIENT MERGE SORT",
explainPlan);
@@ -368,11 +402,13 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
}
@Test
+ @Ignore //TODO remove this once https://issues.apache.org/jira/browse/TEPHRA-208 is fixed
public void testCompactUpdatesStats() throws Exception {
testCompactUpdatesStats(0, fullTableName);
}
@Test
+ @Ignore //TODO remove this once https://issues.apache.org/jira/browse/TEPHRA-208 is fixed
public void testCompactUpdatesStatsWithMinStatsUpdateFreq() throws Exception {
testCompactUpdatesStats(QueryServicesOptions.DEFAULT_STATS_UPDATE_FREQ_MS, fullTableName);
}
@@ -390,6 +426,7 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
Connection conn = getConnection(statsUpdateFreq);
PreparedStatement stmt;
conn.createStatement().execute("CREATE TABLE " + tableName + "(k CHAR(1) PRIMARY KEY, v INTEGER, w INTEGER) "
+ + (!tableDDLOptions.isEmpty() ? tableDDLOptions + "," : "")
+ HColumnDescriptor.KEEP_DELETED_CELLS + "=" + Boolean.FALSE);
stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(?,?,?)");
for (int i = 0; i < nRows; i++) {
@@ -399,11 +436,13 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
stmt.executeUpdate();
}
conn.commit();
+
compactTable(conn, physicalTableName);
- if (statsUpdateFreq == null) {
+
+ if (statsUpdateFreq != 0) {
invalidateStats(conn, tableName);
} else {
- // Confirm that when we have a non zero MIN_STATS_UPDATE_FREQ_MS_ATTRIB, after we run
+ // Confirm that when we have a non zero STATS_UPDATE_FREQ_MS_ATTRIB, after we run
// UPDATATE STATISTICS, the new statistics are faulted in as expected.
List<KeyRange>keyRanges = getAllSplits(conn, tableName);
assertNotEquals(nRows+1, keyRanges.size());
@@ -419,20 +458,40 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
conn.commit();
assertEquals(5, nDeletedRows);
+ Scan scan = new Scan();
+ scan.setRaw(true);
+ PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
+ try (HTableInterface htable = phxConn.getQueryServices().getTable(Bytes.toBytes(tableName))) {
+ ResultScanner scanner = htable.getScanner(scan);
+ Result result;
+ while ((result = scanner.next())!=null) {
+ System.out.println(result);
+ }
+ }
+
compactTable(conn, physicalTableName);
- if (statsUpdateFreq == null) {
- invalidateStats(conn, tableName);
+
+ scan = new Scan();
+ scan.setRaw(true);
+ phxConn = conn.unwrap(PhoenixConnection.class);
+ try (HTableInterface htable = phxConn.getQueryServices().getTable(Bytes.toBytes(tableName))) {
+ ResultScanner scanner = htable.getScanner(scan);
+ Result result;
+ while ((result = scanner.next())!=null) {
+ System.out.println(result);
+ }
}
- keyRanges = getAllSplits(conn, tableName);
- if (statsUpdateFreq != null) {
+ if (statsUpdateFreq != 0) {
+ invalidateStats(conn, tableName);
+ } else {
assertEquals(nRows+1, keyRanges.size());
- // If we've set MIN_STATS_UPDATE_FREQ_MS_ATTRIB, an UPDATE STATISTICS will invalidate the cache
+ // If we've set STATS_UPDATE_FREQ_MS_ATTRIB, an UPDATE STATISTICS will invalidate the cache
// and force us to pull over the new stats
int rowCount = conn.createStatement().executeUpdate("UPDATE STATISTICS " + tableName);
assertEquals(5, rowCount);
- keyRanges = getAllSplits(conn, tableName);
}
+ keyRanges = getAllSplits(conn, tableName);
assertEquals(nRows/2+1, keyRanges.size());
ResultSet rs = conn.createStatement().executeQuery("SELECT SUM(GUIDE_POSTS_ROW_COUNT) FROM "
+ PhoenixDatabaseMetaData.SYSTEM_STATS_NAME + " WHERE PHYSICAL_NAME='" + physicalTableName + "'");
@@ -447,7 +506,8 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
PreparedStatement stmt;
conn.createStatement().execute(
"CREATE TABLE " + fullTableName
- + "(k VARCHAR PRIMARY KEY, a.v INTEGER, b.v INTEGER, c.v INTEGER NULL, d.v INTEGER NULL) ");
+ + "(k VARCHAR PRIMARY KEY, a.v INTEGER, b.v INTEGER, c.v INTEGER NULL, d.v INTEGER NULL) "
+ + tableDDLOptions );
stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?, ?, ?, ?)");
byte[] val = new byte[250];
for (int i = 0; i < nRows; i++) {
@@ -473,7 +533,7 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
List<KeyRange> keyRanges = getAllSplits(conn, fullTableName);
assertEquals(26, keyRanges.size());
rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM " + fullTableName);
- assertEquals("CLIENT 26-CHUNK 25 ROWS 12530 BYTES PARALLEL 1-WAY FULL SCAN OVER " + physicalTableName,
+ assertEquals("CLIENT 26-CHUNK 25 ROWS " + (columnEncoded ? ( mutable ? "12530" : "14422" ) : "12420") + " BYTES PARALLEL 1-WAY FULL SCAN OVER " + physicalTableName,
QueryUtil.getExplainPlan(rs));
ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
@@ -485,7 +545,8 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
+ QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB + "\"=" + Long.toString(1000);
conn.createStatement().execute(query);
keyRanges = getAllSplits(conn, fullTableName);
- assertEquals(12, keyRanges.size());
+ boolean oneCellPerColFamliyStorageScheme = !mutable && columnEncoded;
+ assertEquals(oneCellPerColFamliyStorageScheme ? 13 : 12, keyRanges.size());
rs = conn
.createStatement()
@@ -496,25 +557,25 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
assertTrue(rs.next());
assertEquals("A", rs.getString(1));
assertEquals(24, rs.getInt(2));
- assertEquals(12252, rs.getInt(3));
- assertEquals(11, rs.getInt(4));
+ assertEquals(columnEncoded ? ( mutable ? 12252 : 14144 ) : 12144, rs.getInt(3));
+ assertEquals(oneCellPerColFamliyStorageScheme ? 12 : 11, rs.getInt(4));
assertTrue(rs.next());
assertEquals("B", rs.getString(1));
- assertEquals(20, rs.getInt(2));
- assertEquals(5600, rs.getInt(3));
- assertEquals(5, rs.getInt(4));
+ assertEquals(oneCellPerColFamliyStorageScheme ? 24 : 20, rs.getInt(2));
+ assertEquals(columnEncoded ? ( mutable ? 5600 : 7492 ) : 5540, rs.getInt(3));
+ assertEquals(oneCellPerColFamliyStorageScheme ? 6 : 5, rs.getInt(4));
assertTrue(rs.next());
assertEquals("C", rs.getString(1));
assertEquals(24, rs.getInt(2));
- assertEquals(6724, rs.getInt(3));
+ assertEquals(columnEncoded ? ( mutable ? 6724 : 7516 ) : 6652, rs.getInt(3));
assertEquals(6, rs.getInt(4));
assertTrue(rs.next());
assertEquals("D", rs.getString(1));
assertEquals(24, rs.getInt(2));
- assertEquals(6724, rs.getInt(3));
+ assertEquals(columnEncoded ? ( mutable ? 6724 : 7516 ) : 6652, rs.getInt(3));
assertEquals(6, rs.getInt(4));
assertFalse(rs.next());
@@ -539,7 +600,7 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
Connection conn = getConnection();
String ddl = "CREATE TABLE " + fullTableName + " (t_id VARCHAR NOT NULL,\n" + "k1 INTEGER NOT NULL,\n"
+ "k2 INTEGER NOT NULL,\n" + "C3.k3 INTEGER,\n" + "C2.v1 VARCHAR,\n"
- + "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2)) split on ('e','j','o')";
+ + "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2)) " + tableDDLOptions + " split on ('e','j','o')";
conn.createStatement().execute(ddl);
String[] strings = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z" };
@@ -559,7 +620,7 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
int startIndex = r.nextInt(strings.length);
int endIndex = r.nextInt(strings.length - startIndex) + startIndex;
long rows = endIndex - startIndex;
- long c2Bytes = rows * 37;
+ long c2Bytes = rows * (columnEncoded ? ( mutable ? 37 : 70 ) : 35);
String physicalTableName = SchemaUtil.getPhysicalHBaseTableName(fullTableName, userTableNamespaceMapped, PTableType.TABLE).getString();
rs = conn.createStatement().executeQuery(
"SELECT COLUMN_FAMILY,SUM(GUIDE_POSTS_ROW_COUNT),SUM(GUIDE_POSTS_WIDTH) from SYSTEM.STATS where PHYSICAL_NAME = '"
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
index 8e1db17..ed294bf 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
@@ -25,31 +25,34 @@ import static org.junit.Assert.assertTrue;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
-import java.sql.SQLException;
import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.phoenix.expression.ArrayColumnExpression;
+import org.apache.phoenix.expression.KeyValueColumnExpression;
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.TestUtil;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
/**
* Tests to demonstrate and verify the STORE_NULLS option on a table,
@@ -57,82 +60,101 @@ import org.junit.Test;
* functionality allows having row-level versioning (similar to how KEEP_DELETED_CELLS works), but
* also allows permanently deleting a row.
*/
-
-//TODO: samarth parameterize this test once the storage scheme is optional
+@RunWith(Parameterized.class)
public class StoreNullsIT extends ParallelStatsDisabledIT {
- private static final Log LOG = LogFactory.getLog(StoreNullsIT.class);
- private String WITH_NULLS;
- private String WITHOUT_NULLS;
- private String IMMUTABLE_WITH_NULLS;
- private String IMMUTABLE_WITHOUT_NULLS;
- private Connection conn;
- private Statement stmt;
-
- @Before
- public void setUp() throws SQLException {
- WITH_NULLS = generateUniqueName();
- WITHOUT_NULLS = generateUniqueName();
- IMMUTABLE_WITH_NULLS = generateUniqueName();
- IMMUTABLE_WITHOUT_NULLS = generateUniqueName();
- conn = DriverManager.getConnection(getUrl());
- conn.setAutoCommit(true);
-
- stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + WITH_NULLS + " (" +
- "id SMALLINT NOT NULL PRIMARY KEY, " +
- "name VARCHAR) " +
- "STORE_NULLS = true, VERSIONS = 1000, KEEP_DELETED_CELLS = false");
- stmt.execute("CREATE TABLE " + WITHOUT_NULLS + " (" +
- "id SMALLINT NOT NULL PRIMARY KEY, " +
- "name VARCHAR) " +
- "VERSIONS = 1000, KEEP_DELETED_CELLS = false");
- stmt.execute("CREATE TABLE " + IMMUTABLE_WITH_NULLS + " ("
- + "id SMALLINT NOT NULL PRIMARY KEY, name VARCHAR) "
- + "STORE_NULLS = true, VERSIONS = 1, KEEP_DELETED_CELLS = false, IMMUTABLE_ROWS=true");
- stmt.execute("CREATE TABLE " + IMMUTABLE_WITHOUT_NULLS + " ("
- + "id SMALLINT NOT NULL PRIMARY KEY, name VARCHAR) "
- + "VERSIONS = 1, KEEP_DELETED_CELLS = false, IMMUTABLE_ROWS=true");
+ private final boolean mutable;
+ private final boolean columnEncoded;
+ private final boolean storeNulls;
+ private final String ddlFormat;
+
+ private String dataTableName;
+
+ public StoreNullsIT(boolean mutable, boolean columnEncoded, boolean storeNulls) {
+ this.mutable = mutable;
+ this.columnEncoded = columnEncoded;
+ this.storeNulls = storeNulls;
+
+ StringBuilder sb = new StringBuilder("CREATE TABLE %s (id SMALLINT NOT NULL PRIMARY KEY, name VARCHAR) VERSIONS = 1000, KEEP_DELETED_CELLS = false ");
+ if (!mutable) {
+ sb.append(",").append("IMMUTABLE_ROWS=true");
+ }
+ if (columnEncoded) {
+ sb.append(",").append("COLUMN_ENCODED_BYTES=4");
+ }
+ if (storeNulls) {
+ sb.append(",").append("STORE_NULLS=true");
+ }
+ this.ddlFormat = sb.toString();
}
-
- @After
- public void tearDown() throws SQLException {
- stmt.close();
- conn.close();
+
+ @Parameters(name="StoreNullsIT_mutable={0}, columnEncoded={1}, storeNulls={2}") // name is used by failsafe as file name in reports
+ public static Collection<Boolean[]> data() {
+ return Arrays.asList(new Boolean[][] {
+ { false, false, false }, { false, false, true },
+ { false, true, false }, { false, true, true },
+ { true, false, false }, { true, false, true },
+ { true, true, false }, { true, true, true }});
+ }
+
+
+ @Before
+ public void setupTableNames() throws Exception {
+ dataTableName = generateUniqueName();
}
@Test
public void testStoringNullsForImmutableTables() throws Exception {
- stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITH_NULLS + " VALUES (1, 'v1')");
- stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITHOUT_NULLS + " VALUES (1, 'v1')");
- stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITH_NULLS + " VALUES (2, null)");
- stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITHOUT_NULLS + " VALUES (2, null)");
-
- ensureNullsStoredAsEmptyByteArrays(IMMUTABLE_WITH_NULLS);
- ensureNullsStoredAsEmptyByteArrays(IMMUTABLE_WITHOUT_NULLS);
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Statement stmt = conn.createStatement()) {
+ conn.setAutoCommit(true);
+ stmt.execute(String.format(ddlFormat, dataTableName));
+ stmt.executeUpdate("UPSERT INTO " + dataTableName + " VALUES (1, 'v1')");
+ stmt.executeUpdate("UPSERT INTO " + dataTableName + " VALUES (2, null)");
+ TestUtil.doMajorCompaction(conn, dataTableName);
+ ensureNullsStoredCorrectly(conn);
+ }
}
- private void ensureNullsStoredAsEmptyByteArrays(String tableName) throws Exception {
- HTable htable = new HTable(getUtility().getConfiguration(), tableName);
+ private void ensureNullsStoredCorrectly(Connection conn) throws Exception {
+ ResultSet rs1 = conn.createStatement().executeQuery("SELECT NAME FROM "+dataTableName);
+ rs1.next();
+ assertEquals("v1", rs1.getString(1));
+ rs1.next();
+ assertNull(rs1.getString(1));
+ rs1.next();
+
+ HTable htable = new HTable(getUtility().getConfiguration(), dataTableName);
Scan s = new Scan();
s.setRaw(true);
ResultScanner scanner = htable.getScanner(s);
// first row has a value for name
Result rs = scanner.next();
+ PTable table = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, dataTableName));
+ PColumn nameColumn = table.getPColumnForColumnName("NAME");
+ byte[] qualifier = table.getStorageScheme()== StorageScheme.ONE_CELL_PER_COLUMN_FAMILY ? QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES : nameColumn.getColumnQualifierBytes();
+ assertTrue(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, qualifier));
assertTrue(rs.size() == 2); // 2 because it also includes the empty key value column
- PColumn nameColumn = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, tableName)).getPColumnForColumnName("NAME");
- ArrayColumnExpression colExpression = new ArrayColumnExpression(nameColumn, "NAME", QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS);
+ KeyValueColumnExpression colExpression = table.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY ? new ArrayColumnExpression(nameColumn, "NAME", table.getEncodingScheme()) : new KeyValueColumnExpression(nameColumn);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
colExpression.evaluate(new ResultTuple(rs), ptr);
assertEquals(new ImmutableBytesPtr(PVarchar.INSTANCE.toBytes("v1")), ptr);
-
rs = scanner.next();
- assertTrue(rs.size() == 2); // 2 because it also includes the empty key value column
- // assert null stored as empty
+ if ( !mutable && !columnEncoded // we don't issue a put with empty value for immutable tables with cols stored per key value
+ || (mutable && !storeNulls)) { // for this case we use a delete to represent the null
+ assertFalse(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, qualifier));
+ assertEquals(1, rs.size());
+ }
+ else {
+ assertTrue(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, qualifier));
+ assertEquals(2, rs.size());
+ }
+ // assert null stored correctly
ptr = new ImmutableBytesPtr();
- colExpression.evaluate(new ResultTuple(rs), ptr);
- assertEquals(new ImmutableBytesPtr(ByteUtil.EMPTY_BYTE_ARRAY), ptr);
+ if (colExpression.evaluate(new ResultTuple(rs), ptr)) {
+ assertEquals(new ImmutableBytesPtr(ByteUtil.EMPTY_BYTE_ARRAY), ptr);
+ }
assertNull(scanner.next());
scanner.close();
htable.close();
@@ -140,93 +162,80 @@ public class StoreNullsIT extends ParallelStatsDisabledIT {
@Test
public void testQueryingHistory() throws Exception {
- stmt.executeUpdate("UPSERT INTO " + WITH_NULLS + " VALUES (1, 'v1')");
- stmt.executeUpdate("UPSERT INTO " + WITHOUT_NULLS + " VALUES (1, 'v1')");
-
- Thread.sleep(10L);
- long afterFirstInsert = System.currentTimeMillis();
- Thread.sleep(10L);
-
- stmt.executeUpdate("UPSERT INTO " + WITH_NULLS + " VALUES (1, null)");
- stmt.executeUpdate("UPSERT INTO " + WITHOUT_NULLS + " VALUES (1, null)");
- Thread.sleep(10L);
-
- TestUtil.doMajorCompaction(conn, WITH_NULLS);
- TestUtil.doMajorCompaction(conn, WITHOUT_NULLS);
-
- Properties historicalProps = new Properties();
- historicalProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Statement stmt = conn.createStatement()) {
+ conn.setAutoCommit(true);
+ stmt.execute(String.format(ddlFormat, dataTableName));
+ stmt.executeUpdate("UPSERT INTO " + dataTableName + " VALUES (1, 'v1')");
+ Thread.sleep(10L);
+ long afterFirstInsert = System.currentTimeMillis();
+ Thread.sleep(10L);
+
+ stmt.executeUpdate("UPSERT INTO " + dataTableName + " VALUES (1, null)");
+ Thread.sleep(10L);
+
+ TestUtil.doMajorCompaction(conn, dataTableName);
+
+ Properties historicalProps = new Properties();
+ historicalProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
Long.toString(afterFirstInsert));
- Connection historicalConn = DriverManager.getConnection(getUrl(), historicalProps);
- Statement historicalStmt = historicalConn.createStatement();
-
- ResultSet rs = historicalStmt.executeQuery(
- "SELECT name FROM " + WITH_NULLS + " WHERE id = 1");
- assertTrue(rs.next());
- assertEquals("v1", rs.getString(1));
- rs.close();
+ Connection historicalConn = DriverManager.getConnection(getUrl(), historicalProps);
+ Statement historicalStmt = historicalConn.createStatement();
+ ResultSet rs = historicalStmt.executeQuery( "SELECT name FROM " + dataTableName + " WHERE id = 1");
+
+ if (storeNulls || !mutable) { // store nulls is set to true if the table is immutable
+ assertTrue(rs.next());
+ assertEquals("v1", rs.getString(1));
+ rs.close();
+ }
+ else {
+ // The single null wipes out all history for a field if STORE_NULLS is not enabled
+ assertTrue(rs.next());
+ assertNull(rs.getString(1));
+ }
+
+ rs.close();
+ historicalStmt.close();
+ historicalConn.close();
+ }
- // The single null wipes out all history for a field if STORE_NULLS is not enabled
- rs = historicalStmt.executeQuery("SELECT name FROM " + WITHOUT_NULLS + " WHERE id = 1");
- assertTrue(rs.next());
- assertNull(rs.getString(1));
- rs.close();
-
- historicalStmt.close();
- historicalConn.close();
}
// Row deletes should work in the same way regardless of what STORE_NULLS is set to
@Test
public void testDeletes() throws Exception {
- stmt.executeUpdate("UPSERT INTO " + WITH_NULLS + " VALUES (1, 'v1')");
- stmt.executeUpdate("UPSERT INTO " + WITHOUT_NULLS + " VALUES (1, 'v1')");
-
- Thread.sleep(10L);
- long afterFirstInsert = System.currentTimeMillis();
- Thread.sleep(10L);
-
- stmt.executeUpdate("DELETE FROM " + WITH_NULLS + " WHERE id = 1");
- stmt.executeUpdate("DELETE FROM " + WITHOUT_NULLS + " WHERE id = 1");
- Thread.sleep(10L);
-
- TestUtil.doMajorCompaction(conn, WITH_NULLS);
- TestUtil.doMajorCompaction(conn, WITHOUT_NULLS);
-
- Properties historicalProps = new Properties();
- historicalProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(afterFirstInsert));
- Connection historicalConn = DriverManager.getConnection(getUrl(), historicalProps);
- Statement historicalStmt = historicalConn.createStatement();
-
- // The row should be completely gone for both tables now
-
- ResultSet rs = historicalStmt.executeQuery(
- "SELECT name FROM " + WITH_NULLS + " WHERE id = 1");
- assertFalse(rs.next());
- rs.close();
-
- rs = historicalStmt.executeQuery("SELECT name FROM " + WITHOUT_NULLS + " WHERE id = 1");
- assertFalse(rs.next());
- rs.close();
- }
-
- @Test
- public void testSetStoreNullsDefaultViaConfig() throws SQLException {
- Properties props = new Properties();
- props.setProperty(QueryServices.DEFAULT_STORE_NULLS_ATTRIB, "true");
- Connection storeNullsConn = DriverManager.getConnection(getUrl(), props);
-
- Statement stmt = storeNullsConn.createStatement();
- stmt.execute("CREATE TABLE with_nulls_default (" +
- "id smallint primary key," +
- "name varchar)");
-
- ResultSet rs = stmt.executeQuery("SELECT store_nulls FROM SYSTEM.CATALOG " +
- "WHERE table_name = 'WITH_NULLS_DEFAULT' AND store_nulls is not null");
- assertTrue(rs.next());
- assertTrue(rs.getBoolean(1));
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Statement stmt = conn.createStatement()) {
+ conn.setAutoCommit(true);
+ stmt.execute(String.format(ddlFormat, dataTableName));
+ stmt.executeUpdate("UPSERT INTO " + dataTableName + " VALUES (1, 'v1')");
+
+ Thread.sleep(10L);
+ long afterFirstInsert = System.currentTimeMillis();
+ Thread.sleep(10L);
+
+ stmt.executeUpdate("DELETE FROM " + dataTableName + " WHERE id = 1");
+ Thread.sleep(10L);
+
+ TestUtil.doMajorCompaction(conn, dataTableName);
+
+ Properties historicalProps = new Properties();
+ historicalProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
+ Long.toString(afterFirstInsert));
+ Connection historicalConn = DriverManager.getConnection(getUrl(), historicalProps);
+ Statement historicalStmt = historicalConn.createStatement();
+
+ // The row should be completely gone for both tables now
+
+ ResultSet rs = historicalStmt.executeQuery(
+ "SELECT name FROM " + dataTableName + " WHERE id = 1");
+ assertFalse(rs.next());
+ rs.close();
+
+ rs = historicalStmt.executeQuery("SELECT name FROM " + dataTableName + " WHERE id = 1");
+ assertFalse(rs.next());
+ rs.close();
+ }
}
-
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsPropIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsPropIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsPropIT.java
new file mode 100644
index 0000000..26ff629
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsPropIT.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.apache.phoenix.query.QueryServices;
+import org.junit.Test;
+
+public class StoreNullsPropIT extends ParallelStatsDisabledIT {
+
+ @Test
+ public void testSetStoreNullsDefaultViaConfig() throws SQLException {
+ Properties props = new Properties();
+ props.setProperty(QueryServices.DEFAULT_STORE_NULLS_ATTRIB, "true");
+ Connection storeNullsConn = DriverManager.getConnection(getUrl(), props);
+
+ Statement stmt = storeNullsConn.createStatement();
+ stmt.execute("CREATE TABLE with_nulls_default (" +
+ "id smallint primary key," +
+ "name varchar)");
+
+ ResultSet rs = stmt.executeQuery("SELECT store_nulls FROM SYSTEM.CATALOG " +
+ "WHERE table_name = 'WITH_NULLS_DEFAULT' AND store_nulls is not null");
+ assertTrue(rs.next());
+ assertTrue(rs.getBoolean(1));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java
index 6b394c1..f9ef0c2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java
@@ -27,8 +27,8 @@ import com.google.common.collect.Maps;
public class SysTableNamespaceMappedStatsCollectorIT extends StatsCollectorIT {
- public SysTableNamespaceMappedStatsCollectorIT(boolean transactional, boolean userTableNamespaceMapped) {
- super(transactional, userTableNamespaceMapped);
+ public SysTableNamespaceMappedStatsCollectorIT(boolean mutable, boolean transactional, boolean userTableNamespaceMapped, boolean columnEncoded) {
+ super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
}
@BeforeClass
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index c8318ec..7615935 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -61,7 +61,6 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.NamedTableNode;
import org.apache.phoenix.parse.TableName;
import org.apache.phoenix.query.BaseTest;
-import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
index 499f58c..d1ab61e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
@@ -54,6 +54,7 @@ import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -614,11 +615,13 @@ public class MutableIndexIT extends ParallelStatsDisabledIT {
}
@Test
+ @Ignore //TODO remove after PHOENIX-3585 is fixed
public void testSplitDuringIndexScan() throws Exception {
testSplitDuringIndexScan(false);
}
@Test
+ @Ignore //TODO remove after PHOENIX-3585 is fixed
public void testSplitDuringIndexReverseScan() throws Exception {
testSplitDuringIndexScan(true);
}
@@ -676,6 +679,7 @@ public class MutableIndexIT extends ParallelStatsDisabledIT {
}
@Test
+ @Ignore //TODO remove after PHOENIX-3585 is fixed
public void testIndexHalfStoreFileReader() throws Exception {
Connection conn1 = getConnection();
HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index fb4e3c3..2c3c663 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -368,6 +368,8 @@ public enum SQLExceptionCode {
CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW(1134, "XCL34", "Altering this table property on a view is not allowed"),
IMMUTABLE_TABLE_PROPERTY_INVALID(1135, "XCL35", "IMMUTABLE table property cannot be used with CREATE IMMUTABLE TABLE statement "),
+
+ MAX_COLUMNS_EXCEEDED(1136, "XCL36", "The number of columns exceed the maximum supported by the table's qualifier encoding scheme"),
/**
* Implementation defined class. Phoenix internal error. (errorcode 20, sqlstate INT).
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
index fd8ac8b..d345a07 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
@@ -306,6 +306,9 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
public static final byte[] SYSTEM_MUTEX_NAME_BYTES = Bytes.toBytes(SYSTEM_MUTEX_NAME);
public static final byte[] SYSTEM_MUTEX_FAMILY_NAME_BYTES = TABLE_FAMILY_BYTES;
+ public static final String COLUMN_ENCODED_BYTES = "COLUMN_ENCODED_BYTES";
+ public static final byte[] COLUMN_ENCODED_BYTES_BYTES = Bytes.toBytes(COLUMN_ENCODED_BYTES);
+
private final PhoenixConnection connection;
private final ResultSet emptyResultSet;
public static final int MAX_LOCAL_SI_VERSION_DISALLOW = VersionUtil.encodeVersion("0", "98", "8");
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
index eee4a5f..4085251 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
@@ -224,7 +224,7 @@ public interface QueryConstants {
public static final ImmutableBytesPtr DEFAULT_COLUMN_FAMILY_BYTES_PTR = new ImmutableBytesPtr(
DEFAULT_COLUMN_FAMILY_BYTES);
// column qualifier of the single key value used to store all columns for the COLUMNS_STORED_IN_SINGLE_CELL storage scheme
- public static final String SINGLE_KEYVALUE_COLUMN_QUALIFIER = "0";
+ public static final String SINGLE_KEYVALUE_COLUMN_QUALIFIER = "1";
public final static byte[] SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES = Bytes.toBytes(SINGLE_KEYVALUE_COLUMN_QUALIFIER);
public static final ImmutableBytesPtr SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES_PTR = new ImmutableBytesPtr(
SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
index 65d385e..3789138 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
@@ -226,6 +226,8 @@ public interface QueryServices extends SQLCloseable {
public static final String CLIENT_CACHE_ENCODING = "phoenix.table.client.cache.encoding";
public static final String AUTO_UPGRADE_ENABLED = "phoenix.autoupgrade.enabled";
+
+ public static final String DEFAULT_COLUMN_ENCODED_BYTES_ATRRIB = "phoenix.default.column.encoded.bytes.attrib";
/**
* Get executor service used for parallel scans
*/
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
index 3b4d9cc..60599f9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
@@ -256,6 +256,8 @@ public class QueryServicesOptions {
public static final String DEFAULT_CLIENT_CACHE_ENCODING = PTableRefFactory.Encoding.OBJECT.toString();
public static final boolean DEFAULT_AUTO_UPGRADE_ENABLED = true;
+
+ public static final int DEFAULT_COLUMN_ENCODED_BYTES = 0;
@SuppressWarnings("serial")
public static final Set<String> DEFAULT_QUERY_SERVER_SKIP_WORDS = new HashSet<String>() {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 7c3876a..67b7663 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -93,7 +93,6 @@ import static org.apache.phoenix.query.QueryServices.DROP_METADATA_ATTRIB;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_DROP_METADATA;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RUN_UPDATE_STATS_ASYNC;
import static org.apache.phoenix.schema.PTable.EncodedCQCounter.NULL_COUNTER;
-import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS;
import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
import static org.apache.phoenix.schema.PTable.StorageScheme.ONE_CELL_PER_COLUMN_FAMILY;
import static org.apache.phoenix.schema.PTable.StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN;
@@ -199,6 +198,7 @@ import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTable.LinkType;
import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme.QualifierOutOfRangeException;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTable.ViewType;
import org.apache.phoenix.schema.stats.GuidePostsKey;
@@ -977,7 +977,7 @@ public class MetaDataClient {
}
table = createTableInternal(statement, splits, parent, viewStatement, viewType, viewColumnConstants, isViewColumnReferenced, false, null, null, tableProps, commonFamilyProps);
- if (table == null || table.getType() == PTableType.VIEW || table.isTransactional()) {
+ if (table == null || table.getType() == PTableType.VIEW /*|| table.isTransactional()*/) {
return new MutationState(0,connection);
}
// Hack to get around the case when an SCN is specified on the connection.
@@ -1695,6 +1695,7 @@ public class MetaDataClient {
? SchemaUtil.isNamespaceMappingEnabled(tableType, connection.getQueryServices().getProps())
: parent.isNamespaceMapped();
boolean isLocalIndex = indexType == IndexType.LOCAL;
+ QualifierEncodingScheme encodingScheme = QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
if (parent != null && tableType == PTableType.INDEX) {
timestamp = TransactionUtil.getTableTimestamp(connection, transactional);
storeNulls = parent.getStoreNulls();
@@ -2033,7 +2034,6 @@ public class MetaDataClient {
int pkPositionOffset = pkColumns.size();
int position = positionOffset;
StorageScheme storageScheme = ONE_CELL_PER_KEYVALUE_COLUMN;
- QualifierEncodingScheme encodingScheme = NON_ENCODED_QUALIFIERS;
EncodedCQCounter cqCounter = NULL_COUNTER;
PTable viewPhysicalTable = null;
if (tableType == PTableType.VIEW) {
@@ -2087,23 +2087,22 @@ public class MetaDataClient {
tableExists = false;
}
if (tableExists) {
- storageScheme = ONE_CELL_PER_KEYVALUE_COLUMN;
encodingScheme = NON_ENCODED_QUALIFIERS;
} else if (parent != null) {
- storageScheme = parent.getStorageScheme();
encodingScheme = parent.getEncodingScheme();
- } else if (isImmutableRows) {
- storageScheme = ONE_CELL_PER_COLUMN_FAMILY;
- encodingScheme = FOUR_BYTE_QUALIFIERS;
- // since we are storing all columns of a column family in a single key value we can't use deletes to store nulls
- storeNulls = true;
} else {
- storageScheme = ONE_CELL_PER_KEYVALUE_COLUMN;
- encodingScheme = FOUR_BYTE_QUALIFIERS;
+ Byte encodingSchemeSerializedByte = (Byte) TableProperty.COLUMN_ENCODED_BYTES.getValue(tableProps);
+ if (encodingSchemeSerializedByte == null) {
+ encodingSchemeSerializedByte = (byte)connection.getQueryServices().getProps().getInt(QueryServices.DEFAULT_COLUMN_ENCODED_BYTES_ATRRIB, QueryServicesOptions.DEFAULT_COLUMN_ENCODED_BYTES);
+ }
+ encodingScheme = QualifierEncodingScheme.fromSerializedValue(encodingSchemeSerializedByte);
}
+ if (isImmutableRows && encodingScheme != NON_ENCODED_QUALIFIERS) {
+ storageScheme = ONE_CELL_PER_COLUMN_FAMILY;
+ }
cqCounter = encodingScheme != NON_ENCODED_QUALIFIERS ? new EncodedCQCounter() : NULL_COUNTER;
}
-
+
Map<String, Integer> changedCqCounters = new HashMap<>(colDefs.size());
for (ColumnDef colDef : colDefs) {
rowTimeStampColumnAlreadyFound = checkAndValidateRowTimestampCol(colDef, pkConstraint, rowTimeStampColumnAlreadyFound, tableType);
@@ -2137,7 +2136,15 @@ public class MetaDataClient {
}
}
Integer encodedCQ = isPkColumn ? null : cqCounter.getNextQualifier(cqCounterFamily);
- byte[] columnQualifierBytes = EncodedColumnsUtil.getColumnQualifierBytes(columnDefName.getColumnName(), encodedCQ, encodingScheme);
+ byte[] columnQualifierBytes = null;
+ try {
+ columnQualifierBytes = EncodedColumnsUtil.getColumnQualifierBytes(columnDefName.getColumnName(), encodedCQ, encodingScheme);
+ }
+ catch (QualifierOutOfRangeException e) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.MAX_COLUMNS_EXCEEDED)
+ .setSchemaName(schemaName)
+ .setTableName(tableName).build().buildException();
+ }
PColumn column = newColumn(position++, colDef, pkConstraint, defaultFamilyName, false, columnQualifierBytes);
if (cqCounter.increment(cqCounterFamily)) {
changedCqCounters.put(cqCounterFamily, cqCounter.getNextQualifier(cqCounterFamily));
@@ -2177,8 +2184,6 @@ public class MetaDataClient {
}
}
-
-
// We need a PK definition for a TABLE or mapped VIEW
if (!isPK && pkColumnsNames.isEmpty() && tableType != PTableType.VIEW && viewType != ViewType.MAPPED) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_MISSING)
@@ -3182,7 +3187,15 @@ public class MetaDataClient {
cqCounterToUse.getNextQualifier(familyName));
}
}
- byte[] columnQualifierBytes = EncodedColumnsUtil.getColumnQualifierBytes(colDef.getColumnDefName().getColumnName(), encodedCQ, table);
+ byte[] columnQualifierBytes = null;
+ try {
+ columnQualifierBytes = EncodedColumnsUtil.getColumnQualifierBytes(colDef.getColumnDefName().getColumnName(), encodedCQ, table);
+ }
+ catch (QualifierOutOfRangeException e) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.MAX_COLUMNS_EXCEEDED)
+ .setSchemaName(schemaName)
+ .setTableName(tableName).build().buildException();
+ }
PColumn column = newColumn(position++, colDef, PrimaryKeyConstraint.EMPTY, table.getDefaultFamilyName() == null ? null : table.getDefaultFamilyName().getString(), true, columnQualifierBytes);
columns.add(column);
String pkName = null;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
index 9962859..36df961 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
@@ -145,6 +145,27 @@ public enum TableProperty {
}
},
+
+ COLUMN_ENCODED_BYTES(PhoenixDatabaseMetaData.COLUMN_ENCODED_BYTES, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, false, false) {
+ @Override
+ public Object getValue(Object value) {
+ if (value instanceof String) {
+ String strValue = (String) value;
+ if ("NONE".equalsIgnoreCase(strValue)) {
+ return (byte)0;
+ }
+ } else {
+ return value == null ? null : ((Number) value).byteValue();
+ }
+ return value;
+ }
+
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.getEncodingScheme();
+ }
+
+ }
;
private final String propertyName;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
index 67aae72..6c8ac48 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
@@ -762,7 +762,7 @@ public class QueryOptimizerTest extends BaseConnectionlessQueryTest {
public void testMinMaxQualifierRangeWithOrderByOnKVColumn() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String tableName = "testMintestMinMaxQualifierRange".toUpperCase();
- conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER, v2 VARCHAR)");
+ conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER, v2 VARCHAR) COLUMN_ENCODED_BYTES=4");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
ResultSet rs = stmt.executeQuery("SELECT K from " + tableName + " ORDER BY (v1)");
assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE);
@@ -778,7 +778,7 @@ public class QueryOptimizerTest extends BaseConnectionlessQueryTest {
public void testMinMaxQualifierRangeWithNoOrderBy() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String tableName = "testMintestMinMaxQualifierRange".toUpperCase();
- conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER, v2 VARCHAR)");
+ conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER, v2 VARCHAR) COLUMN_ENCODED_BYTES=4");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
ResultSet rs = stmt.executeQuery("SELECT K from " + tableName);
assertQualifierRanges(rs, ENCODED_CQ_COUNTER_INITIAL_VALUE, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
index 8553b73..276d946 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
@@ -127,11 +127,11 @@ public class MutationStateTest {
private void assertTable(String tableName1,List<KeyValue> keyValues1,String tableName2,List<KeyValue> keyValues2) {
assertTrue("MUTATION_TEST1".equals(tableName1));
assertTrue(Bytes.equals(PUnsignedInt.INSTANCE.toBytes(111),CellUtil.cloneRow(keyValues1.get(0))));
- assertTrue("app1".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues1.get(1)))));
+ assertTrue("app1".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues1.get(0)))));
assertTrue("MUTATION_TEST2".equals(tableName2));
assertTrue(Bytes.equals(PUnsignedInt.INSTANCE.toBytes(222),CellUtil.cloneRow(keyValues2.get(0))));
- assertTrue("app2".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues2.get(1)))));
+ assertTrue("app2".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues2.get(0)))));
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index 41d6e7b..a87b4f2 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -147,7 +147,8 @@ import org.apache.tephra.TransactionManager;
import org.apache.tephra.TxConstants;
import org.apache.tephra.distributed.TransactionService;
import org.apache.tephra.metrics.TxMetricsCollector;
-import org.apache.tephra.persist.InMemoryTransactionStateStorage;
+import org.apache.tephra.persist.HDFSTransactionStateStorage;
+import org.apache.tephra.snapshot.SnapshotCodecProvider;
import org.apache.twill.discovery.DiscoveryService;
import org.apache.twill.discovery.ZKDiscoveryService;
import org.apache.twill.internal.utils.Networks;
@@ -450,14 +451,18 @@ public abstract class BaseTest {
}
- protected static void setupTxManager() throws SQLException, IOException {
+ protected static void setTxnConfigs() throws IOException {
config.setBoolean(TxConstants.Manager.CFG_DO_PERSIST, false);
config.set(TxConstants.Service.CFG_DATA_TX_CLIENT_RETRY_STRATEGY, "n-times");
config.setInt(TxConstants.Service.CFG_DATA_TX_CLIENT_ATTEMPTS, 1);
config.setInt(TxConstants.Service.CFG_DATA_TX_BIND_PORT, Networks.getRandomPort());
config.set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, tmpFolder.newFolder().getAbsolutePath());
config.setInt(TxConstants.Manager.CFG_TX_TIMEOUT, DEFAULT_TXN_TIMEOUT_SECONDS);
-
+ config.unset(TxConstants.Manager.CFG_TX_HDFS_USER);
+ config.setLong(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, 5L);
+ }
+
+ protected static void setupTxManager() throws SQLException, IOException {
ConnectionInfo connInfo = ConnectionInfo.create(getUrl());
zkClient = ZKClientServices.delegate(
ZKClients.reWatchOnExpire(
@@ -473,7 +478,7 @@ public abstract class BaseTest {
zkClient.startAndWait();
DiscoveryService discovery = new ZKDiscoveryService(zkClient);
- txManager = new TransactionManager(config, new InMemoryTransactionStateStorage(), new TxMetricsCollector());
+ txManager = new TransactionManager(config, new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()), new TxMetricsCollector());
txService = new TransactionService(config, zkClient, discovery, Providers.of(txManager));
txService.startAndWait();
}
@@ -502,8 +507,9 @@ public abstract class BaseTest {
/**
* Set up the test hbase cluster.
* @return url to be used by clients to connect to the cluster.
+ * @throws IOException
*/
- protected static String setUpTestCluster(@Nonnull Configuration conf, ReadOnlyProps overrideProps) {
+ protected static String setUpTestCluster(@Nonnull Configuration conf, ReadOnlyProps overrideProps) throws IOException {
boolean isDistributedCluster = isDistributedClusterModeEnabled(conf);
if (!isDistributedCluster) {
return initMiniCluster(conf, overrideProps);
@@ -558,8 +564,9 @@ public abstract class BaseTest {
}
protected static void setUpTestDriver(ReadOnlyProps serverProps, ReadOnlyProps clientProps) throws Exception {
+ setTxnConfigs();
String url = checkClusterInitialized(serverProps);
- checkTxManagerInitialized(clientProps);
+ checkTxManagerInitialized(serverProps);
if (driver == null) {
driver = initAndRegisterTestDriver(url, clientProps);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
index 1d71ec0..76479d6 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
@@ -95,8 +95,8 @@ public class ConnectionlessTest {
" entity_history_id char(12) not null,\n" +
" created_by varchar,\n" +
" created_date date\n" +
- " CONSTRAINT pk PRIMARY KEY (organization_id, key_prefix, entity_history_id) ) " +
- (saltBuckets == null ? "" : (PhoenixDatabaseMetaData.SALT_BUCKETS + "=" + saltBuckets));
+ " CONSTRAINT pk PRIMARY KEY (organization_id, key_prefix, entity_history_id) ) COLUMN_ENCODED_BYTES=4 " +
+ (saltBuckets == null ? "" : " , " + (PhoenixDatabaseMetaData.SALT_BUCKETS + "=" + saltBuckets));
Properties props = new Properties();
Connection conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement statement = conn.prepareStatement(dmlStmt);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index 3c9a1bc..ead712b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -74,6 +74,7 @@ import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheRequest;
import org.apache.phoenix.coprocessor.generated.MetaDataProtos.ClearCacheResponse;
import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService;
+import org.apache.phoenix.execute.MutationState;
import org.apache.phoenix.expression.AndExpression;
import org.apache.phoenix.expression.ByteBasedLikeExpression;
import org.apache.phoenix.expression.ComparisonExpression;
@@ -108,6 +109,7 @@ import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PLongColumn;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.RowKeyValueAccessor;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableRef;
@@ -769,15 +771,26 @@ public class TestUtil {
// We simply write a marker row, request a major compaction, and then wait until the marker
// row is gone
+ PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
+ PTable table = pconn.getTable(new PTableKey(pconn.getTenantId(), tableName));
ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
- try (HTableInterface htable = services.getTable(Bytes.toBytes(tableName))) {
+ MutationState mutationState = pconn.getMutationState();
+ if (table.isTransactional()) {
+ mutationState.startTransaction();
+ }
+ try (HTableInterface htable = mutationState.getHTable(table)) {
byte[] markerRowKey = Bytes.toBytes("TO_DELETE");
-
+
Put put = new Put(markerRowKey);
- put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, HConstants.EMPTY_BYTE_ARRAY,
- HConstants.EMPTY_BYTE_ARRAY);
+ put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_VALUE_BYTES, QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
htable.put(put);
- htable.delete(new Delete(markerRowKey));
+ Delete delete = new Delete(markerRowKey);
+ delete.deleteColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
+ htable.delete(delete);
+ htable.close();
+ if (table.isTransactional()) {
+ mutationState.commit();
+ }
HBaseAdmin hbaseAdmin = services.getAdmin();
hbaseAdmin.flush(tableName);
@@ -786,19 +799,28 @@ public class TestUtil {
boolean compactionDone = false;
while (!compactionDone) {
- Thread.sleep(2000L);
+ Thread.sleep(6000L);
Scan scan = new Scan();
scan.setStartRow(markerRowKey);
scan.setStopRow(Bytes.add(markerRowKey, new byte[] { 0 }));
scan.setRaw(true);
- ResultScanner scanner = htable.getScanner(scan);
- List<Result> results = Lists.newArrayList(scanner);
- LOG.info("Results: " + results);
- compactionDone = results.isEmpty();
- scanner.close();
-
+ try (HTableInterface htableForRawScan = services.getTable(Bytes.toBytes(tableName))) {
+ ResultScanner scanner = htableForRawScan.getScanner(scan);
+ List<Result> results = Lists.newArrayList(scanner);
+ LOG.info("Results: " + results);
+ compactionDone = results.isEmpty();
+ scanner.close();
+ }
LOG.info("Compaction done: " + compactionDone);
+
+ // need to run compaction after the next txn snapshot has been written so that compaction can remove deleted rows
+ if (!compactionDone && table.isTransactional()) {
+ hbaseAdmin = services.getAdmin();
+ hbaseAdmin.flush(tableName);
+ hbaseAdmin.majorCompact(tableName);
+ hbaseAdmin.close();
+ }
}
}
}
[2/2] phoenix git commit: PHOENIX-3519 Specify
QualifierEncodingScheme in CREATE TABLE statement
Posted by td...@apache.org.
PHOENIX-3519 Specify QualifierEncodingScheme in CREATE TABLE statement
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/61d9035c
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/61d9035c
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/61d9035c
Branch: refs/heads/encodecolumns2
Commit: 61d9035cd09bd1fff834dccd03a454df803e521a
Parents: c004c6e
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Mon Jan 9 19:22:19 2017 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Wed Jan 25 09:18:48 2017 -0800
----------------------------------------------------------------------
.../AlterMultiTenantTableWithViewsIT.java | 25 +-
.../apache/phoenix/end2end/AlterTableIT.java | 237 ++++++++-------
.../phoenix/end2end/AlterTableWithViewsIT.java | 210 +++++++------
.../end2end/ColumnEncodedBytesPropIT.java | 95 ++++++
.../phoenix/end2end/StatsCollectorIT.java | 115 ++++++--
.../apache/phoenix/end2end/StoreNullsIT.java | 291 ++++++++++---------
.../phoenix/end2end/StoreNullsPropIT.java | 51 ++++
...SysTableNamespaceMappedStatsCollectorIT.java | 4 +-
.../apache/phoenix/end2end/index/IndexIT.java | 1 -
.../phoenix/end2end/index/MutableIndexIT.java | 4 +
.../phoenix/exception/SQLExceptionCode.java | 2 +
.../phoenix/jdbc/PhoenixDatabaseMetaData.java | 3 +
.../apache/phoenix/query/QueryConstants.java | 2 +-
.../org/apache/phoenix/query/QueryServices.java | 2 +
.../phoenix/query/QueryServicesOptions.java | 2 +
.../apache/phoenix/schema/MetaDataClient.java | 47 +--
.../apache/phoenix/schema/TableProperty.java | 21 ++
.../phoenix/compile/QueryOptimizerTest.java | 4 +-
.../phoenix/execute/MutationStateTest.java | 4 +-
.../java/org/apache/phoenix/query/BaseTest.java | 19 +-
.../phoenix/query/ConnectionlessTest.java | 4 +-
.../java/org/apache/phoenix/util/TestUtil.java | 46 ++-
22 files changed, 769 insertions(+), 420 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
index 8275f3f..adadca7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
@@ -17,7 +17,6 @@
*/
package org.apache.phoenix.end2end;
-import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
import static org.apache.phoenix.query.QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT;
import static org.apache.phoenix.query.QueryConstants.DIVERGED_VIEW_BASE_COLUMN_COUNT;
import static org.junit.Assert.assertEquals;
@@ -477,14 +476,14 @@ public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
// For a diverged view, only base table's pk column will be added and that too at the end.
assertTableDefinition(conn, divergedView, PTableType.VIEW, baseTable, 2, 7, DIVERGED_VIEW_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V3", "VIEW_COL1", "VIEW_COL2", "PK2");
- // Adding existing column VIEW_COL2 to the base table isn't allowed.
+ // Add existing column VIEW_COL2 to the base table
alterBaseTable = "ALTER TABLE " + baseTable + " ADD VIEW_COL2 CHAR(256)";
- try {
- conn.createStatement().execute(alterBaseTable);
- fail();
- } catch (SQLException e) {
- assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
- }
+ conn.createStatement().execute(alterBaseTable);
+
+ // For the non-diverged view, adding the column VIEW_COL2 will end up changing its ordinal position in the view.
+ assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 2, 9, 8, "TENANT_ID", "PK1", "V1", "V2", "V3", "KV", "PK2", "VIEW_COL2", "VIEW_COL1");
+ // For the diverged view, adding the column VIEW_COL2 will not change its ordinal position in the view. It also won't change the base column count or the sequence number
+ assertTableDefinition(conn, divergedView, PTableType.VIEW, baseTable, 2, 7, DIVERGED_VIEW_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V3", "VIEW_COL1", "VIEW_COL2", "PK2");
}
}
@@ -501,13 +500,13 @@ public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
tenant1Conn.createStatement().execute(view1DDL);
}
- assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 1, 5, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3");
+ assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 0, 5, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3");
assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 0, 7, 5, "TENANT_ID", "PK1", "V1", "V2", "V3", "VIEW_COL1", "VIEW_COL2");
String alterBaseTable = "ALTER TABLE " + baseTable + " ADD KV VARCHAR, PK2 VARCHAR PRIMARY KEY";
conn.createStatement().execute(alterBaseTable);
- assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 2, 7, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3", "KV", "PK2");
+ assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 1, 7, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3", "KV", "PK2");
assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 1, 9, 7, "TENANT_ID", "PK1", "V1", "V2", "V3", "KV", "PK2", "VIEW_COL1", "VIEW_COL2");
// verify that the both columns were added to view1
@@ -531,13 +530,13 @@ public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
tenant1Conn.createStatement().execute(view1DDL);
}
- assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 1, 5, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3");
+ assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 0, 5, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3");
assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 0, 7, 5, "TENANT_ID", "PK1", "V1", "V2", "V3", "VIEW_COL1", "VIEW_COL2");
String alterBaseTable = "ALTER TABLE " + baseTable + " DROP COLUMN V2";
conn.createStatement().execute(alterBaseTable);
- assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 2, 4, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V3");
+ assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 1, 4, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V3");
assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 1, 6, 4, "TENANT_ID", "PK1", "V1", "V3", "VIEW_COL1", "VIEW_COL2");
// verify that the dropped columns aren't visible
@@ -570,7 +569,7 @@ public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
String view1DDL = "CREATE VIEW " + view1 + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 CHAR(256)) AS SELECT * FROM " + baseTable;
tenant1Conn.createStatement().execute(view1DDL);
// This should not modify the base table
- String alterView = "ALTER VIEW " + view1 + " ADD NEWCOL1 VARCHAR, NEWCOL5 VARCHAR";
+ String alterView = "ALTER VIEW " + view1 + " ADD NEWCOL1 VARCHAR";
tenant1Conn.createStatement().execute(alterView);
HTableDescriptor tableDesc2 = tenant1Conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin().getTableDescriptor(Bytes.toBytes(baseTable));
assertEquals(tableDesc1, tableDesc2);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index c2fb031..9799b08 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -44,6 +44,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Properties;
import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -73,6 +75,9 @@ import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
/**
*
@@ -85,14 +90,28 @@ import org.junit.Test;
* or at the end of test class.
*
*/
+@RunWith(Parameterized.class)
public class AlterTableIT extends ParallelStatsDisabledIT {
private String schemaName;
private String dataTableName;
private String indexTableName;
private String localIndexTableName;
+ private String viewName;
private String dataTableFullName;
private String indexTableFullName;
private String localIndexTableFullName;
+ private String tableDDLOptions;
+ private final boolean columnEncoded;
+
+ public AlterTableIT(boolean columnEncoded) {
+ this.columnEncoded = columnEncoded;
+ this.tableDDLOptions = columnEncoded ? "COLUMN_ENCODED_BYTES=4" : "";
+ }
+
+ @Parameters(name="AlterTableIT_columnEncoded={0}") // name is used by failsafe as file name in reports
+ public static Collection<Boolean> data() {
+ return Arrays.asList( false, true);
+ }
@Before
public void setupTableNames() throws Exception {
@@ -103,6 +122,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
localIndexTableFullName = SchemaUtil.getTableName(schemaName, localIndexTableName);
+ viewName = generateUniqueName();
}
@Test
@@ -114,7 +134,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
try {
String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, a_binary varbinary not null, col1 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string, a_binary)) " + tableDDLOptions;
createTestTable(getUrl(), ddl);
ddl = "ALTER TABLE " + dataTableFullName + " ADD b_string VARCHAR NULL PRIMARY KEY";
@@ -155,7 +175,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
try {
String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, col1 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
conn.createStatement().execute(ddl);
String dml = "UPSERT INTO " + dataTableFullName + " VALUES(?)";
@@ -222,7 +242,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
Connection conn = DriverManager.getConnection(getUrl(), props);
String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, col1 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
try {
conn.createStatement().execute(ddl);
conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD CF.col2 integer CF.IN_MEMORY=true");
@@ -255,6 +275,19 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
helpTestDropIndexedColumn(false);
}
+ private String generateDDLOptions(String options) {
+ StringBuilder sb = new StringBuilder();
+ if (!options.isEmpty()) {
+ sb.append(options);
+ }
+ if (!tableDDLOptions.isEmpty()) {
+ if (sb.length()!=0)
+ sb.append(",");
+ sb.append(tableDDLOptions);
+ }
+ return sb.toString();
+ }
+
private void helpTestDropIndexedColumn(boolean immutable) throws Exception {
String query;
ResultSet rs;
@@ -267,7 +300,8 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
// make sure that the tables are empty, but reachable
conn.createStatement().execute(
"CREATE TABLE " + dataTableFullName
- + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) " + (immutable ? "IMMUTABLE_ROWS = true" : ""));
+ + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) "
+ + generateDDLOptions((immutable ? "IMMUTABLE_ROWS = true" : "")));
query = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
@@ -327,7 +361,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
// make sure that the tables are empty, but reachable
conn.createStatement().execute(
"CREATE TABLE " + dataTableFullName
- + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR)");
+ + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR) " + tableDDLOptions);
String dataTableQuery = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(dataTableQuery);
assertFalse(rs.next());
@@ -442,7 +476,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
// make sure that the tables are empty, but reachable
conn.createStatement().execute(
"CREATE TABLE " + dataTableFullName
- + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
+ + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) " + tableDDLOptions);
query = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
@@ -538,7 +572,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
" B.M_TEXT VARCHAR\n" +
" CONSTRAINT ROWKEY PRIMARY KEY\n" +
"(SENDER_ID,RECIPIENT_ID,M_TIMESTAMP DESC,ROW_ID))\n" +
- "SALT_BUCKETS=4";
+ generateDDLOptions("SALT_BUCKETS=4");
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET IMMUTABLE_ROWS=true";
@@ -572,7 +606,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
" B.M_TEXT VARCHAR\n" +
" CONSTRAINT ROWKEY PRIMARY KEY\n" +
"(SENDER_ID,RECIPIENT_ID,M_TIMESTAMP DESC,ROW_ID))\n" +
- "SALT_BUCKETS=4";
+ generateDDLOptions("SALT_BUCKETS=4");
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN B.JSON";
@@ -595,7 +629,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
try {
String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, col1 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
conn.createStatement().execute(ddl);
String dml = "UPSERT INTO " + dataTableFullName + " VALUES(?)";
@@ -702,7 +736,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
try {
String ddl = "CREATE TABLE " + dataTableFullName + " " + " (a_string varchar not null, col1 integer, cf1.col2 integer"
- + " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ + " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN col1";
@@ -725,7 +759,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
try {
String ddl = "CREATE TABLE " + dataTableFullName + " " + " (a_string varchar not null, col1 integer, cf1.col2 integer"
- + " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ + " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
stmt = conn.prepareStatement(ddl);
stmt.execute();
} finally {
@@ -760,7 +794,8 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
.execute(
"CREATE TABLE " + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
- + " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true, disable_wal=true ");
+ + " CONSTRAINT pk PRIMARY KEY (a_string)) "
+ + generateDDLOptions("immutable_rows=true, disable_wal=true"));
Connection conn2 = DriverManager.getConnection(getUrl(), props);
String query = "SELECT * FROM " + dataTableFullName;
@@ -792,7 +827,8 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
.execute(
"CREATE TABLE " + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
- + " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true");
+ + " CONSTRAINT pk PRIMARY KEY (a_string))"
+ + generateDDLOptions("immutable_rows=true"));
Connection conn2 = DriverManager.getConnection(getUrl(), props);
String query = "SELECT * FROM " + dataTableFullName;
@@ -825,7 +861,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
.execute(
"CREATE TABLE " + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
- + " CONSTRAINT pk PRIMARY KEY (a_string))");
+ + " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions);
Connection conn2 = DriverManager.getConnection(getUrl(), props);
String query = "SELECT * FROM " + dataTableFullName;
@@ -863,7 +899,8 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
.execute(
"CREATE TABLE " + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
- + " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
+ + " CONSTRAINT pk PRIMARY KEY (a_string)) "
+ + generateDDLOptions("immutable_rows=true , SALT_BUCKETS=3 "));
String query = "SELECT * FROM " + dataTableFullName;
ResultSet rs = conn.createStatement().executeQuery(query);
@@ -952,7 +989,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
// here we insert into the orig schema with one column
Connection conn1 = DriverManager.getConnection(getUrl(), props);
- conn1.createStatement().execute("create table " + dataTableFullName + "(id VARCHAR PRIMARY KEY, field1 BIGINT)");
+ conn1.createStatement().execute("create table " + dataTableFullName + "(id VARCHAR PRIMARY KEY, field1 BIGINT) " + tableDDLOptions);
PreparedStatement stmtInsert1 = conn1.prepareStatement("upsert into " + dataTableFullName + " (id, field1) values ( ?, ?)");
stmtInsert1.setString(1, "key1");
stmtInsert1.setLong(2, 1L);
@@ -984,7 +1021,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2))";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + tableDDLOptions;
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " ADD STRING VARCHAR, STRING_DATA_TYPES VARCHAR";
@@ -1001,7 +1038,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID VARCHAR(15) PRIMARY KEY,\n"
- +"COL1 BIGINT)";
+ +"COL1 BIGINT) " + tableDDLOptions;
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
conn1.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + "(COL1)");
@@ -1058,7 +1095,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ "COL1 BIGINT,"
+ "COL2 BIGINT,"
+ "COL3 BIGINT,"
- + "COL4 BIGINT)";
+ + "COL4 BIGINT) " + tableDDLOptions;
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
conn1.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + "(COL1) INCLUDE (COL2,COL3,COL4)");
@@ -1114,7 +1151,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET REPLICATION_SCOPE=1";
@@ -1137,7 +1174,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED=FALSE";
@@ -1159,7 +1196,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, REPLICATION_SCOPE = 1";
@@ -1183,7 +1220,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CF1.CREATION_TIME BIGINT,\n"
+"CF2.LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) IMMUTABLE_ROWS=true";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("IMMUTABLE_ROWS=true");
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(ddl);
assertImmutableRows(conn, dataTableFullName, true);
@@ -1225,7 +1262,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET CF.COMPACTION_ENABLED = FALSE";
@@ -1246,7 +1283,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET CF.DISABLE_WAL = TRUE";
@@ -1267,7 +1304,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"CF.LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET CF.TTL = 86400";
@@ -1288,7 +1325,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET CF.REPLICATION_SCOPE = 1";
@@ -1309,7 +1346,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions(" SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET DEFAULT_COLUMN_FAMILY = 'A'";
@@ -1330,19 +1367,19 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "CREATE VIEW v AS SELECT * FROM " + dataTableFullName + " WHERE CREATION_TIME = 1";
+ ddl = "CREATE VIEW " + viewName + " AS SELECT * FROM " + dataTableFullName + " WHERE CREATION_TIME = 1";
conn1.createStatement().execute(ddl);
- ddl = "ALTER VIEW v SET REPLICATION_SCOPE = 1";
+ ddl = "ALTER VIEW " + viewName + " SET REPLICATION_SCOPE = 1";
try {
conn1.createStatement().execute(ddl);
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.VIEW_WITH_PROPERTIES.getErrorCode(), e.getErrorCode());
}
- ddl = "ALTER VIEW v SET COMPACTION_ENABLED = FALSE";
+ ddl = "ALTER VIEW " + viewName + " SET COMPACTION_ENABLED = FALSE";
try {
conn1.createStatement().execute(ddl);
fail();
@@ -1360,7 +1397,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
String viewFullName = SchemaUtil.getTableName(schemaName, generateUniqueName());
@@ -1395,7 +1432,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
+"CF.LAST_USED DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) IMMUTABLE_ROWS=true, DEFAULT_COLUMN_FAMILY = 'XYZ'";
+ +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("IMMUTABLE_ROWS=true, DEFAULT_COLUMN_FAMILY = 'XYZ'");
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(ddl);
assertImmutableRows(conn, dataTableFullName, true);
@@ -1429,7 +1466,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
String ddl = "CREATE TABLE " + dataTableFullName
+
" (a_string varchar not null, col1 integer, CF.col2 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
try {
conn.createStatement().execute(ddl);
conn.createStatement().execute(
@@ -1455,7 +1492,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
String ddl = "CREATE TABLE " + dataTableFullName + " "
+
" (a_string varchar not null, col1 integer, CF1.col2 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
try {
conn.createStatement().execute(ddl);
conn.createStatement()
@@ -1489,7 +1526,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
String ddl = "CREATE TABLE " + dataTableFullName + " "
+
" (a_string varchar not null, col1 integer, CF1.col2 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + generateDDLOptions("DEFAULT_COLUMN_FAMILY = 'XYZ'");
try {
conn.createStatement().execute(ddl);
conn.createStatement()
@@ -1523,7 +1560,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
String ddl = "CREATE TABLE " + dataTableFullName + " "
+
" (a_string varchar not null, col1 integer, CF1.col2 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) "+ generateDDLOptions("DEFAULT_COLUMN_FAMILY = 'XYZ'");
try {
conn.createStatement().execute(ddl);
try {
@@ -1546,7 +1583,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
String ddl = "CREATE TABLE " + dataTableFullName
+
" (a_string varchar not null, col1 integer, CF1.col2 integer, CF2.col3 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + generateDDLOptions("DEFAULT_COLUMN_FAMILY = 'XYZ' ");
try {
conn.createStatement().execute(ddl);
conn.createStatement()
@@ -1583,7 +1620,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
String ddl = "CREATE TABLE " + dataTableFullName
+
" (a_string varchar not null, col1 integer, CF1.col2 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + generateDDLOptions("DEFAULT_COLUMN_FAMILY = 'XYZ'");
try {
conn.createStatement().execute(ddl);
conn.createStatement().execute(
@@ -1613,7 +1650,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, col1 integer" +
- " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
try {
conn.createStatement().execute(ddl);
conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD col2 integer IN_MEMORY=true");
@@ -1641,7 +1678,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
"CREATE TABLE "
+ dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
- + " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
+ + " CONSTRAINT pk PRIMARY KEY (a_string)) " + generateDDLOptions("immutable_rows=true , SALT_BUCKETS=3 "));
String ddl = "Alter table " + dataTableFullName + " add cf3.col5 integer, cf4.col6 integer in_memory=true";
conn.createStatement().execute(ddl);
@@ -1679,7 +1716,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
"CREATE TABLE "
+ dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
- + " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
+ + " CONSTRAINT pk PRIMARY KEY (a_string)) " + generateDDLOptions("immutable_rows=true , SALT_BUCKETS=3 "));
String ddl = "Alter table " + dataTableFullName + " add cf1.col5 integer in_memory=true";
conn.createStatement().execute(ddl);
@@ -1709,7 +1746,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
try {
String ddl = "CREATE TABLE " + dataTableFullName
- + " (pk char(2) not null primary key, col1 integer, b.col1 integer) SPLIT ON ('EA','EZ')";
+ + " (pk char(2) not null primary key, col1 integer, b.col1 integer) " + tableDDLOptions + " SPLIT ON ('EA','EZ') ";
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " add b.col2 varchar ttl=30";
conn.createStatement().execute(ddl);
@@ -1729,7 +1766,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
try {
String ddl = "CREATE TABLE " + dataTableFullName
- + " (pk char(2) not null primary key) TTL=100 SPLIT ON ('EA','EZ')";
+ + " (pk char(2) not null primary key) " + generateDDLOptions("TTL=100") + " SPLIT ON ('EA','EZ')";
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " add col1 varchar ttl=30";
conn.createStatement().execute(ddl);
@@ -1759,7 +1796,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
- + " ) TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'";
+ + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'");
conn.createStatement().execute(ddl);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
@@ -1794,7 +1831,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
- + " ) TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'";
+ + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'");
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET IN_MEMORY=true";
conn.createStatement().execute(ddl);
@@ -1822,7 +1859,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
- + " ) TTL=86400, SALT_BUCKETS = 4";
+ + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4");
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET IN_MEMORY=true";
conn.createStatement().execute(ddl);
@@ -1850,7 +1887,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
- + " ) TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'";
+ + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'");
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " ADD COL3 INTEGER IN_MEMORY=true";
conn.createStatement().execute(ddl);
@@ -1878,7 +1915,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
- + " ) TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'";
+ + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'");
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " ADD NEWCF.COL3 INTEGER IN_MEMORY=true";
conn.createStatement().execute(ddl);
@@ -1908,7 +1945,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
- + " ) TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'";
+ + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'");
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " ADD NEWCF.COL3 INTEGER IN_MEMORY=true";
conn.createStatement().execute(ddl);
@@ -1972,7 +2009,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
- + " )";
+ + " ) " + tableDDLOptions;
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " ADD NEWCF.COL3 INTEGER NEWCF.UNKNOWN_PROP='ABC'";
try {
@@ -1998,7 +2035,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
Connection conn = DriverManager.getConnection(getUrl(), props);
Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + dataTableFullName + " (id SMALLINT PRIMARY KEY, name VARCHAR)");
+ stmt.execute("CREATE TABLE " + dataTableFullName + " (id SMALLINT PRIMARY KEY, name VARCHAR) "+tableDDLOptions);
ResultSet rs = stmt.executeQuery("SELECT STORE_NULLS FROM SYSTEM.CATALOG " +
"WHERE table_name = '"
@@ -2030,7 +2067,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " k2 integer NOT NULL,"
+ " col1 bigint,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (k1, k2)"
- + " )";
+ + " ) "+tableDDLOptions;
conn.createStatement().execute(ddl);
// set HTableProperty when adding a pk column should fail
@@ -2104,7 +2141,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
- + " )";
+ + " ) "+tableDDLOptions;
conn.createStatement().execute(ddl);
asssertIsWALDisabled(conn, dataTableFullName, false);
@@ -2141,7 +2178,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
@Test
public void testDeclaringColumnAsRowTimestamp() throws Exception {
try (Connection conn = DriverManager.getConnection(getUrl())) {
- conn.createStatement().execute("CREATE TABLE " + dataTableFullName + " (PK1 DATE NOT NULL, PK2 VARCHAR NOT NULL, KV1 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1 ROW_TIMESTAMP, PK2)) ");
+ conn.createStatement().execute("CREATE TABLE " + dataTableFullName + " (PK1 DATE NOT NULL, PK2 VARCHAR NOT NULL, KV1 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1 ROW_TIMESTAMP, PK2)) " + tableDDLOptions);
PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
PTable table = phxConn.getTable(new PTableKey(phxConn.getTenantId(), dataTableFullName));
// Assert that the column shows up as row time stamp in the cache.
@@ -2199,7 +2236,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
@Test
public void testAddingRowTimestampColumnNotAllowedViaAlterTable() throws Exception {
try (Connection conn = DriverManager.getConnection(getUrl())) {
- conn.createStatement().execute("CREATE TABLE " + dataTableFullName + " (PK1 VARCHAR NOT NULL, PK2 VARCHAR NOT NULL, KV1 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1, PK2)) ");
+ conn.createStatement().execute("CREATE TABLE " + dataTableFullName + " (PK1 VARCHAR NOT NULL, PK2 VARCHAR NOT NULL, KV1 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1, PK2)) " + tableDDLOptions);
// adding a new pk column that is also row_timestamp is not allowed
try {
conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD PK3 DATE PRIMARY KEY ROW_TIMESTAMP");
@@ -2217,7 +2254,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
// creating a transactional table should fail if transactions are disabled
try {
- conn.createStatement().execute("CREATE TABLE " + dataTableFullName + "(k INTEGER PRIMARY KEY, v VARCHAR) TRANSACTIONAL=true");
+ conn.createStatement().execute("CREATE TABLE " + dataTableFullName + "(k INTEGER PRIMARY KEY, v VARCHAR) " + generateDDLOptions("TRANSACTIONAL=true"));
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_IF_TXNS_DISABLED.getErrorCode(), e.getErrorCode());
@@ -2239,7 +2276,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
String tableName = generateUniqueName();
conn.createStatement().execute(
"CREATE TABLE " + tableName
- + " (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2)) ");
+ + " (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2)) " + tableDDLOptions);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
admin.disableTable(Bytes.toBytes(tableName));
}
@@ -2256,7 +2293,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
}
@Test
- public void testMetadataForImmutableTableWithEncodedColumns() throws Exception {
+ public void testMetadataForImmutableTable() throws Exception {
String schemaName = "XYZ";
String baseTableName = generateUniqueName();
String viewName = generateUniqueName();
@@ -2270,17 +2307,17 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " COL2 bigint NOT NULL,"
+ " KV1 VARCHAR"
+ " CONSTRAINT NAME_PK PRIMARY KEY (ID, COL1, COL2)"
- + " ) IMMUTABLE_ROWS = true");
+ + " ) " + generateDDLOptions("IMMUTABLE_ROWS = true"));
PTable baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
long initBaseTableSeqNumber = baseTable.getSequenceNumber();
// assert that the client side cache is updated.
EncodedCQCounter cqCounter = baseTable.getEncodedCQCounter();
- assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1), cqCounter.getNextQualifier(QueryConstants.DEFAULT_COLUMN_FAMILY));
+ assertEquals( columnEncoded ? (Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1) : null, cqCounter.getNextQualifier(QueryConstants.DEFAULT_COLUMN_FAMILY));
// assert that the server side metadata is updated correctly.
- assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1, true);
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "KV1", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE);
assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber);
@@ -2291,22 +2328,22 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
PTable view = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullViewName));
// verify that the client side cache is updated. Base table's cq counters should be updated.
- assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 2), baseTable.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
- assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1), baseTable.getEncodedCQCounter().getNextQualifier("A"));
+ assertEquals( columnEncoded ? (Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 2) : null, baseTable.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
+ assertEquals( columnEncoded ? (Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1) : null, baseTable.getEncodedCQCounter().getNextQualifier("A"));
assertNull("A view should always have the null cq counter", view.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
// assert that the server side metadata for the base table and the view is also updated correctly.
- assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 2, true);
- assertEncodedCQCounter("A", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1, true);
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 2);
+ assertEncodedCQCounter("A", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL1", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
assertEncodedCQValue("A", "VIEW_COL2", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE);
- assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 1);
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + (columnEncoded ? 1 : 0));
assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM);
}
}
@Test
- public void testMetadataForMutableTableWithEncodedColumns() throws Exception {
+ public void testMetadataForMutableTable() throws Exception {
String schemaName = "XYZ";
String baseTableName = generateUniqueName();
String viewName = generateUniqueName();
@@ -2320,17 +2357,17 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " COL2 bigint NOT NULL,"
+ " KV1 VARCHAR"
+ " CONSTRAINT NAME_PK PRIMARY KEY (ID, COL1, COL2)"
- + " )");
+ + " ) " + tableDDLOptions);
PTable baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
long initBaseTableSeqNumber = baseTable.getSequenceNumber();
// assert that the client side cache is updated.
EncodedCQCounter cqCounter = baseTable.getEncodedCQCounter();
- assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1), cqCounter.getNextQualifier(QueryConstants.DEFAULT_COLUMN_FAMILY));
+ assertEquals( columnEncoded ? (Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1) : null, cqCounter.getNextQualifier(QueryConstants.DEFAULT_COLUMN_FAMILY));
// assert that the server side metadata is updated correctly.
- assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1, true);
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "KV1", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE);
assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber);
@@ -2341,21 +2378,21 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
PTable view = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullViewName));
// verify that the client side cache is updated. Base table's cq counters should be updated.
- assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 3), baseTable.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
+ assertEquals(columnEncoded ? (Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 3) : null, baseTable.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
assertNull("A view should always have the null cq counter", view.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
// assert that the server side metadata for the base table and the view is also updated correctly.
- assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3, true);
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3);
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL1", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
assertEncodedCQValue("A", "VIEW_COL2", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 2);
- assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 1);
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + (columnEncoded ? 1 : 0));
assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM);
}
}
@Test
- public void testAddingColumnsToTablesAndViewsWithEncodedColumns() throws Exception {
- String schemaName = "XYZ";
+ public void testAddingColumnsToTablesAndViews() throws Exception {
+ String schemaName = generateUniqueName();
String baseTableName = generateUniqueName();
String viewName = generateUniqueName();
String fullTableName = schemaName + "." + baseTableName;
@@ -2370,7 +2407,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+ " COL1 integer NOT NULL,"
+ " COL2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (ID, COL1, COL2)"
- + " )");
+ + " ) " + tableDDLOptions);
PTable baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
long initBaseTableSeqNumber = baseTable.getSequenceNumber();
@@ -2381,30 +2418,30 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
// assert that the client side cache is updated.
baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
EncodedCQCounter encodedCqCounter = baseTable.getEncodedCQCounter();
- assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 3), encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
+ assertEquals( columnEncoded ?(Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 3) : null, encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
// assert that the server side metadata is updated correctly.
- assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3, true);
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3);
// assert that the server side metadata for columns is updated correctly.
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "COL4", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE);
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "COL5", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
assertEncodedCQValue("B", "COL6", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 2);
- assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 1);
+ long baseTableSeqNumBeforeAddingChildCols = initBaseTableSeqNumber + 1;
+ assertSequenceNumber(schemaName, baseTableName, baseTableSeqNumBeforeAddingChildCols);
// Create a view
String viewDDL = "CREATE VIEW " + fullViewName + " ( VIEW_COL1 INTEGER, A.VIEW_COL2 VARCHAR ) AS SELECT * FROM " + fullTableName;
conn.createStatement().execute(viewDDL);
// assert that the server side metadata is updated correctly.
- assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 5, true);
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 5);
// assert that the server side metadata for columns is updated correctly.
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL1", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3);
assertEncodedCQValue("A", "VIEW_COL2", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 4);
- // Creating a view that adds its own columns should increment the base table's sequence number too.
- assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 2);
-
+ // for encoded columns creating a view that adds its own columns should increment the base table's sequence number too.
+ assertSequenceNumber(schemaName, baseTableName, columnEncoded ? initBaseTableSeqNumber + 2 : baseTableSeqNumBeforeAddingChildCols );
// Add column to the view
viewDDL = "ALTER VIEW " + fullViewName + " ADD VIEW_COL3 DECIMAL(10, 2), A.VIEW_COL4 VARCHAR, B.VIEW_COL5 INTEGER";
@@ -2413,7 +2450,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
// assert that the client cache for the base table is updated
baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
encodedCqCounter = baseTable.getEncodedCQCounter();
- assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 8), encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
+ assertEquals( columnEncoded ? (Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 8) : null, encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
// assert client cache for view
PTable view = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullViewName));
@@ -2421,14 +2458,14 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
assertNull("A view should always have the column qualifier counter as null", view.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
// assert that the server side metadata for the base table and the view is also updated correctly.
- assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 8, true);
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 8);
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL1", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3);
assertEncodedCQValue("A", "VIEW_COL2", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 4);
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL3", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 5);
assertEncodedCQValue("A", "VIEW_COL4", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 6);
assertEncodedCQValue("B", "VIEW_COL5", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 7);
- // Adding a column to the should increment the base table's sequence number too since we update the cq counters for column families.
- assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 3);
+ // adding a column to the should increment the base table's sequence number too since we update the cq counters for column families.
+ assertSequenceNumber(schemaName, baseTableName, columnEncoded ? initBaseTableSeqNumber + 3 : baseTableSeqNumBeforeAddingChildCols );
assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM + 1);
// Add column to the base table which doesn't already exist in the view.
@@ -2438,7 +2475,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
// assert that the client cache for the base table is updated
encodedCqCounter = baseTable.getEncodedCQCounter();
- assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 10), encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
+ assertEquals( columnEncoded ? (Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 10) : null, encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
// assert client cache for view
view = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullViewName));
@@ -2446,17 +2483,17 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
assertNull("A view should always have the column qualifier counter as null", view.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
// assert that the server side metadata for the base table and the view is also updated correctly.
- assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, (ENCODED_CQ_COUNTER_INITIAL_VALUE + 10), true);
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, (ENCODED_CQ_COUNTER_INITIAL_VALUE + 10));
assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "COL10", schemaName, viewName, (ENCODED_CQ_COUNTER_INITIAL_VALUE + 8));
assertEncodedCQValue("A", "COL11", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 9);
- assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 4);
+ assertSequenceNumber(schemaName, baseTableName, columnEncoded ? initBaseTableSeqNumber + 4 : initBaseTableSeqNumber + 2 );
assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM + 2);
}
}
private void assertEncodedCQValue(String columnFamily, String columnName, String schemaName, String tableName, int expectedValue) throws Exception {
String query = "SELECT " + COLUMN_QUALIFIER + " FROM SYSTEM.CATALOG WHERE " + TABLE_SCHEM + " = ? AND " + TABLE_NAME
- + " = ? " + " AND " + COLUMN_FAMILY + " = ?" + " AND " + COLUMN_NAME + " = ?";
+ + " = ? " + " AND " + COLUMN_FAMILY + " = ?" + " AND " + COLUMN_NAME + " = ?" + " AND " + COLUMN_QUALIFIER + " IS NOT NULL";
try (Connection conn = DriverManager.getConnection(getUrl())) {
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1, schemaName);
@@ -2465,12 +2502,16 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
stmt.setString(4, columnName);
ResultSet rs = stmt.executeQuery();
assertTrue(rs.next());
- assertTrue(Bytes.equals(QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS.encode(expectedValue), rs.getBytes(1)));
+ if (columnEncoded) {
+ assertTrue(Bytes.equals(QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS.encode(expectedValue), rs.getBytes(1)));
+ } else {
+ assertTrue(Bytes.equals(columnName.getBytes(), rs.getBytes(1)));
+ }
assertFalse(rs.next());
}
}
- private void assertEncodedCQCounter(String columnFamily, String schemaName, String tableName, int expectedValue, boolean rowExists) throws Exception {
+ private void assertEncodedCQCounter(String columnFamily, String schemaName, String tableName, int expectedValue) throws Exception {
String query = "SELECT " + COLUMN_QUALIFIER_COUNTER + " FROM SYSTEM.CATALOG WHERE " + TABLE_SCHEM + " = ? AND " + TABLE_NAME
+ " = ? " + " AND " + COLUMN_FAMILY + " = ? AND " + COLUMN_QUALIFIER_COUNTER + " IS NOT NULL";
try (Connection conn = DriverManager.getConnection(getUrl())) {
@@ -2479,7 +2520,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
stmt.setString(2, tableName);
stmt.setString(3, columnFamily);
ResultSet rs = stmt.executeQuery();
- if (rowExists) {
+ if (columnEncoded) {
assertTrue(rs.next());
assertEquals(expectedValue, rs.getInt(1));
assertFalse(rs.next());
@@ -2511,7 +2552,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"ID VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID))";
+ +"CONSTRAINT PK PRIMARY KEY (ID)) " + tableDDLOptions;
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(ddl);
assertImmutableRows(conn, dataTableFullName, false);
@@ -2527,7 +2568,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
+"ID VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
+"CREATION_TIME BIGINT,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID)) IMMUTABLE_ROWS=true";
+ +"CONSTRAINT PK PRIMARY KEY (ID)) " + generateDDLOptions("COLUMN_ENCODED_BYTES=4, IMMUTABLE_ROWS=true");
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(ddl);
assertImmutableRows(conn, dataTableFullName, true);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index 310071f..73b3756 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -19,7 +19,6 @@ package org.apache.phoenix.end2end;
import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -33,7 +32,6 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Properties;
import org.apache.commons.lang.ArrayUtils;
import org.apache.hadoop.hbase.client.HTableInterface;
@@ -47,8 +45,6 @@ import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.SchemaUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -58,22 +54,41 @@ import org.junit.runners.Parameterized.Parameters;
public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
private final boolean isMultiTenant;
+ private final boolean columnEncoded;
private final String TENANT_SPECIFIC_URL1 = getUrl() + ';' + TENANT_ID_ATTRIB + "=tenant1";
private final String TENANT_SPECIFIC_URL2 = getUrl() + ';' + TENANT_ID_ATTRIB + "=tenant2";
- public AlterTableWithViewsIT(boolean isMultiTenant) {
+ public AlterTableWithViewsIT(boolean isMultiTenant, boolean columnEncoded) {
this.isMultiTenant = isMultiTenant;
+ this.columnEncoded = columnEncoded;
}
- @Parameters(name="AlterTableWithViewsIT_multiTenant={0}") // name is used by failsafe as file name in reports
- public static Collection<Boolean> data() {
- return Arrays.asList(false, true);
+ @Parameters(name="AlterTableWithViewsIT_multiTenant={0}, columnEncoded={1}") // name is used by failsafe as file name in reports
+ public static Collection<Boolean[]> data() {
+ return Arrays.asList(new Boolean[][] {
+ { false, false }, { false, true },
+ { true, false }, { true, true } });
}
private String generateDDL(String format) {
+ return generateDDL("", format);
+ }
+
+ private String generateDDL(String options, String format) {
+ StringBuilder optionsBuilder = new StringBuilder(options);
+ if (columnEncoded) {
+ if (optionsBuilder.length()!=0)
+ optionsBuilder.append(",");
+ optionsBuilder.append("COLUMN_ENCODED_BYTES=4");
+ }
+ if (isMultiTenant) {
+ if (optionsBuilder.length()!=0)
+ optionsBuilder.append(",");
+ optionsBuilder.append("MULTI_TENANT=true");
+ }
return String.format(format, isMultiTenant ? "TENANT_ID VARCHAR NOT NULL, " : "",
- isMultiTenant ? "TENANT_ID, " : "", isMultiTenant ? "MULTI_TENANT=true" : "");
+ isMultiTenant ? "TENANT_ID, " : "", optionsBuilder.toString());
}
@Test
@@ -96,7 +111,7 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
// adding a new pk column and a new regular column
conn.createStatement().execute("ALTER TABLE " + tableName + " ADD COL3 varchar(10) PRIMARY KEY, COL4 integer");
- assertTableDefinition(conn, tableName, PTableType.TABLE, null, 2, 5, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "COL3", "COL4");
+ assertTableDefinition(conn, tableName, PTableType.TABLE, null, columnEncoded ? 2 : 1, 5, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "COL3", "COL4");
assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 1, 7, 5, "ID", "COL1", "COL2", "COL3", "COL4", "VIEW_COL1", "VIEW_COL2");
}
}
@@ -113,28 +128,27 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
+ " COL1 integer NOT NULL,"
+ " COL2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
- + " ) UPDATE_CACHE_FREQUENCY=15 "
- + (isMultiTenant ? ",%s" : "%s");
- conn.createStatement().execute(generateDDL(ddlFormat));
+ + " ) %s ";
+ conn.createStatement().execute(generateDDL("UPDATE_CACHE_FREQUENCY=2", ddlFormat));
viewConn.createStatement().execute("CREATE VIEW " + viewOfTable1 + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 VARCHAR ) AS SELECT * FROM " + tableName);
viewConn.createStatement().execute("CREATE VIEW " + viewOfTable2 + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 VARCHAR ) AS SELECT * FROM " + tableName);
- viewConn.createStatement().execute("ALTER VIEW " + viewOfTable2 + " SET UPDATE_CACHE_FREQUENCY = 5");
+ viewConn.createStatement().execute("ALTER VIEW " + viewOfTable2 + " SET UPDATE_CACHE_FREQUENCY = 1");
PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
PTable table = phoenixConn.getTable(new PTableKey(null, tableName));
PName tenantId = isMultiTenant ? PNameFactory.newName("tenant1") : null;
assertFalse(table.isImmutableRows());
- assertEquals(15, table.getUpdateCacheFrequency());
+ assertEquals(2, table.getUpdateCacheFrequency());
PTable viewTable1 = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable1));
assertFalse(viewTable1.isImmutableRows());
- assertEquals(15, viewTable1.getUpdateCacheFrequency());
+ assertEquals(2, viewTable1.getUpdateCacheFrequency());
// query the view to force the table cache to be updated
viewConn.createStatement().execute("SELECT * FROM "+viewOfTable2);
PTable viewTable2 = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable2));
assertFalse(viewTable2.isImmutableRows());
- assertEquals(5, viewTable2.getUpdateCacheFrequency());
+ assertEquals(1, viewTable2.getUpdateCacheFrequency());
- conn.createStatement().execute("ALTER TABLE " + tableName + " SET IMMUTABLE_ROWS=true, UPDATE_CACHE_FREQUENCY=10");
+ conn.createStatement().execute("ALTER TABLE " + tableName + " SET IMMUTABLE_ROWS=true, UPDATE_CACHE_FREQUENCY=3");
// query the views to force the table cache to be updated
viewConn.createStatement().execute("SELECT * FROM "+viewOfTable1);
viewConn.createStatement().execute("SELECT * FROM "+viewOfTable2);
@@ -142,16 +156,16 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
phoenixConn = conn.unwrap(PhoenixConnection.class);
table = phoenixConn.getTable(new PTableKey(null, tableName));
assertTrue(table.isImmutableRows());
- assertEquals(10, table.getUpdateCacheFrequency());
+ assertEquals(3, table.getUpdateCacheFrequency());
viewTable1 = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable1));
assertTrue(viewTable1.isImmutableRows());
- assertEquals(10, viewTable1.getUpdateCacheFrequency());
+ assertEquals(3, viewTable1.getUpdateCacheFrequency());
viewTable2 = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable2));
assertTrue(viewTable2.isImmutableRows());
// update cache frequency is not propagated to the view since it was altered on the view
- assertEquals(5, viewTable2.getUpdateCacheFrequency());
+ assertEquals(1, viewTable2.getUpdateCacheFrequency());
}
}
@@ -178,7 +192,7 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
// drop two columns from the base table
conn.createStatement().execute("ALTER TABLE " + tableName + " DROP COLUMN COL3, COL5");
- assertTableDefinition(conn, tableName, PTableType.TABLE, null, 2, 4,
+ assertTableDefinition(conn, tableName, PTableType.TABLE, null, columnEncoded ? 2 : 1, 4,
QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "COL4");
assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 1, 6, 4,
"ID", "COL1", "COL2", "COL4", "VIEW_COL1", "VIEW_COL2");
@@ -222,80 +236,84 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
viewConn.commit();
try {
- // adding a key value column to the base table that already exists in the view is not allowed
- conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL4 DECIMAL, VIEW_COL2 VARCHAR(256)");
+ // should fail because there is already a view column with same name of different type
+ conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 char(10)");
fail();
- } catch (SQLException e) {
+ }
+ catch (SQLException e) {
assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+ }
+
+ try {
+ // should fail because there is already a view column with same name with different scale
+ conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 DECIMAL(10,1)");
+ fail();
+ }
+ catch (SQLException e) {
+ assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+ }
+
+ try {
+ // should fail because there is already a view column with same name with different length
+ conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 DECIMAL(9,2)");
+ fail();
+ }
+ catch (SQLException e) {
+ assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+ }
+
+ try {
+ // should fail because there is already a view column with different length
+ conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL2 VARCHAR");
+ fail();
+ }
+ catch (SQLException e) {
+ assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+ }
+
+ // validate that there were no columns added to the table or view, if its table is column encoded the sequence number changes when we increment the cq counter
+ assertTableDefinition(conn, tableName, PTableType.TABLE, null, columnEncoded ? 1 : 0, 3, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2");
+ assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 0, 9, 3, "ID", "COL1", "COL2", "VIEW_COL1", "VIEW_COL2", "VIEW_COL3", "VIEW_COL4", "VIEW_COL5", "VIEW_COL6");
+
+ if (columnEncoded) {
+ try {
+ // adding a key value column to the base table that already exists in the view is not allowed
+ conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL4 DECIMAL, VIEW_COL2 VARCHAR(256)");
+ fail();
+ } catch (SQLException e) {
+ assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+ }
+ }
+ else {
+ // should succeed
+ conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL4 DECIMAL, VIEW_COL2 VARCHAR(256)");
+ assertTableDefinition(conn, tableName, PTableType.TABLE, null, columnEncoded ? 2 : 1, 5, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "VIEW_COL4", "VIEW_COL2");
+ assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 1, 9, 5, "ID", "COL1", "COL2", "VIEW_COL4", "VIEW_COL2", "VIEW_COL1", "VIEW_COL3", "VIEW_COL5", "VIEW_COL6");
+
+ // query table
+ ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals("view1", rs.getString("ID"));
+ assertEquals(12, rs.getInt("COL1"));
+ assertEquals(13, rs.getInt("COL2"));
+ assertEquals("view5", rs.getString("VIEW_COL2"));
+ assertEquals(17, rs.getInt("VIEW_COL4"));
+ assertFalse(rs.next());
+
+ // query view
+ rs = stmt.executeQuery("SELECT * FROM " + viewOfTable);
+ assertTrue(rs.next());
+ assertEquals("view1", rs.getString("ID"));
+ assertEquals(12, rs.getInt("COL1"));
+ assertEquals(13, rs.getInt("COL2"));
+ assertEquals(14, rs.getInt("VIEW_COL1"));
+ assertEquals("view5", rs.getString("VIEW_COL2"));
+ assertEquals("view6", rs.getString("VIEW_COL3"));
+ assertEquals(17, rs.getInt("VIEW_COL4"));
+ assertEquals(18, rs.getInt("VIEW_COL5"));
+ assertEquals("view9", rs.getString("VIEW_COL6"));
+ assertFalse(rs.next());
}
-// try {
-// // should fail because there is already a view column with same name of different type
-// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 char(10)");
-// fail();
-// }
-// catch (SQLException e) {
-// assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
-// }
-//
-// try {
-// // should fail because there is already a view column with same name with different scale
-// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 DECIMAL(10,1)");
-// fail();
-// }
-// catch (SQLException e) {
-// assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
-// }
-//
-// try {
-// // should fail because there is already a view column with same name with different length
-// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 DECIMAL(9,2)");
-// fail();
-// }
-// catch (SQLException e) {
-// assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
-// }
-//
-// try {
-// // should fail because there is already a view column with different length
-// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL2 VARCHAR");
-// fail();
-// }
-// catch (SQLException e) {
-// assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
-// }
-//
-// // validate that there were no columns added to the table or view
-// assertTableDefinition(conn, tableName, PTableType.TABLE, null, 1, 3, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2");
-// assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 0, 9, 3, "ID", "COL1", "COL2", "VIEW_COL1", "VIEW_COL2", "VIEW_COL3", "VIEW_COL4", "VIEW_COL5", "VIEW_COL6");
-//
-// // should succeed
-// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL4 DECIMAL, VIEW_COL2 VARCHAR(256)");
-// assertTableDefinition(conn, tableName, PTableType.TABLE, null, 2, 5, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "VIEW_COL4", "VIEW_COL2");
-// assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 1, 9, 5, "ID", "COL1", "COL2", "VIEW_COL4", "VIEW_COL2", "VIEW_COL1", "VIEW_COL3", "VIEW_COL5", "VIEW_COL6");
-//
-// // query table
-// ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName);
-// assertTrue(rs.next());
-// assertEquals("view1", rs.getString("ID"));
-// assertEquals(12, rs.getInt("COL1"));
-// assertEquals(13, rs.getInt("COL2"));
-// assertEquals("view5", rs.getString("VIEW_COL2"));
-// assertEquals(17, rs.getInt("VIEW_COL4"));
-// assertFalse(rs.next());
-//
-// // query view
-// rs = stmt.executeQuery("SELECT * FROM " + viewOfTable);
-// assertTrue(rs.next());
-// assertEquals("view1", rs.getString("ID"));
-// assertEquals(12, rs.getInt("COL1"));
-// assertEquals(13, rs.getInt("COL2"));
-// assertEquals(14, rs.getInt("VIEW_COL1"));
-// assertEquals("view5", rs.getString("VIEW_COL2"));
-// assertEquals("view6", rs.getString("VIEW_COL3"));
-// assertEquals(17, rs.getInt("VIEW_COL4"));
-// assertEquals(18, rs.getInt("VIEW_COL5"));
-// assertEquals("view9", rs.getString("VIEW_COL6"));
-// assertFalse(rs.next());
}
}
@@ -614,9 +632,9 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
@Test
public void testAlteringViewThatHasChildViews() throws Exception {
- String baseTable = "testAlteringViewThatHasChildViews";
- String childView = "childView";
- String grandChildView = "grandChildView";
+ String baseTable = generateUniqueName();
+ String childView = baseTable + "cildView";
+ String grandChildView = baseTable + "grandChildView";
try (Connection conn = DriverManager.getConnection(getUrl());
Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn ) {
String ddlFormat = "CREATE TABLE IF NOT EXISTS " + baseTable + " ("
http://git-wip-us.apache.org/repos/asf/phoenix/blob/61d9035c/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedBytesPropIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedBytesPropIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedBytesPropIT.java
new file mode 100644
index 0000000..dd64428
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedBytesPropIT.java
@@ -0,0 +1,95 @@
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
+import org.apache.phoenix.schema.PTableKey;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.Test;
+
+public class ColumnEncodedBytesPropIT extends ParallelStatsDisabledIT {
+
+ private String generateColsDDL(int numCols) {
+ StringBuilder sb = new StringBuilder();
+ for (int i=0; i<numCols; ++i) {
+ if (i>0) {
+ sb.append(" , ");
+ }
+ sb.append("col_").append(i).append(" VARCHAR ");
+ }
+ return sb.toString();
+ }
+
+ @Test
+ public void testValidateProperty() throws SQLException {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String dataTableFullName1 = SchemaUtil.getTableName("", generateUniqueName());
+ String dataTableFullName2 = SchemaUtil.getTableName("", generateUniqueName());
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+ Statement stmt = conn.createStatement();
+ String ddl = "CREATE TABLE " + dataTableFullName1 +
+ " (id varchar not null, val varchar " +
+ " CONSTRAINT pk PRIMARY KEY (id)) COLUMN_ENCODED_BYTES=4";
+ stmt.execute(ddl);
+
+ ddl = "CREATE TABLE " + dataTableFullName2 +
+ " (id varchar not null, val varchar " +
+ " CONSTRAINT pk PRIMARY KEY (id)) COLUMN_ENCODED_BYTES=NONE";
+ stmt.execute(ddl);
+
+ PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
+ PTable dataTable1 = phxConn.getTable(new PTableKey(null, dataTableFullName1));
+ assertEquals("Encoding scheme set incorrectly", QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS, dataTable1.getEncodingScheme());
+
+ PTable dataTable2 = phxConn.getTable(new PTableKey(null, dataTableFullName2));
+ assertEquals("Encoding scheme set incorrectly", QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, dataTable2.getEncodingScheme());
+ }
+ }
+
+ @Test
+ public void testValidateMaxCols() throws SQLException {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String dataTableFullName = SchemaUtil.getTableName("", generateUniqueName());
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+ Statement stmt = conn.createStatement();
+ // create table with more cols than is supported by the encoding
+ try {
+ stmt.execute("CREATE TABLE " + dataTableFullName +
+ " (id varchar not null, " + generateColsDDL(QualifierEncodingScheme.ONE_BYTE_QUALIFIERS.getMaxQualifier()-QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE+2) +
+ " CONSTRAINT pk PRIMARY KEY (id)) COLUMN_ENCODED_BYTES=1");
+ fail();
+ }
+ catch (SQLException e) {
+ assertEquals(SQLExceptionCode.MAX_COLUMNS_EXCEEDED.getErrorCode(), e.getErrorCode());
+ }
+
+ // create table with number of cols equal to that supported by the encoding
+ stmt.execute("CREATE TABLE " + dataTableFullName +
+ " (id varchar not null, " + generateColsDDL(QualifierEncodingScheme.ONE_BYTE_QUALIFIERS.getMaxQualifier()-QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE+1) +
+ " CONSTRAINT pk PRIMARY KEY (id)) COLUMN_ENCODED_BYTES=1");
+
+ // add one more column
+ try {
+ stmt.execute("ALTER TABLE " + dataTableFullName + " ADD val_x VARCHAR");
+ fail();
+ }
+ catch (SQLException e) {
+ assertEquals(SQLExceptionCode.MAX_COLUMNS_EXCEEDED.getErrorCode(), e.getErrorCode());
+ }
+ }
+ }
+
+}