Search in sources :

Example 36 with ObjectInspectorFactory.getStandardStructObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.

the class MapJoinTestDescription method computeDerived.

public void computeDerived() {
    bigTableColumnNamesList = Arrays.asList(bigTableColumnNames);
    bigTableKeyColumnNames = new String[bigTableKeyColumnNums.length];
    bigTableKeyTypeInfos = new TypeInfo[bigTableKeyColumnNums.length];
    for (int i = 0; i < bigTableKeyColumnNums.length; i++) {
        bigTableKeyColumnNames[i] = bigTableColumnNames[bigTableKeyColumnNums[i]];
        bigTableKeyTypeInfos[i] = bigTableTypeInfos[bigTableKeyColumnNums[i]];
    }
    smallTableValueColumnNamesList = Arrays.asList(smallTableValueColumnNames);
    bigTableObjectInspectors = new ObjectInspector[bigTableTypeInfos.length];
    for (int i = 0; i < bigTableTypeInfos.length; i++) {
        bigTableObjectInspectors[i] = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector((PrimitiveTypeInfo) bigTableTypeInfos[i]);
    }
    bigTableObjectInspectorsList = Arrays.asList(bigTableObjectInspectors);
    smallTableObjectInspectors = new ObjectInspector[smallTableValueTypeInfos.length];
    smallTablePrimitiveCategories = new PrimitiveCategory[smallTableValueTypeInfos.length];
    smallTableValuePrimitiveTypeInfos = new PrimitiveTypeInfo[smallTableValueTypeInfos.length];
    for (int i = 0; i < smallTableValueTypeInfos.length; i++) {
        PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) smallTableValueTypeInfos[i];
        smallTableObjectInspectors[i] = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(primitiveTypeInfo);
        smallTablePrimitiveCategories[i] = primitiveTypeInfo.getPrimitiveCategory();
        smallTableValuePrimitiveTypeInfos[i] = primitiveTypeInfo;
    }
    smallTableObjectInspectorsList = Arrays.asList(smallTableObjectInspectors);
    bigTableStandardObjectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(bigTableColumnNamesList, Arrays.asList((ObjectInspector[]) bigTableObjectInspectors));
    smallTableStandardObjectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(smallTableValueColumnNamesList, Arrays.asList((ObjectInspector[]) smallTableObjectInspectors));
    inputObjectInspectors = new ObjectInspector[] { bigTableStandardObjectInspector, smallTableStandardObjectInspector };
    int outputLength = bigTableRetainColumnNums.length + smallTableRetainKeyColumnNums.length + smallTableRetainValueColumnNums.length;
    outputColumnNames = createOutputColumnNames(outputLength);
    outputTypeInfos = new TypeInfo[outputLength];
    int outputIndex = 0;
    for (int i = 0; i < bigTableRetainColumnNums.length; i++) {
        outputTypeInfos[outputIndex++] = bigTableTypeInfos[bigTableRetainColumnNums[i]];
    }
    // }
    for (int i = 0; i < smallTableRetainValueColumnNums.length; i++) {
        outputTypeInfos[outputIndex++] = smallTableValueTypeInfos[smallTableRetainValueColumnNums[i]];
    }
    outputObjectInspectors = new ObjectInspector[outputLength];
    for (int i = 0; i < outputLength; i++) {
        PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) outputTypeInfos[i];
        outputObjectInspectors[i] = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(primitiveTypeInfo);
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)

Example 37 with ObjectInspectorFactory.getStandardStructObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.

the class DataBuilder method createRows.

/**
 * returns the InspectableObject array the builder methods
 * helped to assemble.
 * @return InspectableObject array (objects that have data coupled with
 * and object inspector )
 */
