Search in sources :

Example 1 with LazyObjectBase

use of org.apache.hadoop.hive.serde2.lazy.LazyObjectBase in project hive by apache.

the class DelimitedAccumuloRowIdFactory method createRowId.

@Override
public LazyObjectBase createRowId(ObjectInspector inspector) throws SerDeException {
    LazyObjectBase lazyObj = LazyFactory.createLazyObject(inspector, ColumnEncoding.BINARY == rowIdMapping.getEncoding());
    log.info("Created " + lazyObj.getClass() + " for rowId with inspector " + inspector.getClass());
    return lazyObj;
}
Also used : LazyObjectBase(org.apache.hadoop.hive.serde2.lazy.LazyObjectBase)

Example 2 with LazyObjectBase

use of org.apache.hadoop.hive.serde2.lazy.LazyObjectBase in project hive by apache.

the class LazyAccumuloRow method uncheckedGetField.

/*
   * split pairs by delimiter.
   */
private Object uncheckedGetField(int id) {
    if (getFieldInited()[id]) {
        return getFields()[id].getObject();
    }
    getFieldInited()[id] = true;
    ColumnMapping columnMapping = columnMappings.get(id);
    LazyObjectBase field = getFields()[id];
    if (columnMapping instanceof HiveAccumuloMapColumnMapping) {
        HiveAccumuloMapColumnMapping mapColumnMapping = (HiveAccumuloMapColumnMapping) columnMapping;
        LazyAccumuloMap map = (LazyAccumuloMap) field;
        map.init(row, mapColumnMapping);
    } else {
        byte[] value;
        if (columnMapping instanceof HiveAccumuloRowIdColumnMapping) {
            // Use the rowID directly
            value = row.getRowId().getBytes();
        } else if (columnMapping instanceof HiveAccumuloColumnMapping) {
            HiveAccumuloColumnMapping accumuloColumnMapping = (HiveAccumuloColumnMapping) columnMapping;
            // Use the colfam and colqual to get the value
            value = row.getValue(new Text(accumuloColumnMapping.getColumnFamilyBytes()), new Text(accumuloColumnMapping.getColumnQualifierBytes()));
        } else {
            log.error("Could not process ColumnMapping of type " + columnMapping.getClass() + " at offset " + id + " in column mapping: " + columnMapping.getMappingSpec());
            throw new IllegalArgumentException("Cannot process ColumnMapping of type " + columnMapping.getClass());
        }
        if (value == null || isNull(oi.getNullSequence(), value, 0, value.length)) {
            field.setNull();
        } else {
            ByteArrayRef ref = new ByteArrayRef();
            ref.setData(value);
            field.init(ref, 0, value.length);
        }
    }
    return field.getObject();
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef) HiveAccumuloRowIdColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloRowIdColumnMapping) HiveAccumuloMapColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping) LazyObjectBase(org.apache.hadoop.hive.serde2.lazy.LazyObjectBase) Text(org.apache.hadoop.io.Text) HiveAccumuloColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloColumnMapping) HiveAccumuloMapColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping) HiveAccumuloColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloColumnMapping) HiveAccumuloRowIdColumnMapping(org.apache.hadoop.hive.accumulo.columns.HiveAccumuloRowIdColumnMapping) ColumnMapping(org.apache.hadoop.hive.accumulo.columns.ColumnMapping)

Example 3 with LazyObjectBase

use of org.apache.hadoop.hive.serde2.lazy.LazyObjectBase in project hive by apache.

the class LazyHBaseRow method uncheckedGetField.

/**
 * Get the field out of the row without checking whether parsing is needed.
 * This is called by both getField and getFieldsAsList.
 * @param fieldID  The id of the field starting from 0.
 * @return  The value of the field
 */
