use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class FormatToBytesWritableMapper method initColumnIndexes.
/*
Map all unique pairs <family, name> to index. Table name is part of TableRowkey, so we do
not care about it
*/
private void initColumnIndexes() throws SQLException {
columnIndexes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
int columnIndex = 0;
for (int index = 0; index < logicalNames.size(); index++) {
PTable table = PhoenixRuntime.getTable(conn, logicalNames.get(index));
if (!table.getImmutableStorageScheme().equals(ImmutableStorageScheme.ONE_CELL_PER_COLUMN)) {
List<PColumnFamily> cfs = table.getColumnFamilies();
for (int i = 0; i < cfs.size(); i++) {
byte[] family = cfs.get(i).getName().getBytes();
byte[] cfn = Bytes.add(family, QueryConstants.NAMESPACE_SEPARATOR_BYTES, QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
columnIndexes.put(cfn, new Integer(columnIndex));
columnIndex++;
}
} else {
List<PColumn> cls = table.getColumns();
for (int i = 0; i < cls.size(); i++) {
PColumn c = cls.get(i);
byte[] family = new byte[0];
byte[] cq;
if (!SchemaUtil.isPKColumn(c)) {
family = c.getFamilyName().getBytes();
cq = c.getColumnQualifierBytes();
} else {
cq = c.getName().getBytes();
}
byte[] cfn = Bytes.add(family, QueryConstants.NAMESPACE_SEPARATOR_BYTES, cq);
if (!columnIndexes.containsKey(cfn)) {
columnIndexes.put(cfn, new Integer(columnIndex));
columnIndex++;
}
}
byte[] emptyColumnFamily = SchemaUtil.getEmptyColumnFamily(table);
byte[] emptyKeyValue = EncodedColumnsUtil.getEmptyKeyValueInfo(table).getFirst();
byte[] cfn = Bytes.add(emptyColumnFamily, QueryConstants.NAMESPACE_SEPARATOR_BYTES, emptyKeyValue);
columnIndexes.put(cfn, new Integer(columnIndex));
columnIndex++;
}
}
}
use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class GuidePostsCache method invalidateAll.
public void invalidateAll(PTable table) {
byte[] physicalName = table.getPhysicalName().getBytes();
List<PColumnFamily> families = table.getColumnFamilies();
if (families.isEmpty()) {
invalidate(new GuidePostsKey(physicalName, SchemaUtil.getEmptyColumnFamily(table)));
} else {
for (PColumnFamily family : families) {
invalidate(new GuidePostsKey(physicalName, family.getName().getBytes()));
}
}
}
use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class IndexTestUtil method generateIndexData.
public static List<Mutation> generateIndexData(PTable indexTable, PTable dataTable, Mutation dataMutation, ImmutableBytesWritable ptr, KeyValueBuilder builder) throws SQLException {
byte[] dataRowKey = dataMutation.getRow();
RowKeySchema dataRowKeySchema = dataTable.getRowKeySchema();
List<PColumn> dataPKColumns = dataTable.getPKColumns();
int i = 0;
int indexOffset = 0;
Boolean hasValue;
// Skip salt column
int maxOffset = dataRowKey.length;
dataRowKeySchema.iterator(dataRowKey, ptr, dataTable.getBucketNum() == null ? i : ++i);
List<PColumn> indexPKColumns = indexTable.getPKColumns();
List<PColumn> indexColumns = indexTable.getColumns();
int nIndexColumns = indexPKColumns.size();
int maxIndexValues = indexColumns.size() - nIndexColumns - indexOffset;
BitSet indexValuesSet = new BitSet(maxIndexValues);
byte[][] indexValues = new byte[indexColumns.size() - indexOffset][];
while ((hasValue = dataRowKeySchema.next(ptr, i, maxOffset)) != null) {
if (hasValue) {
PColumn dataColumn = dataPKColumns.get(i);
PColumn indexColumn = indexTable.getColumnForColumnName(IndexUtil.getIndexColumnName(dataColumn));
coerceDataValueToIndexValue(dataColumn, indexColumn, ptr);
indexValues[indexColumn.getPosition() - indexOffset] = ptr.copyBytes();
}
i++;
}
PRow row;
long ts = MetaDataUtil.getClientTimeStamp(dataMutation);
if (dataMutation instanceof Delete && dataMutation.getFamilyCellMap().values().isEmpty()) {
indexTable.newKey(ptr, indexValues);
row = indexTable.newRow(builder, ts, ptr, false);
row.delete();
} else {
// If no column families in table, then nothing to look for
if (!dataTable.getColumnFamilies().isEmpty()) {
for (Map.Entry<byte[], List<Cell>> entry : dataMutation.getFamilyCellMap().entrySet()) {
PColumnFamily family = dataTable.getColumnFamily(entry.getKey());
for (Cell kv : entry.getValue()) {
@SuppressWarnings("deprecation") byte[] cq = kv.getQualifier();
byte[] emptyKVQualifier = EncodedColumnsUtil.getEmptyKeyValueInfo(dataTable).getFirst();
if (Bytes.compareTo(emptyKVQualifier, cq) != 0) {
try {
PColumn dataColumn = family.getPColumnForColumnQualifier(cq);
PColumn indexColumn = indexTable.getColumnForColumnName(IndexUtil.getIndexColumnName(family.getName().getString(), dataColumn.getName().getString()));
ptr.set(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
coerceDataValueToIndexValue(dataColumn, indexColumn, ptr);
indexValues[indexPKColumns.indexOf(indexColumn) - indexOffset] = ptr.copyBytes();
if (!SchemaUtil.isPKColumn(indexColumn)) {
indexValuesSet.set(indexColumn.getPosition() - nIndexColumns - indexOffset);
}
} catch (ColumnNotFoundException e) {
// Ignore as this means that the data column isn't in the index
}
}
}
}
}
indexTable.newKey(ptr, indexValues);
row = indexTable.newRow(builder, ts, ptr, false);
int pos = 0;
while ((pos = indexValuesSet.nextSetBit(pos)) >= 0) {
int index = nIndexColumns + indexOffset + pos++;
PColumn indexColumn = indexColumns.get(index);
row.setValue(indexColumn, indexValues[index]);
}
}
return row.toRowMutations();
}
use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class PhoenixRuntime method getPColumn.
@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;
}
use of org.apache.phoenix.schema.PColumnFamily in project phoenix by apache.
the class ConnectionQueryServicesImpl method updateDescriptorForTx.
private void updateDescriptorForTx(PTable table, Map<String, Object> tableProps, HTableDescriptor tableDescriptor, String txValue, Set<HTableDescriptor> descriptorsToUpdate, Set<HTableDescriptor> origDescriptors) throws SQLException {
byte[] physicalTableName = table.getPhysicalName().getBytes();
try (HBaseAdmin admin = getAdmin()) {
setTransactional(tableDescriptor, table.getType(), txValue, tableProps);
Map<String, Object> indexTableProps;
if (txValue == null) {
indexTableProps = Collections.<String, Object>emptyMap();
} else {
indexTableProps = Maps.newHashMapWithExpectedSize(1);
indexTableProps.put(TxConstants.READ_NON_TX_DATA, Boolean.valueOf(txValue));
}
for (PTable index : table.getIndexes()) {
HTableDescriptor indexDescriptor = admin.getTableDescriptor(index.getPhysicalName().getBytes());
origDescriptors.add(indexDescriptor);
indexDescriptor = new HTableDescriptor(indexDescriptor);
descriptorsToUpdate.add(indexDescriptor);
if (index.getColumnFamilies().isEmpty()) {
byte[] dataFamilyName = SchemaUtil.getEmptyColumnFamily(table);
byte[] indexFamilyName = SchemaUtil.getEmptyColumnFamily(index);
HColumnDescriptor indexColDescriptor = indexDescriptor.getFamily(indexFamilyName);
HColumnDescriptor tableColDescriptor = tableDescriptor.getFamily(dataFamilyName);
indexColDescriptor.setMaxVersions(tableColDescriptor.getMaxVersions());
indexColDescriptor.setValue(TxConstants.PROPERTY_TTL, tableColDescriptor.getValue(TxConstants.PROPERTY_TTL));
} else {
for (PColumnFamily family : index.getColumnFamilies()) {
byte[] familyName = family.getName().getBytes();
indexDescriptor.getFamily(familyName).setMaxVersions(tableDescriptor.getFamily(familyName).getMaxVersions());
HColumnDescriptor indexColDescriptor = indexDescriptor.getFamily(familyName);
HColumnDescriptor tableColDescriptor = tableDescriptor.getFamily(familyName);
indexColDescriptor.setMaxVersions(tableColDescriptor.getMaxVersions());
indexColDescriptor.setValue(TxConstants.PROPERTY_TTL, tableColDescriptor.getValue(TxConstants.PROPERTY_TTL));
}
}
setTransactional(indexDescriptor, index.getType(), txValue, indexTableProps);
}
try {
HTableDescriptor indexDescriptor = admin.getTableDescriptor(MetaDataUtil.getViewIndexPhysicalName(physicalTableName));
origDescriptors.add(indexDescriptor);
indexDescriptor = new HTableDescriptor(indexDescriptor);
descriptorsToUpdate.add(indexDescriptor);
setSharedIndexMaxVersion(table, tableDescriptor, indexDescriptor);
setTransactional(indexDescriptor, PTableType.INDEX, txValue, indexTableProps);
} catch (org.apache.hadoop.hbase.TableNotFoundException ignore) {
// Ignore, as we may never have created a view index table
}
try {
HTableDescriptor indexDescriptor = admin.getTableDescriptor(MetaDataUtil.getLocalIndexPhysicalName(physicalTableName));
origDescriptors.add(indexDescriptor);
indexDescriptor = new HTableDescriptor(indexDescriptor);
descriptorsToUpdate.add(indexDescriptor);
setSharedIndexMaxVersion(table, tableDescriptor, indexDescriptor);
setTransactional(indexDescriptor, PTableType.INDEX, txValue, indexTableProps);
} catch (org.apache.hadoop.hbase.TableNotFoundException ignore) {
// Ignore, as we may never have created a view index table
}
} catch (IOException e) {
throw ServerUtil.parseServerException(e);
}
}
Aggregations