private static ColumnDef findColumnDefOrNull(List<ColumnDef> colDefs, ColumnName colName) { for (ColumnDef colDef : colDefs) { if (colDef.getColumnDefName().getColumnName().equals(colName.getColumnName())) { return colDef; } } return null; }
private static boolean isPkColumn(PrimaryKeyConstraint pkConstraint, ColumnDef colDef) { return colDef.isPK() || (pkConstraint != null && pkConstraint.contains(colDef.getColumnDefName())); }
state._fsp--; if (state.failed) return ret; if ( state.backtracking==0 ) { if (d.getDataType()!=null) { ret.getFirst().add(d); } ret.getSecond().add(d.getColumnDefName()); } state._fsp--; if (state.failed) return ret; if ( state.backtracking==0 ) { if (d.getDataType()!=null) { ret.getFirst().add(d); } ret.getSecond().add(d.getColumnDefName()); }
protected PTable addDynamicColumns(List<ColumnDef> dynColumns, PTable theTable) throws SQLException { if (!dynColumns.isEmpty()) { List<PColumn> allcolumns = new ArrayList<PColumn>(); List<PColumn> existingColumns = theTable.getColumns(); // Need to skip the salting column, as it's handled in the PTable builder call below allcolumns.addAll(theTable.getBucketNum() == null ? existingColumns : existingColumns.subList(1, existingColumns.size())); // Position still based on with the salting columns int position = existingColumns.size(); PName defaultFamilyName = PNameFactory.newName(SchemaUtil.getEmptyColumnFamily(theTable)); for (ColumnDef dynColumn : dynColumns) { PName familyName = defaultFamilyName; PName name = PNameFactory.newName(dynColumn.getColumnDefName().getColumnName()); String family = dynColumn.getColumnDefName().getFamilyName(); if (family != null) { theTable.getColumnFamily(family); // Verifies that column family exists familyName = PNameFactory.newName(family); } allcolumns.add(new PColumnImpl(name, familyName, dynColumn.getDataType(), dynColumn.getMaxLength(), dynColumn.getScale(), dynColumn.isNull(), position, dynColumn.getSortOrder(), dynColumn.getArraySize(), null, false, dynColumn.getExpression(), false, true, Bytes.toBytes(dynColumn.getColumnDefName().getColumnName()), HConstants.LATEST_TIMESTAMP)); position++; } theTable = PTableImpl.builderWithColumns(theTable, allcolumns) .build(); } return theTable; }
private void throwIfLastPKOfParentIsVariableLength(PTable parent, String viewSchemaName, String viewName, ColumnDef col) throws SQLException { // if the last pk column is variable length then we read all the // bytes of the rowkey without looking for a separator byte see // https://issues.apache.org/jira/browse/PHOENIX-978?focusedCommentId=14617847&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14617847 // so we cannot add a pk column to a view if the last pk column of the parent is variable length if (isLastPKVariableLength(parent)) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_MODIFY_VIEW_PK) .setSchemaName(viewSchemaName) .setTableName(viewName) .setColumnName(col.getColumnDefName().getColumnName()) .build().buildException(); } }
List<PColumnFamily> families = Lists.newArrayListWithExpectedSize(table.getDynamicColumns().size()); for (ColumnDef def : table.getDynamicColumns()) { if (def.getColumnDefName().getFamilyName() != null) { families.add(new PColumnFamilyImpl(PNameFactory.newName(def.getColumnDefName().getFamilyName()),Collections.<PColumn>emptyList()));//, NON_ENCODED_QUALIFIERS));
for (int i = 0; i < columnDefs.size(); i++) { ColumnDef columnDef = columnDefs.get(i); if(columnDef.getColumnDefName().getFamilyName()!=null && columnDef.getColumnDefName().getFamilyName().contains(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNALLOWED_COLUMN_FAMILY) .build().buildException();
private PColumn newColumn(int position, ColumnDef def, PrimaryKeyConstraint pkConstraint, String defaultColumnFamily, boolean addingToPK, byte[] columnQualifierBytes, boolean isImmutableRows) throws SQLException { try { ColumnName columnDefName = def.getColumnDefName(); SortOrder sortOrder = def.getSortOrder(); boolean isPK = def.isPK(); if (def.getColumnDefName().getFamilyName() != null) { String family = def.getColumnDefName().getFamilyName(); if (isPK) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_WITH_FAMILY_NAME)
|| defaultExpression.getDeterminism() != Determinism.ALWAYS) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_DEFAULT) .setColumnName(this.getColumnDefName().getColumnName()).build() .buildException(); if (this.isRowTimestamp() || ( pkConstraint != null && pkConstraint.isColumnRowTimestamp(this.getColumnDefName()))) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.CANNOT_CREATE_DEFAULT_ROWTIMESTAMP) .setColumnName(this.getColumnDefName().getColumnName()) .build().buildException(); if (e.getCause() instanceof SQLException) { SQLException sqlE = (SQLException) e.getCause(); throw new DelegateSQLException(sqlE, ". DEFAULT " + SQLExceptionInfo.COLUMN_NAME + "=" + this.getColumnDefName().getColumnName()); defaultValue.getScale(), this.getMaxLength(), this.getScale())) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY).setColumnName(this.getColumnDefName().getColumnName()) .setMessage("DEFAULT " + this.getExpression()).build() .buildException();
String familyName = columnDef.getColumnDefName().getFamilyName(); String columnName = columnDef.getColumnDefName().getColumnName(); if (familyName!=null) { try { if(colDef.isPK()) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.NOT_NULLABLE_COLUMN_IN_ROW_KEY) .setColumnName(colDef.getColumnDefName().getColumnName()).build().buildException(); } else if (!willBeImmutableRows) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.KEY_VALUE_NOT_NULL) .setColumnName(colDef.getColumnDefName().getColumnName()).build().buildException(); .setColumnName(colDef.getColumnDefName().getColumnName()).build().buildException(); String colDefFamily = colDef.getColumnDefName().getFamilyName(); String familyName = null; ImmutableStorageScheme storageScheme = table.getImmutableStorageScheme(); columnQualifierBytes = EncodedColumnsUtil.getColumnQualifierBytes(colDef.getColumnDefName().getColumnName(), encodedCQ, table, colDef.isPK()); if (colDef.isPK()) { PDataType indexColDataType = IndexUtil.getIndexColumnDataType(colDef.isNull(), colDef.getDataType()); ColumnName indexColName = ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(null, colDef.getColumnDefName().getColumnName())); 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());
if (wasPKDefined) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_ALREADY_EXISTS) .setColumnName(colDef.getColumnDefName().getColumnName()).build().buildException(); .setSchemaName(schemaName) .setTableName(tableName) .setColumnName(colDef.getColumnDefName().getColumnName()).build().buildException(); ColumnName columnDefName = colDef.getColumnDefName(); String colDefFamily = columnDefName.getFamilyName(); boolean isPkColumn = isPkColumn(pkConstraint, colDef); throw new ColumnNotFoundException(schemaName, tableName, null, colName.getColumnName()); if (colDef.getColumnDefName().getFamilyName() != null) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_WITH_FAMILY_NAME) .setSchemaName(schemaName) .setTableName(tableName) .setColumnName(colDef.getColumnDefName().getColumnName() ) .setFamilyName(colDef.getColumnDefName().getFamilyName()) .build().buildException();
private static ColumnDef findColumnDefOrNull(List<ColumnDef> colDefs, ColumnName colName) { for (ColumnDef colDef : colDefs) { if (colDef.getColumnDefName().getColumnName().equals(colName.getColumnName())) { return colDef; } } return null; }
private static ColumnDef findColumnDefOrNull(List<ColumnDef> colDefs, ColumnName colName) { for (ColumnDef colDef : colDefs) { if (colDef.getColumnDefName().getColumnName().equals(colName.getColumnName())) { return colDef; } } return null; }
private static boolean isPkColumn(PrimaryKeyConstraint pkConstraint, ColumnDef colDef) { return colDef.isPK() || (pkConstraint != null && pkConstraint.contains(colDef.getColumnDefName())); }
private static boolean isPkColumn(PrimaryKeyConstraint pkConstraint, ColumnDef colDef) { return colDef.isPK() || (pkConstraint != null && pkConstraint.contains(colDef.getColumnDefName())); }
private static boolean checkAndValidateRowTimestampCol(ColumnDef colDef, PrimaryKeyConstraint pkConstraint, boolean rowTimeStampColAlreadyFound, PTableType tableType) throws SQLException { ColumnName columnDefName = colDef.getColumnDefName(); if (tableType == VIEW && (pkConstraint.getNumColumnsWithRowTimestamp() > 0 || colDef.isRowTimestamp())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.ROWTIMESTAMP_NOT_ALLOWED_ON_VIEW)
if (pkConstraint.contains(columnDef.getColumnDefName())) { columnDef.setIsPK(true);
public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode table, long timeStamp, Map<String, UDFParseNode> udfParseNodes, boolean isNamespaceMapped) throws SQLException { super(connection, 0, false, udfParseNodes, null); List<PColumnFamily> families = Lists.newArrayListWithExpectedSize(table.getDynamicColumns().size()); for (ColumnDef def : table.getDynamicColumns()) { if (def.getColumnDefName().getFamilyName() != null) { families.add(new PColumnFamilyImpl(PNameFactory.newName(def.getColumnDefName().getFamilyName()),Collections.<PColumn>emptyList()));//, NON_ENCODED_QUALIFIERS)); } } Long scn = connection.getSCN(); String schema = table.getName().getSchemaName(); if (connection.getSchema() != null) { schema = schema != null ? schema : connection.getSchema(); } // Storage scheme and encoding scheme don't matter here since the PTable is being used only for the purposes of create table. // The actual values of these two will be determined by the metadata client. PTable theTable = new PTableImpl(connection.getTenantId(), schema, table.getName().getTableName(), scn == null ? HConstants.LATEST_TIMESTAMP : scn, families, isNamespaceMapped); theTable = this.addDynamicColumns(table.getDynamicColumns(), theTable); alias = null; tableRefs = ImmutableList.of(new TableRef(alias, theTable, timeStamp, !table.getDynamicColumns().isEmpty())); schemas = ImmutableList.of(new PSchema(theTable.getSchemaName().toString(), timeStamp)); }
private void throwIfLastPKOfParentIsFixedLength(PTable parent, String viewSchemaName, String viewName, ColumnDef col) throws SQLException { if (isLastPKVariableLength(parent)) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_MODIFY_VIEW_PK) .setSchemaName(viewSchemaName) .setTableName(viewName) .setColumnName(col.getColumnDefName().getColumnName()) .build().buildException(); } }
private void throwIfLastPKOfParentIsVariableLength(PTable parent, String viewSchemaName, String viewName, ColumnDef col) throws SQLException { // if the last pk column is variable length then we read all the // bytes of the rowkey without looking for a separator byte see // https://issues.apache.org/jira/browse/PHOENIX-978?focusedCommentId=14617847&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14617847 // so we cannot add a pk column to a view if the last pk column of the parent is variable length if (isLastPKVariableLength(parent)) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_MODIFY_VIEW_PK) .setSchemaName(viewSchemaName) .setTableName(viewName) .setColumnName(col.getColumnDefName().getColumnName()) .build().buildException(); } }