Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -301,6 +301,22 @@ public void testSetSaltedTableAsImmutable() throws Exception {
}
}

@Test
public void testSetPropertySchemaVersion() throws Exception {
Properties props = new Properties();
final String schemaName = generateUniqueName();
final String tableName = generateUniqueName();
final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName);
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
CreateTableIT.testCreateTableSchemaVersionHelper(conn, schemaName, tableName, "V1.0");
String version = "V1.1";
String alterSql = "ALTER TABLE " + dataTableFullName + " SET SCHEMA_VERSION='" + version + "'";
conn.createStatement().execute(alterSql);
PTable table = PhoenixRuntime.getTableNoCache(conn, dataTableFullName);
assertEquals(version, table.getSchemaVersion());
}
}


@Test
public void testDropColumnFromSaltedTable() throws Exception {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1465,6 +1465,30 @@ public void testLastDDLTimestampWithChildViews() throws Exception {

}


@Test
public void testCreateViewSchemaVersion() throws Exception {
Properties props = new Properties();
final String schemaName = generateUniqueName();
final String tableName = generateUniqueName();
final String viewName = generateUniqueName();
final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName);
final String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
String oldVersion = "V1.0";
CreateTableIT.testCreateTableSchemaVersionHelper(conn, schemaName, tableName, oldVersion);
String createViewSql = "CREATE VIEW " + viewFullName + " AS SELECT * FROM " + dataTableFullName +
" SCHEMA_VERSION='" + oldVersion + "'";
conn.createStatement().execute(createViewSql);
PTable view = PhoenixRuntime.getTableNoCache(conn, viewFullName);
assertEquals(oldVersion, view.getSchemaVersion());
String newVersion = "V1.1";
String alterViewSql = "ALTER VIEW " + viewFullName + " SET SCHEMA_VERSION='" + newVersion + "'";
conn.createStatement().execute(alterViewSql);
PTable view2 = PhoenixRuntime.getTableNoCache(conn, viewFullName);
assertEquals(newVersion, view2.getSchemaVersion());
PTable baseTable = PhoenixRuntime.getTableNoCache(conn, dataTableFullName);
assertEquals(oldVersion, baseTable.getSchemaVersion());
}
}

}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1167,6 +1167,31 @@ public void testTableDescriptorPriority() throws SQLException, IOException {
}
}

@Test
public void testCreateTableSchemaVersion() throws Exception {
Properties props = new Properties();
final String schemaName = generateUniqueName();
final String tableName = generateUniqueName();
final String version = "V1.0";
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
testCreateTableSchemaVersionHelper(conn, schemaName, tableName, version);
}
}

public static void testCreateTableSchemaVersionHelper(Connection conn, String schemaName, String tableName,
String dataTableVersion)
throws Exception {
final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName);
String ddl =
"CREATE TABLE " + dataTableFullName + " (\n" + "ID1 VARCHAR(15) NOT NULL,\n"
+ "ID2 VARCHAR(15) NOT NULL,\n" + "CREATED_DATE DATE,\n"
+ "CREATION_TIME BIGINT,\n" + "LAST_USED DATE,\n"
+ "CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SCHEMA_VERSION='" + dataTableVersion + "'";
conn.createStatement().execute(ddl);
PTable table = PhoenixRuntime.getTableNoCache(conn, dataTableFullName);
assertEquals(dataTableVersion, table.getSchemaVersion());
}

@Test
public void testCreateTableDDLTimestamp() throws Exception {
Properties props = new Properties();
Expand Down
19 changes: 19 additions & 0 deletions phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -324,6 +324,25 @@ public void testViewUsesTableLocalIndex() throws Exception {
}
}

@Test
public void testCreateViewSchemaVersion() throws Exception {
Properties props = new Properties();
final String schemaName = generateUniqueName();
final String tableName = generateUniqueName();
final String viewName = generateUniqueName();
final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName);
final String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
String version = "V1.0";
CreateTableIT.testCreateTableSchemaVersionHelper(conn, schemaName, tableName, version);
String createViewSql = "CREATE VIEW " + viewFullName + " AS SELECT * FROM " + dataTableFullName +
" SCHEMA_VERSION='" + version + "'";
conn.createStatement().execute(createViewSql);
PTable view = PhoenixRuntime.getTableNoCache(conn, viewFullName);
assertEquals(version, view.getSchemaVersion());
}
}

