Search in sources :

Example 1 with ColumnFamilySchema

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ColumnFamilySchema in project hbase by apache.

the class ProtobufUtil method convertToHTableDesc.

/**
   * Converts a TableSchema to HTableDescriptor
   * @param ts A pb TableSchema instance.
   * @return An {@link HTableDescriptor} made from the passed in pb <code>ts</code>.
   */
public static HTableDescriptor convertToHTableDesc(final TableSchema ts) {
    List<ColumnFamilySchema> list = ts.getColumnFamiliesList();
    HColumnDescriptor[] hcds = new HColumnDescriptor[list.size()];
    int index = 0;
    for (ColumnFamilySchema cfs : list) {
        hcds[index++] = ProtobufUtil.convertToHColumnDesc(cfs);
    }
    HTableDescriptor htd = new HTableDescriptor(ProtobufUtil.toTableName(ts.getTableName()));
    for (HColumnDescriptor hcd : hcds) {
        htd.addFamily(hcd);
    }
    for (BytesBytesPair a : ts.getAttributesList()) {
        htd.setValue(a.getFirst().toByteArray(), a.getSecond().toByteArray());
    }
    for (NameStringPair a : ts.getConfigurationList()) {
        htd.setConfiguration(a.getName(), a.getValue());
    }
    return htd;
}
Also used : ColumnFamilySchema(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ColumnFamilySchema) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair) BytesBytesPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.BytesBytesPair) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 2 with ColumnFamilySchema

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ColumnFamilySchema in project hbase by apache.

the class HColumnDescriptor method parseFrom.

/**
   * @param bytes A pb serialized {@link HColumnDescriptor} instance with pb magic prefix
   * @return An instance of {@link HColumnDescriptor} made from <code>bytes</code>
   * @throws DeserializationException
   * @see #toByteArray()
   */
public static HColumnDescriptor parseFrom(final byte[] bytes) throws DeserializationException {
    if (!ProtobufUtil.isPBMagicPrefix(bytes))
        throw new DeserializationException("No magic");
    int pblen = ProtobufUtil.lengthOfPBMagic();
    ColumnFamilySchema.Builder builder = ColumnFamilySchema.newBuilder();
    ColumnFamilySchema cfs = null;
    try {
        ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen);
        cfs = builder.build();
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
    return ProtobufUtil.convertToHColumnDesc(cfs);
}
Also used : ColumnFamilySchema(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ColumnFamilySchema) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

ColumnFamilySchema (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ColumnFamilySchema)2 IOException (java.io.IOException)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)1 BytesBytesPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.BytesBytesPair)1 NameStringPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)1