private Object uncheckedGetField(int fieldID) {
    LazyObjectBase[] fields = getFields();
    boolean[] fieldsInited = getFieldInited();
    if (!fieldsInited[fieldID]) {
        fieldsInited[fieldID] = true;
        ColumnMapping colMap = columnsMapping[fieldID];
        if (!colMap.hbaseRowKey && !colMap.hbaseTimestamp && colMap.qualifierName == null) {
            // it is a column family
            // primitive type for Map<Key, Value> can be stored in binary format. Pass in the
            // qualifier prefix to cherry pick the qualifiers that match the prefix instead of picking
            // up everything
            ((LazyHBaseCellMap) fields[fieldID]).init(result, colMap.familyNameBytes, colMap.binaryStorage, colMap.qualifierPrefixBytes, colMap.isDoPrefixCut());
            return fields[fieldID].getObject();
        }
        if (colMap.hbaseTimestamp) {
            // Get the latest timestamp of all the cells as the row timestamp
            // from hbase-0.96.0
            long timestamp = result.rawCells()[0].getTimestamp();
            for (int i = 1; i < result.rawCells().length; i++) {
                timestamp = Math.max(timestamp, result.rawCells()[i].getTimestamp());
            }
            LazyObjectBase lz = fields[fieldID];
            if (lz instanceof LazyTimestamp) {
                ((LazyTimestamp) lz).getWritableObject().set(Timestamp.ofEpochMilli(timestamp));
            } else {
                ((LazyLong) lz).getWritableObject().set(timestamp);
            }
            return lz.getObject();
        }
        byte[] bytes;
        if (colMap.hbaseRowKey) {
            bytes = result.getRow();
        } else {
            // it is a column i.e. a column-family with column-qualifier
            bytes = result.getValue(colMap.familyNameBytes, colMap.qualifierNameBytes);
        }
        if (bytes == null || isNull(oi.getNullSequence(), bytes, 0, bytes.length)) {
            fields[fieldID].setNull();
        } else {
            ByteArrayRef ref = new ByteArrayRef();
            ref.setData(bytes);
            fields[fieldID].init(ref, 0, bytes.length);
        }
    }
    return fields[fieldID].getObject();
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef) LazyTimestamp(org.apache.hadoop.hive.serde2.lazy.LazyTimestamp) LazyObjectBase(org.apache.hadoop.hive.serde2.lazy.LazyObjectBase) ColumnMapping(org.apache.hadoop.hive.hbase.ColumnMappings.ColumnMapping)

Example 4 with LazyObjectBase

use of org.apache.hadoop.hive.serde2.lazy.LazyObjectBase in project hive by apache.

the class TestDefaultAccumuloRowIdFactory method testBinaryStringRowId.

@Test
public void testBinaryStringRowId() throws SerDeException {
    AccumuloSerDe accumuloSerDe = new AccumuloSerDe();
    Properties properties = new Properties();
    Configuration conf = new Configuration();
    properties.setProperty(AccumuloSerDeParameters.COLUMN_MAPPINGS, ":rowID,cf:cq");
    properties.setProperty(serdeConstants.LIST_COLUMNS, "row,col");
    properties.setProperty(serdeConstants.LIST_COLUMN_TYPES, "string,string");
    properties.setProperty(AccumuloSerDeParameters.DEFAULT_STORAGE_TYPE, ColumnEncoding.BINARY.getName());
    accumuloSerDe.initialize(conf, properties, null);
    DefaultAccumuloRowIdFactory rowIdFactory = new DefaultAccumuloRowIdFactory();
    rowIdFactory.init(accumuloSerDe.getParams(), properties);
    LazyStringObjectInspector oi = LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, (byte) '\\');
    LazyObjectBase lazyObj = rowIdFactory.createRowId(oi);
    Assert.assertNotNull(lazyObj);
    Assert.assertTrue(LazyString.class.isAssignableFrom(lazyObj.getClass()));
}
Also used : LazyString(org.apache.hadoop.hive.serde2.lazy.LazyString) LazyStringObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyStringObjectInspector) Configuration(org.apache.hadoop.conf.Configuration) LazyObjectBase(org.apache.hadoop.hive.serde2.lazy.LazyObjectBase) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

LazyObjectBase (org.apache.hadoop.hive.serde2.lazy.LazyObjectBase)4 ByteArrayRef (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)2 Properties (java.util.Properties)1 Configuration (org.apache.hadoop.conf.Configuration)1 ColumnMapping (org.apache.hadoop.hive.accumulo.columns.ColumnMapping)1 HiveAccumuloColumnMapping (org.apache.hadoop.hive.accumulo.columns.HiveAccumuloColumnMapping)1 HiveAccumuloMapColumnMapping (org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping)1 HiveAccumuloRowIdColumnMapping (org.apache.hadoop.hive.accumulo.columns.HiveAccumuloRowIdColumnMapping)1 ColumnMapping (org.apache.hadoop.hive.hbase.ColumnMappings.ColumnMapping)1 LazyString (org.apache.hadoop.hive.serde2.lazy.LazyString)1 LazyTimestamp (org.apache.hadoop.hive.serde2.lazy.LazyTimestamp)1 LazyStringObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyStringObjectInspector)1 Text (org.apache.hadoop.io.Text)1 Test (org.junit.Test)1