@Test
public void testCreateViewTimestamp() throws Exception {
String tenantId = null;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,15 @@
import java.util.Properties;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.phoenix.end2end.CreateTableIT;
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.util.IndexScrutiny;
import org.apache.phoenix.util.PhoenixRuntime;
Expand DownExpand Up@@ -736,8 +741,8 @@ private void testUpsertingDeletedRowShouldGiveProperDataWithIndexes(boolean mult
assertEquals(1, rs.getInt(2));
assertEquals(0.5F, rs.getFloat(1), 0.0);
assertEquals("foo", rs.getString(3));
}
}
}
}

@Test
public void testUpsertingDeletedRowWithNullCoveredColumn() throws Exception {
Expand DownExpand Up@@ -916,6 +921,25 @@ public void testDeleteCount_index() throws Exception {
}
}

@Test
public void testCreateIndexSchemaVersion() throws Exception {
Properties props = new Properties();
final String schemaName = generateUniqueName();
final String tableName = generateUniqueName();
final String indexName = generateUniqueName();
final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName);
final String indexFullName = SchemaUtil.getTableName(schemaName, indexName);
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
String version = "V1.0";
CreateTableIT.testCreateTableSchemaVersionHelper(conn, schemaName, tableName, version);
String createIndexSql = "CREATE INDEX " + indexName + " ON " + dataTableFullName +
" (ID2) INCLUDE (ID1) SCHEMA_VERSION='" + version + "'";
conn.createStatement().execute(createIndexSql);
PTable index = PhoenixRuntime.getTableNoCache(conn, indexFullName);
assertEquals(version, index.getSchemaVersion());
}
}

private void upsertRow(String dml, Connection tenantConn, int i) throws SQLException {
PreparedStatement stmt = tenantConn.prepareStatement(dml);
stmt.setString(1, "00000000000000" + String.valueOf(i));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,7 @@
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.compile.QueryPlan;
import org.apache.phoenix.end2end.CreateTableIT;
import org.apache.phoenix.end2end.IndexToolIT;
import org.apache.phoenix.end2end.SplitSystemCatalogIT;
import org.apache.phoenix.hbase.index.IndexRegionObserver;
Expand DownExpand Up@@ -805,6 +806,30 @@ public void testIndexIdDataTypeDefaultValue() throws Exception {
}
}

@Test
public void testCreateViewSchemaVersion() throws Exception {
Properties props = new Properties();
final String schemaName = generateUniqueName();
final String tableName = generateUniqueName();
final String viewName = generateUniqueName();
final String viewIndexName = generateUniqueName();
final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName);
final String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
final String viewIndexFullName = SchemaUtil.getTableName(schemaName, viewIndexName);
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
String version = "V1.0";
CreateTableIT.testCreateTableSchemaVersionHelper(conn, schemaName, tableName, version);
String createViewSql = "CREATE VIEW " + viewFullName + " AS SELECT * FROM " + dataTableFullName +
" SCHEMA_VERSION='" + version + "'";
conn.createStatement().execute(createViewSql);
String createViewIndexSql = "CREATE INDEX " + viewIndexName + " ON "
+ viewFullName + " (ID2) INCLUDE (ID1) SCHEMA_VERSION='" + version + "'";
conn.createStatement().execute(createViewIndexSql);
PTable viewIndex = PhoenixRuntime.getTableNoCache(conn, viewIndexFullName);
assertEquals(version, viewIndex.getSchemaVersion());
}
}

