public static PTable getTableNoCache(Connection conn, String name) throws SQLException { String schemaName = SchemaUtil.getSchemaNameFromFullName(name); String tableName = SchemaUtil.getTableNameFromFullName(name); PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); MetaDataMutationResult result = new MetaDataClient(pconn).updateCache(pconn.getTenantId(), schemaName, tableName, true); if(result.getMutationCode() != MutationCode.TABLE_ALREADY_EXISTS) { throw new TableNotFoundException(schemaName, tableName); } return result.getTable(); }
@Override public MutationState execute() throws SQLException { MetaDataClient client = new MetaDataClient(getContext().getConnection()); return client.addColumn(ExecutableAddColumnStatement.this); } };
private PTable addTableToCache(MetaDataMutationResult result) throws SQLException { addIndexesFromParentTable(result, null, false); PTable table = result.getTable(); connection.addTable(table, TransactionUtil.getResolvedTime(connection, result)); return table; }
@Override public MutationState execute() throws SQLException { MetaDataClient client = new MetaDataClient(getContext().getConnection()); return client.dropIndex(ExecutableDropIndexStatement.this); } };
@Override public MutationState execute() throws SQLException { MetaDataClient client = new MetaDataClient(getContext().getConnection()); return client.dropColumn(ExecutableDropColumnStatement.this); } };
@Override public MutationState execute() throws SQLException { MetaDataClient client = new MetaDataClient(getContext().getConnection()); return client.alterIndex(ExecutableAlterIndexStatement.this); } };
while (true) { Map<String, List<Pair<String, Object>>> properties=new HashMap<>(stmtProperties.size());; metaProperties = loadStmtProperties(stmtProperties,properties,table,removeTableProps); changingPhoenixTableProperty = evaluateStmtProperties(metaProperties,metaPropertiesEvaluated,table,schemaName,tableName); throwIfLastPKOfParentIsVariableLength(getParentOfView(table), schemaName, tableName, colDef); PColumn column = newColumn(position++, colDef, PrimaryKeyConstraint.EMPTY, table.getDefaultFamilyName() == null ? null : table.getDefaultFamilyName().getString(), true, columnQualifierBytes, willBeImmutableRows); columns.add(column); String pkName = null; addColumnMutation(schemaName, tableName, column, colUpsert, null, pkName, keySeq, table.getBucketNum() != null); Expression expression = new RowKeyColumnExpression(columns.get(i), new RowKeyValueAccessor(pkColumns, pkSlotPosition)); ColumnDef indexColDef = FACTORY.columnDef(indexColName, indexColDataType.getSqlTypeName(), colDef.isNull(), colDef.getMaxLength(), colDef.getScale(), true, colDef.getSortOrder(), expression.toString(), colDef.isRowTimestamp()); PColumn indexColumn = newColumn(indexPosition++, indexColDef, PrimaryKeyConstraint.EMPTY, null, true, null, willBeImmutableRows); addColumnMutation(schemaName, index.getTableName().getString(), indexColumn, colUpsert, index.getParentTableName().getString(), index.getPKName() == null ? null : index.getPKName().getString(), ++nextIndexKeySeq, index.getBucketNum() != null); throwIfInsufficientColumns(schemaName, tableName, table.getPKColumns(), table.getBucketNum()!=null, metaPropertiesEvaluated.getMultiTenant()); metaPropertiesEvaluated.getUpdateCacheFrequency() != null)) { for (PTable index : table.getIndexes()) { incrementTableSeqNum(index, index.getType(), numPkColumnsAdded, metaProperties.getNonTxToTx() ? Boolean.TRUE : null, metaPropertiesEvaluated.getUpdateCacheFrequency()); incrementTableSeqNum(table, tableType, columnDefs.size(), metaPropertiesEvaluated);
boolean wasPKDefined = false; for (ColumnDef colDef : colDefs) { rowTimeStampColumnAlreadyFound = checkAndValidateRowTimestampCol(colDef, pkConstraint, rowTimeStampColumnAlreadyFound, tableType); if (colDef.isPK()) { // i.e. the column is declared as CREATE TABLE COLNAME DATATYPE PRIMARY KEY... if (wasPKDefined) { ( wasPKDefined || !isPkColumn(pkConstraint, colDef))) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.KEY_VALUE_NOT_NULL) .setSchemaName(schemaName) boolean isPkColumn = isPkColumn(pkConstraint, colDef); String cqCounterFamily = null; if (!isPkColumn) { PColumn column = newColumn(position++, colDef, pkConstraint, defaultFamilyName, false, columnQualifierBytes, isImmutableRows); if (!isAppendOnlySchema && cqCounter.increment(cqCounterFamily)) { changedCqCounters.put(cqCounterFamily, cqCounter.getNextQualifier(cqCounterFamily)); throwIfLastPKOfParentIsVariableLength(parent, schemaName, tableName, colDef); while (pkColumnNamesIterator.hasNext()) { ColumnName colName = pkColumnNamesIterator.next().getFirst(); ColumnDef colDef = findColumnDefOrNull(colDefs, colName); if (colDef == null) { throw new ColumnNotFoundException(schemaName, tableName, null, colName.getColumnName()); throwIfInsufficientColumns(schemaName, tableName, pkColumns, saltBucketNum!=null, multiTenant); populateFamilyPropsList(familyNames, commonFamilyProps, statement, defaultFamilyName, isLocalIndex, familyPropList);
MetaProperties metaProperties = loadStmtProperties(statement.getProps(),properties,table,false); boolean changingPhoenixTableProperty= evaluateStmtProperties(metaProperties,metaPropertiesEvaluated,table,schemaName,tableName); incrementTableSeqNum(table,statement.getTableType(), 0, metaPropertiesEvaluated); tableMetadata.addAll(connection.getMutationState().toMutations(timeStamp).next().getSecond()); connection.rollback(); addTableToCache(result); return buildIndexAtTimeStamp(index, dataTableNode); return buildIndex(index, dataTableRef);
while (true) { Map<String, List<Pair<String, Object>>> properties=new HashMap<>(stmtProperties.size());; metaProperties = loadStmtProperties(stmtProperties,properties,table,removeTableProps); changingPhoenixTableProperty = evaluateStmtProperties(metaProperties,metaPropertiesEvaluated,table,schemaName,tableName); throwIfLastPKOfParentIsFixedLength(getParentOfView(table), schemaName, tableName, colDef); PColumn column = newColumn(position++, colDef, PrimaryKeyConstraint.EMPTY, table.getDefaultFamilyName() == null ? null : table.getDefaultFamilyName().getString(), true, columnQualifierBytes, willBeImmutableRows); columns.add(column); String pkName = null; addColumnMutation(schemaName, tableName, column, colUpsert, null, pkName, keySeq, table.getBucketNum() != null); Expression expression = new RowKeyColumnExpression(columns.get(i), new RowKeyValueAccessor(pkColumns, pkSlotPosition)); ColumnDef indexColDef = FACTORY.columnDef(indexColName, indexColDataType.getSqlTypeName(), colDef.isNull(), colDef.getMaxLength(), colDef.getScale(), true, colDef.getSortOrder(), expression.toString(), colDef.isRowTimestamp()); PColumn indexColumn = newColumn(indexPosition++, indexColDef, PrimaryKeyConstraint.EMPTY, null, true, null, willBeImmutableRows); addColumnMutation(schemaName, index.getTableName().getString(), indexColumn, colUpsert, index.getParentTableName().getString(), index.getPKName() == null ? null : index.getPKName().getString(), ++nextIndexKeySeq, index.getBucketNum() != null); throwIfInsufficientColumns(schemaName, tableName, table.getPKColumns(), table.getBucketNum()!=null, metaPropertiesEvaluated.getMultiTenant()); incrementTableSeqNum(index, index.getType(), numPkColumnsAdded, metaProperties.getNonTxToTx() ? Boolean.TRUE : null, metaPropertiesEvaluated.getUpdateCacheFrequency()); incrementTableSeqNum(table, tableType, columnDefs.size(), metaPropertiesEvaluated); MutationCode code = processMutationResult(schemaName, tableName, result); if (code == MutationCode.COLUMN_ALREADY_EXISTS) { addTableToCache(result); if (!ifNotExists) {
/** * Update the cache with the latest as of the connection scn. * @param schemaName * @param tableName * @return the timestamp from the server, negative if the table was added to the cache and positive otherwise * @throws SQLException */ public MetaDataMutationResult updateCache(String schemaName, String tableName) throws SQLException { return updateCache(schemaName, tableName, false); }
Map<String,Object> tableProps = Maps.newHashMapWithExpectedSize(statement.getProps().size()); Map<String,Object> commonFamilyProps = Maps.newHashMapWithExpectedSize(statement.getProps().size() + 1); populatePropertyMaps(statement.getProps(), tableProps, commonFamilyProps, statement.getTableType()); MetaDataMutationResult result = updateCache(tableName.getSchemaName(), tableName.getTableName()); if (result.getMutationCode()==MutationCode.TABLE_ALREADY_EXISTS) { table = result.getTable(); return addColumn(table, columnDefs, statement.getProps(), statement.ifNotExists(), true, NamedTableNode.create(statement.getTableName()), statement.getTableType()); table = createTableInternal(statement, splits, parent, viewStatement, viewType, viewIndexIdType, viewColumnConstants, isViewColumnReferenced, false, null, null, tableProps, commonFamilyProps);
dropColumnMutations(table, tableColumnsToDrop); boolean removedIndexTableOrColumn=false; Long timeStamp = table.isTransactional() ? tableRef.getTimeStamp() : null; long indexTableSeqNum = incrementTableSeqNum(index, index.getType(), -indexColumnsToDrop.size(), null, null); dropColumnMutations(index, indexColumnsToDrop); long clientTimestamp = MutationState.getTableTimestamp(timeStamp, connection.getSCN()); connection.removeColumn(tenantId, index.getName().getString(), long seqNum = incrementTableSeqNum(table, statement.getTableType(), -tableColumnsToDrop.size(), null, null); tableMetaData.addAll(connection.getMutationState().toMutations(timeStamp).next().getSecond()); connection.rollback(); byte[] emptyCF = getNewEmptyColumnFamilyOrNull(tableContainingColumnToDrop, columnRefToDrop.getColumn()); if (emptyCF != null) { try { MutationCode code = processMutationResult(schemaName, tableName, result); if (code == MutationCode.COLUMN_NOT_FOUND) { addTableToCache(result); if (!statement.ifExists()) { throw new ColumnNotFoundException(schemaName, tableName, Bytes.toString(result.getFamilyName()), Bytes.toString(result.getColumnName())); MutationPlan plan = compiler.compile( Collections.singletonList(droppedColumnTableRef), getNewEmptyColumnFamilyOrNull(droppedColumnTableRef.getTable(), droppedColumn), null, Collections.singletonList(droppedColumn),
boolean wasPKDefined = false; for (ColumnDef colDef : colDefs) { rowTimeStampColumnAlreadyFound = checkAndValidateRowTimestampCol(colDef, pkConstraint, rowTimeStampColumnAlreadyFound, tableType); if (colDef.isPK()) { // i.e. the column is declared as CREATE TABLE COLNAME DATATYPE PRIMARY KEY... if (wasPKDefined) { ( wasPKDefined || !isPkColumn(pkConstraint, colDef))) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.KEY_VALUE_NOT_NULL) .setSchemaName(schemaName) boolean isPkColumn = isPkColumn(pkConstraint, colDef); String cqCounterFamily = null; if (!isPkColumn) { PColumn column = newColumn(position++, colDef, pkConstraint, defaultFamilyName, false, columnQualifierBytes, isImmutableRows); if (!isAppendOnlySchema && cqCounter.increment(cqCounterFamily)) { changedCqCounters.put(cqCounterFamily, cqCounter.getNextQualifier(cqCounterFamily)); throwIfLastPKOfParentIsFixedLength(parent, schemaName, tableName, colDef); while (pkColumnNamesIterator.hasNext()) { ColumnName colName = pkColumnNamesIterator.next().getFirst(); ColumnDef colDef = findColumnDefOrNull(colDefs, colName); if (colDef == null) { throw new ColumnNotFoundException(schemaName, tableName, null, colName.getColumnName()); throwIfInsufficientColumns(schemaName, tableName, pkColumns, saltBucketNum!=null, multiTenant); addColumnMutation(schemaName, tableName, column, colUpsert, parentTableName, pkName, keySeq, saltBucketNum != null);
private BaseColumnResolver(PhoenixConnection connection, int tsAddition, TableName mutatingTableName) { this.connection = connection; this.client = connection == null ? null : new MetaDataClient(connection); this.tsAddition = tsAddition; functionMap = new HashMap<String, PFunction>(1); this.functions = Collections.<PFunction>emptyList(); this.mutatingTableName = mutatingTableName; }
updateCache(origTenantId, SchemaUtil.getSchemaNameFromFullName(parentViewName), SchemaUtil.getTableNameFromFullName(parentViewName), alwaysHitServer, resolvedTimestamp); addTableToCache(result); return result; } else { if (addIndexesFromParentTable(result, resolvedTimestamp, true)) { connection.addTable(result.getTable(), resolvedTime); } else {
@Override public MutationState execute() throws SQLException { MetaDataClient client = new MetaDataClient(getContext().getConnection()); return client.dropTable(ExecutableDropTableStatement.this); } };
@Override public MutationState execute() throws SQLException { MetaDataClient client = new MetaDataClient(getContext().getConnection()); return client.dropSchema(ExecutableDropSchemaStatement.this); } };
@Override public MutationState execute() throws SQLException { MetaDataClient client = new MetaDataClient(getContext().getConnection()); return client.changePermissions(ExecutableChangePermsStatement.this); } };
@Override public MutationState execute() throws SQLException { MetaDataClient client = new MetaDataClient(getContext().getConnection()); return client.updateStatistics(ExecutableUpdateStatisticsStatement.this); } };