Search in sources :

Example 6 with PColumnFamily

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));
            }
        }
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) PColumnFamily(org.apache.phoenix.schema.PColumnFamily)

Example 7 with PColumnFamily

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;
}
Also used : PColumnFamily(org.apache.phoenix.schema.PColumnFamily) HashSet(java.util.HashSet)

Example 8 with PColumnFamily

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);
    }
}
Also used : ColumnNotFoundException(org.apache.phoenix.schema.ColumnNotFoundException) PColumnFamily(org.apache.phoenix.schema.PColumnFamily) ColumnFamilyNotFoundException(org.apache.phoenix.schema.ColumnFamilyNotFoundException)

Example 9 with PColumnFamily

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);
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) SQLException(java.sql.SQLException) PColumnFamily(org.apache.phoenix.schema.PColumnFamily)

Example 10 with PColumnFamily

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;
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) SQLException(java.sql.SQLException) PColumnFamily(org.apache.phoenix.schema.PColumnFamily)

Aggregations

PColumnFamily (org.apache.phoenix.schema.PColumnFamily)22 PColumn (org.apache.phoenix.schema.PColumn)13 PTable (org.apache.phoenix.schema.PTable)10 SQLException (java.sql.SQLException)6 ColumnFamilyNotFoundException (org.apache.phoenix.schema.ColumnFamilyNotFoundException)6 ColumnNotFoundException (org.apache.phoenix.schema.ColumnNotFoundException)6 List (java.util.List)4 Map (java.util.Map)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 TreeMap (java.util.TreeMap)3 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)3 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)3 Pair (org.apache.hadoop.hbase.util.Pair)3 BaseTerminalExpression (org.apache.phoenix.expression.BaseTerminalExpression)3 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)3 Expression (org.apache.phoenix.expression.Expression)3 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)3 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)3