public InspectableObject[] createRows() {
    InspectableObject[] toReturn = new InspectableObject[this.rows.size()];
    for (int i = 0; i < toReturn.length; i++) {
        toReturn[i] = new InspectableObject();
        toReturn[i].o = rows.get(i);
        toReturn[i].oi = ObjectInspectorFactory.getStandardStructObjectInspector(this.columnNames, this.columnTypes);
    }
    return toReturn;
}
Also used : InspectableObject(org.apache.hadoop.hive.serde2.objectinspector.InspectableObject)

Example 38 with ObjectInspectorFactory.getStandardStructObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.

the class TestGenericUDFExtractUnionValueConverter method convertStruct.

@Test
public void convertStruct() {
    ObjectInspector inspector = ObjectInspectorFactory.getStandardStructObjectInspector(Arrays.asList("foo"), Arrays.<ObjectInspector>asList(unionObjectInspector));
    Object value = Arrays.asList(union);
    @SuppressWarnings("unchecked") List<Object> result = (List<Object>) underTest.convert(value, inspector);
    assertThat(result.size(), is(1));
    assertThat(result.get(0), is((Object) Arrays.asList("foo", null)));
}
Also used : StandardUnionObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) List(java.util.List) Test(org.junit.Test)

Example 39 with ObjectInspectorFactory.getStandardStructObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.

the class InternalUtil method createStructObjectInspector.

static StructObjectInspector createStructObjectInspector(HCatSchema outputSchema) throws IOException {
    if (outputSchema == null) {
        throw new IOException("Invalid output schema specified");
    }
    List<ObjectInspector> fieldInspectors = new ArrayList<ObjectInspector>();
    List<String> fieldNames = new ArrayList<String>();
    for (HCatFieldSchema hcatFieldSchema : outputSchema.getFields()) {
        TypeInfo type = TypeInfoUtils.getTypeInfoFromTypeString(hcatFieldSchema.getTypeString());
        fieldNames.add(hcatFieldSchema.getName());
        fieldInspectors.add(getObjectInspector(type));
    }
    StructObjectInspector structInspector = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldInspectors);
    return structInspector;
}
Also used : ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ArrayList(java.util.ArrayList) IOException(java.io.IOException) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) HCatFieldSchema(org.apache.hive.hcatalog.data.schema.HCatFieldSchema) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Example 40 with ObjectInspectorFactory.getStandardStructObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.

the class DynamicPartitionPruner method prunePartitionSingleSource.

@VisibleForTesting
protected void prunePartitionSingleSource(String source, SourceInfo si) throws HiveException {
    if (si.skipPruning.get()) {
        // in this case we've determined that there's too much data
        // to prune dynamically.
        LOG.info("Skip pruning on " + source + ", column " + si.columnName);
        return;
    }
    Set<Object> values = si.values;
    String columnName = si.columnName;
    if (LOG.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("Pruning ");
        sb.append(columnName);
        sb.append(" with ");
        for (Object value : values) {
            sb.append(value == null ? null : value.toString());
            sb.append(", ");
        }
        LOG.debug(sb.toString());
    }
    ObjectInspector oi = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getPrimitiveTypeInfo(si.columnType));
    Converter converter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaStringObjectInspector, oi);
    StructObjectInspector soi = ObjectInspectorFactory.getStandardStructObjectInspector(Collections.singletonList(columnName), Collections.singletonList(oi));
    @SuppressWarnings("rawtypes") ExprNodeEvaluator eval = ExprNodeEvaluatorFactory.get(si.partKey);
    eval.initialize(soi);
    applyFilterToPartitions(converter, eval, columnName, values);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) Converter(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)78 ArrayList (java.util.ArrayList)73 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)56 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)20 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)16 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)16 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)12 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)11 Text (org.apache.hadoop.io.Text)11 ListTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo)10 MapTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo)10 StructTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo)10 Test (org.junit.Test)10 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)9 StandardStructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector)9 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)8 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)8 IOException (java.io.IOException)7 StandardListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector)7 WritableHiveCharObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveCharObjectInspector)7