Java Code Examples for org.apache.hadoop.hbase.HColumnDescriptor#getMaxVersions()

The following examples show how to use org.apache.hadoop.hbase.HColumnDescriptor#getMaxVersions() . 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: ThriftUtilities.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * This utility method creates a new Thrift ColumnDescriptor "struct" based on
 * an Hbase HColumnDescriptor object.
 *
 * @param in
 *          Hbase HColumnDescriptor object
 * @return Thrift ColumnDescriptor
 */
static public ColumnDescriptor colDescFromHbase(HColumnDescriptor in) {
  ColumnDescriptor col = new ColumnDescriptor();
  col.name = ByteBuffer.wrap(Bytes.add(in.getName(), KeyValue.COLUMN_FAMILY_DELIM_ARRAY));
  col.maxVersions = in.getMaxVersions();
  col.compression = in.getCompressionType().toString();
  col.inMemory = in.isInMemory();
  col.blockCacheEnabled = in.isBlockCacheEnabled();
  col.bloomFilterType = in.getBloomFilterType().toString();
  col.timeToLive = in.getTimeToLive();
  return col;
}
 
Example 2
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();
}