Java Code Examples for org.apache.phoenix.schema.PTable#getDefaultFamilyName()

The following examples show how to use org.apache.phoenix.schema.PTable#getDefaultFamilyName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColumnParseNode.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void toSQL(ColumnResolver resolver, StringBuilder buf) {
    // If resolver is not null, then resolve to get fully qualified name
    String tableName = null;
    if (resolver == null) {
        if (this.tableName != null) {
            tableName = this.tableName.getTableName();
        }
    } else {
        try {
            ColumnRef ref = resolver.resolveColumn(this.getSchemaName(), this.getTableName(), this.getName());
            PColumn column = ref.getColumn();
            if (!SchemaUtil.isPKColumn(column)) {
                PTable table = ref.getTable();
                String defaultFamilyName = table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY : table.getDefaultFamilyName().getString();
                // Translate to the data table column name
                String dataFamilyName = column.getFamilyName().getString() ;
                tableName = defaultFamilyName.equals(dataFamilyName) ? null : dataFamilyName;
            }
            
        } catch (SQLException e) {
            throw new RuntimeException(e); // Already resolved, so not possible
        }
    }
    if (tableName != null) {
        if (isTableNameCaseSensitive()) {
            buf.append('"');
            buf.append(tableName);
            buf.append('"');
        } else {
            buf.append(tableName);
        }
        buf.append('.');
    }
    toSQL(buf);
}
 
Example 2
Source File: ColumnParseNode.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void toSQL(ColumnResolver resolver, StringBuilder buf) {
    // If resolver is not null, then resolve to get fully qualified name
    String tableName = null;
    if (resolver == null) {
        if (this.tableName != null) {
            tableName = this.tableName.getTableName();
        }
    } else {
        try {
            ColumnRef ref = resolver.resolveColumn(this.getSchemaName(), this.getTableName(), this.getName());
            PColumn column = ref.getColumn();
            if (!SchemaUtil.isPKColumn(column)) {
                PTable table = ref.getTable();
                String defaultFamilyName = table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY : table.getDefaultFamilyName().getString();
                // Translate to the data table column name
                String dataFamilyName = column.getFamilyName().getString() ;
                tableName = defaultFamilyName.equals(dataFamilyName) ? null : dataFamilyName;
            }
            
        } catch (SQLException e) {
            throw new RuntimeException(e); // Already resolved, so not possible
        }
    }
    if (tableName != null) {
        if (isTableNameCaseSensitive()) {
            buf.append('"');
            buf.append(tableName);
            buf.append('"');
        } else {
            buf.append(tableName);
        }
        buf.append('.');
    }
    toSQL(buf);
}
 
Example 3
Source File: PhoenixMetadata.java    From presto with Apache License 2.0 4 votes vote down vote up
private Map<String, Object> getTableProperties(ConnectorSession session, JdbcTableHandle handle)
{
    ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();

    try (PhoenixConnection connection = phoenixClient.getConnection(JdbcIdentity.from(session));
            HBaseAdmin admin = connection.getQueryServices().getAdmin()) {
        String schemaName = toPhoenixSchemaName(Optional.ofNullable(handle.getSchemaName())).orElse(null);
        PTable table = getTable(connection, SchemaUtil.getTableName(schemaName, handle.getTableName()));

        boolean salted = table.getBucketNum() != null;
        StringJoiner joiner = new StringJoiner(",");
        List<PColumn> pkColumns = table.getPKColumns();
        for (PColumn pkColumn : pkColumns.subList(salted ? 1 : 0, pkColumns.size())) {
            joiner.add(pkColumn.getName().getString());
        }
        properties.put(PhoenixTableProperties.ROWKEYS, joiner.toString());

        if (table.getBucketNum() != null) {
            properties.put(PhoenixTableProperties.SALT_BUCKETS, table.getBucketNum());
        }
        if (table.isWALDisabled()) {
            properties.put(PhoenixTableProperties.DISABLE_WAL, table.isWALDisabled());
        }
        if (table.isImmutableRows()) {
            properties.put(PhoenixTableProperties.IMMUTABLE_ROWS, table.isImmutableRows());
        }

        String defaultFamilyName = QueryConstants.DEFAULT_COLUMN_FAMILY;
        if (table.getDefaultFamilyName() != null) {
            defaultFamilyName = table.getDefaultFamilyName().getString();
            properties.put(PhoenixTableProperties.DEFAULT_COLUMN_FAMILY, defaultFamilyName);
        }

        HTableDescriptor tableDesc = admin.getTableDescriptor(table.getPhysicalName().getBytes());

        HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
        for (HColumnDescriptor columnFamily : columnFamilies) {
            if (columnFamily.getNameAsString().equals(defaultFamilyName)) {
                if (!"NONE".equals(columnFamily.getBloomFilterType().toString())) {
                    properties.put(PhoenixTableProperties.BLOOMFILTER, columnFamily.getBloomFilterType().toString());
                }
                if (columnFamily.getMaxVersions() != 1) {
                    properties.put(PhoenixTableProperties.VERSIONS, columnFamily.getMaxVersions());
                }
                if (columnFamily.getMinVersions() > 0) {
                    properties.put(PhoenixTableProperties.MIN_VERSIONS, columnFamily.getMinVersions());
                }
                if (!columnFamily.getCompression().toString().equals("NONE")) {
                    properties.put(PhoenixTableProperties.COMPRESSION, columnFamily.getCompression().toString());
                }
                if (columnFamily.getTimeToLive() < FOREVER) {
                    properties.put(PhoenixTableProperties.TTL, columnFamily.getTimeToLive());
                }
                break;
            }
        }
    }
    catch (IOException | SQLException e) {
        throw new PrestoException(PHOENIX_METADATA_ERROR, "Couldn't get Phoenix table properties", e);
    }
    return properties.build();
}
 
Example 4
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static byte[] getEmptyColumnFamily(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES : table.getDefaultFamilyName().getBytes() : families.get(0).getName().getBytes();
}
 
Example 5
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static ImmutableBytesPtr getEmptyColumnFamilyPtr(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES_PTR : table.getDefaultFamilyName().getBytesPtr() : families.get(0)
            .getName().getBytesPtr();
}
 
Example 6
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static byte[] getEmptyColumnFamily(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES) : table.getDefaultFamilyName().getBytes() : families.get(0).getName().getBytes();
}
 
Example 7
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static String getEmptyColumnFamilyAsString(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY : QueryConstants.DEFAULT_COLUMN_FAMILY) : table.getDefaultFamilyName().getString() : families.get(0).getName().getString();
}
 
Example 8
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static ImmutableBytesPtr getEmptyColumnFamilyPtr(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES_PTR : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES_PTR) : table.getDefaultFamilyName().getBytesPtr() : families.get(0)
            .getName().getBytesPtr();
}