Java Code Examples for org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory#getPrimitiveTypeInfo()

The following examples show how to use org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory#getPrimitiveTypeInfo() . 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 Project: localization_nifi   File: NiFiOrcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static TypeInfo getPrimitiveOrcTypeFromPrimitiveAvroType(Schema.Type avroType) throws IllegalArgumentException {
    if (avroType == null) {
        throw new IllegalArgumentException("Avro type is null");
    }
    switch (avroType) {
        case INT:
            return TypeInfoFactory.getPrimitiveTypeInfo("int");
        case LONG:
            return TypeInfoFactory.getPrimitiveTypeInfo("bigint");
        case BOOLEAN:
            return TypeInfoFactory.getPrimitiveTypeInfo("boolean");
        case BYTES:
            return TypeInfoFactory.getPrimitiveTypeInfo("binary");
        case DOUBLE:
            return TypeInfoFactory.getPrimitiveTypeInfo("double");
        case FLOAT:
            return TypeInfoFactory.getPrimitiveTypeInfo("float");
        case STRING:
            return TypeInfoFactory.getPrimitiveTypeInfo("string");
        default:
            throw new IllegalArgumentException("Avro type " + avroType.getName() + " is not a primitive type");
    }
}
 
Example 2
@Test
public void test_getOrcField_primitive() throws Exception {
    // Expected ORC types
    TypeInfo[] expectedTypes = {
            TypeInfoFactory.getPrimitiveTypeInfo("int"),
            TypeInfoFactory.getPrimitiveTypeInfo("bigint"),
            TypeInfoFactory.getPrimitiveTypeInfo("boolean"),
            TypeInfoFactory.getPrimitiveTypeInfo("float"),
            TypeInfoFactory.getPrimitiveTypeInfo("double"),
            TypeInfoFactory.getPrimitiveTypeInfo("binary"),
            TypeInfoFactory.getPrimitiveTypeInfo("string")
    };

    // Build a fake Avro record with all types
    Schema testSchema = buildPrimitiveAvroSchema();
    List<Schema.Field> fields = testSchema.getFields();
    for (int i = 0; i < fields.size(); i++) {
        assertEquals(expectedTypes[i], NiFiOrcUtils.getOrcField(fields.get(i).schema()));
    }

}
 
Example 3
Source Project: nifi   File: NiFiOrcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static TypeInfo getPrimitiveOrcTypeFromPrimitiveFieldType(DataType rawDataType) throws IllegalArgumentException {
    if (rawDataType == null) {
        throw new IllegalArgumentException("Avro type is null");
    }
    RecordFieldType fieldType = rawDataType.getFieldType();
    if (RecordFieldType.INT.equals(fieldType)) {
        return TypeInfoFactory.getPrimitiveTypeInfo("int");
    }
    if (RecordFieldType.LONG.equals(fieldType)) {
        return TypeInfoFactory.getPrimitiveTypeInfo("bigint");
    }
    if (RecordFieldType.BOOLEAN.equals(fieldType)) {
        return TypeInfoFactory.getPrimitiveTypeInfo("boolean");
    }
    if (RecordFieldType.DOUBLE.equals(fieldType)) {
        return TypeInfoFactory.getPrimitiveTypeInfo("double");
    }
    if (RecordFieldType.FLOAT.equals(fieldType)) {
        return TypeInfoFactory.getPrimitiveTypeInfo("float");
    }
    if (RecordFieldType.STRING.equals(fieldType)) {
        return TypeInfoFactory.getPrimitiveTypeInfo("string");
    }

    throw new IllegalArgumentException("Field type " + fieldType.name() + " is not a primitive type");
}
 
Example 4
Source Project: nifi   File: NiFiOrcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static TypeInfo getPrimitiveOrcTypeFromPrimitiveAvroType(Schema.Type avroType) throws IllegalArgumentException {
    if (avroType == null) {
        throw new IllegalArgumentException("Avro type is null");
    }
    switch (avroType) {
        case INT:
            return TypeInfoFactory.getPrimitiveTypeInfo("int");
        case LONG:
            return TypeInfoFactory.getPrimitiveTypeInfo("bigint");
        case BOOLEAN:
        case NULL: // ORC has no null type, so just pick the smallest. All values are necessarily null.
            return TypeInfoFactory.getPrimitiveTypeInfo("boolean");
        case BYTES:
            return TypeInfoFactory.getPrimitiveTypeInfo("binary");
        case DOUBLE:
            return TypeInfoFactory.getPrimitiveTypeInfo("double");
        case FLOAT:
            return TypeInfoFactory.getPrimitiveTypeInfo("float");
        case STRING:
            return TypeInfoFactory.getPrimitiveTypeInfo("string");
        default:
            throw new IllegalArgumentException("Avro type " + avroType.getName() + " is not a primitive type");
    }
}
 
Example 5
static TypeInfo createInt() {
    return TypeInfoFactory.getPrimitiveTypeInfo("int");
}
 
Example 6
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createDouble() {
    return TypeInfoFactory.getPrimitiveTypeInfo("double");
}
 
Example 7
static TypeInfo createBoolean() {
    return TypeInfoFactory.getPrimitiveTypeInfo("boolean");
}
 
Example 8
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createInt() {
    return TypeInfoFactory.getPrimitiveTypeInfo("int");
}
 
Example 9
static TypeInfo createDouble() {
    return TypeInfoFactory.getPrimitiveTypeInfo("double");
}
 
Example 10
static TypeInfo createBinary() {
    return TypeInfoFactory.getPrimitiveTypeInfo("binary");
}
 
Example 11
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createBinary() {
    return TypeInfoFactory.getPrimitiveTypeInfo("binary");
}
 
Example 12
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createFloat() {
    return TypeInfoFactory.getPrimitiveTypeInfo("float");
}
 
Example 13
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createInt() {
    return TypeInfoFactory.getPrimitiveTypeInfo("int");
}
 
Example 14
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createLong() {
    return TypeInfoFactory.getPrimitiveTypeInfo("bigint");
}
 
Example 15
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createBoolean() {
    return TypeInfoFactory.getPrimitiveTypeInfo("boolean");
}
 
Example 16
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createFloat() {
    return TypeInfoFactory.getPrimitiveTypeInfo("float");
}
 
Example 17
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createString() {
    return TypeInfoFactory.getPrimitiveTypeInfo("string");
}
 
Example 18
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createBinary() {
    return TypeInfoFactory.getPrimitiveTypeInfo("binary");
}
 
Example 19
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createString() {
    return TypeInfoFactory.getPrimitiveTypeInfo("string");
}
 
Example 20
Source Project: nifi   File: TestNiFiOrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
static TypeInfo createLong() {
    return TypeInfoFactory.getPrimitiveTypeInfo("bigint");
}