Search in sources :

Example 51 with PColumn

use of org.apache.phoenix.schema.PColumn in project DataX by alibaba.

the class HbaseSQLHelper method getPColumnNames.

public static List<String> getPColumnNames(String connectionString, String tableName) throws SQLException {
    Connection con = DriverManager.getConnection(connectionString);
    PhoenixConnection phoenixConnection = con.unwrap(PhoenixConnection.class);
    MetaDataClient metaDataClient = new MetaDataClient(phoenixConnection);
    PTable table = metaDataClient.updateCache("", tableName).getTable();
    List<String> columnNames = new ArrayList<String>();
    for (PColumn pColumn : table.getColumns()) {
        if (!pColumn.getName().getString().equals(SaltingUtil.SALTING_COLUMN_NAME))
            columnNames.add(pColumn.getName().getString());
        else
            LOG.info(tableName + " is salt table");
    }
    return columnNames;
}
Also used : MetaDataClient(org.apache.phoenix.schema.MetaDataClient) PColumn(org.apache.phoenix.schema.PColumn) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ArrayList(java.util.ArrayList) PTable(org.apache.phoenix.schema.PTable)

Example 52 with PColumn

use of org.apache.phoenix.schema.PColumn in project phoenix by apache.

the class AlterMultiTenantTableWithViewsIT method getIndexOfPkColumn.

private int getIndexOfPkColumn(PhoenixConnection conn, String columnName, String tableName) throws SQLException {
    String normalizedTableName = SchemaUtil.normalizeIdentifier(tableName);
    PTable table = conn.getTable(new PTableKey(conn.getTenantId(), normalizedTableName));
    List<PColumn> pkCols = table.getPKColumns();
    String normalizedColumnName = SchemaUtil.normalizeIdentifier(columnName);
    int i = 0;
    for (PColumn pkCol : pkCols) {
        if (pkCol.getName().getString().equals(normalizedColumnName)) {
            return i;
        }
        i++;
    }
    return -1;
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) PTableKey(org.apache.phoenix.schema.PTableKey) PTable(org.apache.phoenix.schema.PTable)

Example 53 with PColumn

use of org.apache.phoenix.schema.PColumn in project phoenix by apache.

the class EncodedColumnsUtil method setQualifiersForColumnsInFamily.

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;
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) QualifierEncodingScheme(org.apache.phoenix.schema.PTable.QualifierEncodingScheme) Pair(org.apache.hadoop.hbase.util.Pair)

Example 54 with PColumn

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

Example 55 with PColumn

use of org.apache.phoenix.schema.PColumn in project phoenix by apache.

the class MetaDataUtil method getAutoPartitionColumnName.

public static String getAutoPartitionColumnName(PTable parentTable) {
    List<PColumn> parentTableColumns = parentTable.getPKColumns();
    PColumn column = parentTableColumns.get(getAutoPartitionColIndex(parentTable));
    return column.getName().getString();
}
Also used : PColumn(org.apache.phoenix.schema.PColumn)

Aggregations

PColumn (org.apache.phoenix.schema.PColumn)101 PTable (org.apache.phoenix.schema.PTable)59 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)26 Expression (org.apache.phoenix.expression.Expression)21 TableRef (org.apache.phoenix.schema.TableRef)20 ArrayList (java.util.ArrayList)19 PName (org.apache.phoenix.schema.PName)18 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)17 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)17 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)17 ColumnRef (org.apache.phoenix.schema.ColumnRef)17 Hint (org.apache.phoenix.parse.HintNode.Hint)14 PTableKey (org.apache.phoenix.schema.PTableKey)14 ColumnNotFoundException (org.apache.phoenix.schema.ColumnNotFoundException)13 PColumnFamily (org.apache.phoenix.schema.PColumnFamily)13 PSmallint (org.apache.phoenix.schema.types.PSmallint)13 SQLException (java.sql.SQLException)12 ProjectedColumnExpression (org.apache.phoenix.expression.ProjectedColumnExpression)12 PColumnImpl (org.apache.phoenix.schema.PColumnImpl)12 Map (java.util.Map)11