@Override public PColumnFamily getColumnFamily(byte[] family) throws ColumnFamilyNotFoundException { return delegate.getColumnFamily(family); }
@Override public PColumnFamily getColumnFamily(String family) throws ColumnFamilyNotFoundException { return delegate.getColumnFamily(family); }
private PColumn getColumn(int pkCount, byte[][] rowKeyMetaData, PTable table) throws ColumnFamilyNotFoundException, ColumnNotFoundException { PColumn col = null; if (pkCount > FAMILY_NAME_INDEX && rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX].length > 0) { PColumnFamily family = table.getColumnFamily(rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]); col = family.getPColumnForColumnNameBytes(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]); } else if (pkCount > COLUMN_NAME_INDEX && rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX].length > 0) { col = table.getPKColumn(new String(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX])); } return col; }
/** * Returns the column info for the given column for the given table. * * @param table * @param columnName User-specified column name. May be family-qualified or bare. * @return columnInfo associated with the column in the table * @throws SQLException if parameters are null or if column is not found or if column is ambiguous. */ public static ColumnInfo getColumnInfo(PTable table, String columnName) throws SQLException { if (table==null) { throw new SQLException("Table must not be null."); } if (columnName==null) { throw new SQLException("columnName must not be null."); } PColumn pColumn = null; if (columnName.contains(QueryConstants.NAME_SEPARATOR)) { String[] tokens = columnName.split(QueryConstants.NAME_SEPARATOR_REGEX); if (tokens.length!=2) { throw new SQLException(String.format("Unable to process column %s, expected family-qualified name.",columnName)); } String familyName = tokens[0]; String familyColumn = tokens[1]; PColumnFamily family = table.getColumnFamily(familyName); pColumn = family.getPColumnForColumnName(familyColumn); } else { pColumn = table.getColumnForColumnName(columnName); } return getColumnInfo(pColumn); }
public static PColumn getDataColumnOrNull(PTable dataTable, String indexColumnName) { int pos = indexColumnName.indexOf(INDEX_COLUMN_NAME_SEP); if (pos < 0) { return null; } if (pos == 0) { try { return dataTable.getPKColumn(indexColumnName.substring(1)); } catch (ColumnNotFoundException e) { return null; } } PColumnFamily family; try { family = dataTable.getColumnFamily(getDataColumnFamilyName(indexColumnName)); } catch (ColumnFamilyNotFoundException e) { return null; } try { return family.getPColumnForColumnName(indexColumnName.substring(pos+1)); } catch (ColumnNotFoundException e) { return null; } }
@Deprecated private static PColumn getPColumn(PTable table, @Nullable String familyName, String columnName) throws SQLException { if (table==null) { throw new SQLException("Table must not be null."); } if (columnName==null) { throw new SQLException("columnName must not be null."); } // normalize and remove quotes from family and column names before looking up. familyName = SchemaUtil.normalizeIdentifier(familyName); columnName = SchemaUtil.normalizeIdentifier(columnName); PColumn pColumn = null; if (familyName != null) { PColumnFamily family = table.getColumnFamily(familyName); pColumn = family.getPColumnForColumnName(columnName); } else { pColumn = table.getColumnForColumnName(columnName); } return pColumn; }
@Override public Boolean visit(KeyValueColumnExpression node) { try { this.position = table.getColumnFamily(node.getColumnFamily()).getPColumnForColumnQualifier(node.getColumnQualifier()).getPosition(); } catch (SQLException e) { throw new RuntimeException(e); // Impossible } return Boolean.TRUE; }
public static Pair<Integer, Integer> setQualifiersForColumnsInFamily(PTable table, String cf, NavigableSet<byte[]> qualifierSet) throws ColumnFamilyNotFoundException { QualifierEncodingScheme encodingScheme = table.getEncodingScheme(); checkArgument(encodingScheme != QualifierEncodingScheme.NON_ENCODED_QUALIFIERS); Collection<PColumn> columns = table.getColumnFamily(cf).getColumns(); if (columns.size() > 0) { int[] qualifiers = new int[columns.size()]; int i = 0; for (PColumn col : columns) { qualifierSet.add(col.getColumnQualifierBytes()); qualifiers[i++] = encodingScheme.decode(col.getColumnQualifierBytes()); } Arrays.sort(qualifiers); return new Pair<>(qualifiers[0], qualifiers[qualifiers.length - 1]); } return null; }
public ColumnRef(TableRef tableRef, String familyName, String columnName) throws MetaDataEntityNotFoundException { this(tableRef, tableRef.getTable().getColumnFamily(familyName).getPColumnForColumnName(columnName).getPosition()); }
private ColumnFamilyRef resolveColumnFamily(String tableName, String cfName) throws SQLException { if (tableName == null) { ColumnFamilyRef theColumnFamilyRef = null; Iterator<TableRef> iterator = tables.iterator(); while (iterator.hasNext()) { TableRef tableRef = iterator.next(); try { PColumnFamily columnFamily = tableRef.getTable().getColumnFamily(cfName); if (columnFamily == null) { throw new TableNotFoundException(cfName); } theColumnFamilyRef = new ColumnFamilyRef(tableRef, columnFamily); } catch (ColumnFamilyNotFoundException e) {} } if (theColumnFamilyRef != null) { return theColumnFamilyRef; } throw new TableNotFoundException(cfName); } else { TableRef tableRef = null; try { tableRef = resolveTable(null, tableName); } catch (TableNotFoundException e) { return resolveColumnFamily(null, cfName); } PColumnFamily columnFamily = tableRef.getTable().getColumnFamily(cfName); return new ColumnFamilyRef(tableRef, columnFamily); } }
private static PColumn getColumn(PTable table, @Nullable String familyName, String columnName) throws SQLException { if (table==null) { throw new SQLException("Table must not be null."); } if (columnName==null) { throw new SQLException("columnName must not be null."); } // normalize and remove quotes from family and column names before looking up. familyName = SchemaUtil.normalizeIdentifier(familyName); columnName = SchemaUtil.normalizeIdentifier(columnName); // Column names are always for the data table, so we must translate them if // we're dealing with an index table. if (table.getType() == PTableType.INDEX) { columnName = IndexUtil.getIndexColumnName(familyName, columnName); } PColumn pColumn = null; if (familyName != null) { PColumnFamily family = table.getColumnFamily(familyName); pColumn = family.getPColumnForColumnName(columnName); } else { pColumn = table.getColumnForColumnName(columnName); } return pColumn; }
@Override public ColumnRef resolveColumn(String schemaName, String tableName, String colName) throws SQLException { TableRef tableRef = tableRefs.get(0); boolean resolveCF = false; if (schemaName != null || tableName != null) { String resolvedTableName = tableRef.getTable().getTableName().getString(); String resolvedSchemaName = tableRef.getTable().getSchemaName().getString(); if (schemaName != null && tableName != null) { if ( ! ( schemaName.equals(resolvedSchemaName) && tableName.equals(resolvedTableName) )) { if (!(resolveCF = schemaName.equals(alias))) { throw new ColumnNotFoundException(schemaName, tableName, null, colName); } } } else { // schemaName == null && tableName != null if (tableName != null && !tableName.equals(alias) && (!tableName.equals(resolvedTableName) || !resolvedSchemaName.equals(""))) { resolveCF = true; } } } PColumn column = resolveCF ? tableRef.getTable().getColumnFamily(tableName).getPColumnForColumnName(colName) : tableRef.getTable().getColumnForColumnName(colName); return new ColumnRef(tableRef, column.getPosition()); }
@Override public ColumnRef resolveColumn(String schemaName, String tableName, String colName) throws SQLException { PColumn column = tableName != null ? tableRef.getTable().getColumnFamily(tableName).getPColumnForColumnName(colName) : tableRef.getTable().getColumnForColumnName(colName); return new ColumnRef(tableRef, column.getPosition()); }
private Void addDataColInfo(final PTable dataTable, Expression expression) { Preconditions.checkArgument(expression instanceof SingleCellColumnExpression || expression instanceof KeyValueColumnExpression); KeyValueColumnExpression colExpression = null; if (expression instanceof SingleCellColumnExpression) { colExpression = ((SingleCellColumnExpression) expression).getKeyValueExpression(); } else { colExpression = ((KeyValueColumnExpression) expression); } byte[] cf = colExpression.getColumnFamily(); byte[] cq = colExpression.getColumnQualifier(); try { PColumn dataColumn = cf == null ? dataTable.getColumnForColumnQualifier(null, cq) : dataTable.getColumnFamily(cf) .getPColumnForColumnQualifier(cq); indexedColumnsInfo.add(new Pair<>(dataColumn.getFamilyName() .getString(), dataColumn.getName().getString())); } catch (ColumnNotFoundException | ColumnFamilyNotFoundException | AmbiguousColumnException e) { throw new RuntimeException(e); } return null; } };
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 static void projectTableColumnFamily(StatementContext context, String cfName, TableRef tableRef, boolean resolveColumn, List<Expression> projectedExpressions, List<ExpressionProjector> projectedColumns) throws SQLException { PTable table = tableRef.getTable(); PColumnFamily pfamily = table.getColumnFamily(cfName); for (PColumn column : pfamily.getColumns()) { ColumnRef ref = new ColumnRef(tableRef, column.getPosition()); if (resolveColumn) { ref = context.getResolver().resolveColumn(table.getTableName().getString(), cfName, column.getName().getString()); } Expression expression = ref.newColumnExpression(); projectedExpressions.add(expression); String colName = column.getName().toString(); boolean isCaseSensitive = !SchemaUtil.normalizeIdentifier(colName).equals(colName); projectedColumns.add(new ExpressionProjector(colName, tableRef.getTableAlias() == null ? table.getName().getString() : tableRef.getTableAlias(), expression, isCaseSensitive)); } }
column = table.getPKColumn(columnToRemove.getName().getString()); } else { column = table.getColumnFamily(familyName).getPColumnForColumnName(columnToRemove.getName().getString());
public static String findExistingColumn(PTable table, List<PColumn> columns) { for (PColumn column : columns) { PName familyName = column.getFamilyName(); if (familyName == null) { try { return table.getPKColumn(column.getName().getString()).getName().getString(); } catch (ColumnNotFoundException e) { continue; } } else { try { return table.getColumnFamily(familyName.getString()).getPColumnForColumnName(column.getName().getString()).getName().getString(); } catch (ColumnFamilyNotFoundException e) { continue; // Shouldn't happen } catch (ColumnNotFoundException e) { continue; } } } return null; }
resolvedTable.getColumnFamily(column.getFamilyName().getString()).getPColumnForColumnName( column.getName().getString());
String tableName = index.getParentName().getString(); PTable table = conn.getTable(new PTableKey(conn.getTenantId(), tableName)); PColumnFamily pfamily = table.getColumnFamily(cfName); for (PColumn column : pfamily.getColumns()) { String indexColName = IndexUtil.getIndexColumnName(column);