use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class ConnectionQueryServicesImpl method setSharedIndexMaxVersion.
private void setSharedIndexMaxVersion(PTable table, HTableDescriptor tableDescriptor, HTableDescriptor indexDescriptor) {
if (table.getColumnFamilies().isEmpty()) {
byte[] familyName = SchemaUtil.getEmptyColumnFamily(table);
HColumnDescriptor indexColDescriptor = indexDescriptor.getFamily(familyName);
HColumnDescriptor tableColDescriptor = tableDescriptor.getFamily(familyName);
indexColDescriptor.setMaxVersions(tableColDescriptor.getMaxVersions());
indexColDescriptor.setValue(TxConstants.PROPERTY_TTL, tableColDescriptor.getValue(TxConstants.PROPERTY_TTL));
} else {
for (PColumnFamily family : table.getColumnFamilies()) {
byte[] familyName = family.getName().getBytes();
HColumnDescriptor indexColDescriptor = indexDescriptor.getFamily(familyName);
if (indexColDescriptor != null) {
HColumnDescriptor tableColDescriptor = tableDescriptor.getFamily(familyName);
indexColDescriptor.setMaxVersions(tableColDescriptor.getMaxVersions());
indexColDescriptor.setValue(TxConstants.PROPERTY_TTL, tableColDescriptor.getValue(TxConstants.PROPERTY_TTL));
}
}
}
}
use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class ConnectionQueryServicesImpl method existingColumnFamilies.
private HashSet<String> existingColumnFamilies(PTable table) {
List<PColumnFamily> cfs = table.getColumnFamilies();
HashSet<String> cfNames = new HashSet<>(cfs.size());
for (PColumnFamily cf : table.getColumnFamilies()) {
cfNames.add(cf.getName().getString());
}
return cfNames;
}
use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class IndexUtil method getDataColumn.
public static PColumn getDataColumn(PTable dataTable, String indexColumnName) {
int pos = indexColumnName.indexOf(INDEX_COLUMN_NAME_SEP);
if (pos < 0) {
throw new IllegalArgumentException("Could not find expected '" + INDEX_COLUMN_NAME_SEP + "' separator in index column name of \"" + indexColumnName + "\"");
}
if (pos == 0) {
try {
return dataTable.getPKColumn(indexColumnName.substring(1));
} catch (ColumnNotFoundException e) {
throw new IllegalArgumentException("Could not find PK column \"" + indexColumnName.substring(pos + 1) + "\" in index column name of \"" + indexColumnName + "\"", e);
}
}
PColumnFamily family;
try {
family = dataTable.getColumnFamily(getDataColumnFamilyName(indexColumnName));
} catch (ColumnFamilyNotFoundException e) {
throw new IllegalArgumentException("Could not find column family \"" + indexColumnName.substring(0, pos) + "\" in index column name of \"" + indexColumnName + "\"", e);
}
try {
return family.getPColumnForColumnName(indexColumnName.substring(pos + 1));
} catch (ColumnNotFoundException e) {
throw new IllegalArgumentException("Could not find column \"" + indexColumnName.substring(pos + 1) + "\" in index column name of \"" + indexColumnName + "\"", e);
}
}
use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class PhoenixRuntime method getColumnInfo.
/**
* 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);
}
use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class PhoenixRuntime method getColumn.
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);
// 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;
}
Aggregations