public void createBaseTable(Connection conn, String schemaName, String tableName,
boolean multiTenant,
Integer saltBuckets, String splits, boolean immutable)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,16 +49,20 @@
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LAST_DDL_TIMESTAMP_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LINK_TYPE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MAX_VALUE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MIN_VALUE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MIN_PHOENIX_TTL_HWM;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MIN_VALUE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MULTI_TENANT_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.NULLABLE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.NUM_ARGS_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ORDINAL_POSITION_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHOENIX_TTL_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHOENIX_TTL_HWM_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHOENIX_TTL_NOT_DEFINED;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHYSICAL_TABLE_NAME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PK_NAME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.RETURN_TYPE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SALT_BUCKETS_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCHEMA_VERSION_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SORT_ORDER_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.STORAGE_SCHEME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.STORE_NULLS_BYTES;
Expand All@@ -75,9 +79,6 @@
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHOENIX_TTL_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHOENIX_TTL_HWM_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHOENIX_TTL_NOT_DEFINED;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE_BYTES;
import static org.apache.phoenix.query.QueryConstants.VIEW_MODIFIED_PROPERTY_TAG_TYPE;
import static org.apache.phoenix.schema.PTableType.INDEX;
Expand DownExpand Up@@ -348,6 +349,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements RegionCopr
private static final Cell CHANGE_DETECTION_ENABLED_KV =
createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES,
CHANGE_DETECTION_ENABLED_BYTES);
private static final Cell SCHEMA_VERSION_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY,
TABLE_FAMILY_BYTES, SCHEMA_VERSION_BYTES);

private static final List<Cell> TABLE_KV_COLUMNS = Lists.newArrayList(
EMPTY_KEYVALUE_KV,
Expand DownExpand Up@@ -384,7 +387,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements RegionCopr
PHOENIX_TTL_KV,
PHOENIX_TTL_HWM_KV,
LAST_DDL_TIMESTAMP_KV,
CHANGE_DETECTION_ENABLED_KV
CHANGE_DETECTION_ENABLED_KV,
SCHEMA_VERSION_KV
);

static {
Expand DownExpand Up@@ -427,6 +431,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements RegionCopr
TABLE_KV_COLUMNS.indexOf(LAST_DDL_TIMESTAMP_KV);
private static final int CHANGE_DETECTION_ENABLED_INDEX =
TABLE_KV_COLUMNS.indexOf(CHANGE_DETECTION_ENABLED_KV);
private static final int SCHEMA_VERSION_INDEX = TABLE_KV_COLUMNS.indexOf(SCHEMA_VERSION_KV);
// KeyValues for Column
private static final KeyValue DECIMAL_DIGITS_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, DECIMAL_DIGITS_BYTES);
private static final KeyValue COLUMN_SIZE_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, COLUMN_SIZE_BYTES);
Expand DownExpand Up@@ -1227,6 +1232,11 @@ private PTable getTable(RegionScanner scanner, long clientTimeStamp, long tableT
changeDetectionEnabledKv.getValueOffset(),
changeDetectionEnabledKv.getValueLength()));

Cell schemaVersionKv = tableKeyValues[SCHEMA_VERSION_INDEX];
String schemaVersion = schemaVersionKv != null ? (String) PVarchar.INSTANCE.toObject(
schemaVersionKv.getValueArray(), schemaVersionKv.getValueOffset(), schemaVersionKv.getValueLength())
: null;

// Check the cell tag to see whether the view has modified this property
final byte[] tagUseStatsForParallelization = (useStatsForParallelizationKv == null) ?
HConstants.EMPTY_BYTE_ARRAY :
Expand DownExpand Up@@ -1359,6 +1369,7 @@ private PTable getTable(RegionScanner scanner, long clientTimeStamp, long tableT
.setViewModifiedPhoenixTTL(viewModifiedPhoenixTTL)
.setLastDDLTimestamp(lastDDLTimestamp)
.setIsChangeDetectionEnabled(isChangeDetectionEnabled)
.setSchemaVersion(schemaVersion)
.setColumns(columns)
.build();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,7 +100,7 @@ public abstract class MetaDataProtocol extends MetaDataService {
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_15_0 = MIN_TABLE_TIMESTAMP + 29;
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_16_0 = MIN_TABLE_TIMESTAMP + 33;
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_5_1_0 = MIN_SYSTEM_TABLE_TIMESTAMP_4_16_0;
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0 = MIN_TABLE_TIMESTAMP + 34;
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0 = MIN_TABLE_TIMESTAMP + 35;
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_5_2_0 = MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0;
// MIN_SYSTEM_TABLE_TIMESTAMP needs to be set to the max of all the MIN_SYSTEM_TABLE_TIMESTAMP_* constants
public static final long MIN_SYSTEM_TABLE_TIMESTAMP = MIN_SYSTEM_TABLE_TIMESTAMP_5_2_0;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -393,6 +393,9 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
public static final byte[] CHANGE_DETECTION_ENABLED_BYTES =
Bytes.toBytes(CHANGE_DETECTION_ENABLED);

public static final String SCHEMA_VERSION = "SCHEMA_VERSION";
public static final byte[] SCHEMA_VERSION_BYTES = Bytes.toBytes(SCHEMA_VERSION);

public static final String SYSTEM_CHILD_LINK_TABLE = "CHILD_LINK";
public static final String SYSTEM_CHILD_LINK_NAME = SchemaUtil.getTableName(SYSTEM_CATALOG_SCHEMA, SYSTEM_CHILD_LINK_TABLE);
public static final byte[] SYSTEM_CHILD_LINK_NAME_BYTES = Bytes.toBytes(SYSTEM_CHILD_LINK_NAME);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -2321,7 +2321,7 @@ public MetaDataMutationResult addColumn(final List<Mutation> tableMetaData,
// In this, case we only include the table header row, as until we add schemaBytes and tableBytes
// as args to this function, we have no way of getting them in this case.
// TODO: change to if (tableMetaData.isEmpty()) once we pass through schemaBytes and tableBytes
// Also, could be used to update property values on ALTER TABLE t SET prop=xxx
// Also, could be used to update table descriptor property values on ALTER TABLE t SET prop=xxx
if ((tableMetaData.isEmpty()) || (tableMetaData.size() == 1 && tableMetaData.get(0).isEmpty())) {
if (modifyHTable) {
sendHBaseMetaData(tableDescriptors, pollingNeeded);
Expand DownExpand Up@@ -3859,9 +3859,13 @@ protected PhoenixConnection upgradeSystemCatalogIfRequired(PhoenixConnection met
}
if (currentServerSideTableTimeStamp < MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0) {
metaConnection = addColumnsIfNotExists(metaConnection,
PhoenixDatabaseMetaData.SYSTEM_CATALOG, MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0,
PhoenixDatabaseMetaData.SYSTEM_CATALOG, MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0 -1,
PhoenixDatabaseMetaData.PHYSICAL_TABLE_NAME
+ " " + PVarchar.INSTANCE.getSqlTypeName());

metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0,
PhoenixDatabaseMetaData.SCHEMA_VERSION + " " + PVarchar.INSTANCE.getSqlTypeName());
}
return metaConnection;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -113,6 +113,7 @@
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.RETURN_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SALT_BUCKETS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCAN_METRICS_JSON;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCHEMA_VERSION;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCOPE_CATALOG;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCOPE_SCHEMA;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCOPE_TABLE;
Expand DownExpand Up@@ -312,8 +313,9 @@ enum JoinType {INNER, LEFT_OUTER}
VIEW_INDEX_ID_DATA_TYPE + " INTEGER,\n" +
PHOENIX_TTL + " BIGINT,\n" +
PHOENIX_TTL_HWM + " BIGINT,\n" +
LAST_DDL_TIMESTAMP + " BIGINT, " +
CHANGE_DETECTION_ENABLED + " BOOLEAN, " +
LAST_DDL_TIMESTAMP + " BIGINT, \n" +
CHANGE_DETECTION_ENABLED + " BOOLEAN, \n" +
SCHEMA_VERSION + " VARCHAR, \n" +
// Column metadata (will be null for table row)
DATA_TYPE + " INTEGER," +
COLUMN_SIZE + " INTEGER," +
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -370,6 +370,11 @@ public boolean isChangeDetectionEnabled() {
return delegate.isChangeDetectionEnabled();
}

@Override
public String getSchemaVersion() {
return delegate.getSchemaVersion();
}

@Override public Map<String, String> getPropertyValues() { return delegate.getPropertyValues(); }

@Override public Map<String, String> getDefaultPropertyValues() { return delegate.getDefaultPropertyValues(); }
Expand Down
Loading