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 File: TestNiFiOrcUtils.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: NiFiOrcUtils.java    From localization_nifi with 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 3
Source File: NiFiOrcUtils.java    From nifi with 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 4
Source File: NiFiOrcUtils.java    From nifi with 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 5
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createLong() {
    return TypeInfoFactory.getPrimitiveTypeInfo("bigint");
}
 
Example 6
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createString() {
    return TypeInfoFactory.getPrimitiveTypeInfo("string");
}
 
Example 7
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createBinary() {
    return TypeInfoFactory.getPrimitiveTypeInfo("binary");
}
 
Example 8
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createString() {
    return TypeInfoFactory.getPrimitiveTypeInfo("string");
}
 
Example 9
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createFloat() {
    return TypeInfoFactory.getPrimitiveTypeInfo("float");
}
 
Example 10
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createBoolean() {
    return TypeInfoFactory.getPrimitiveTypeInfo("boolean");
}
 
Example 11
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createLong() {
    return TypeInfoFactory.getPrimitiveTypeInfo("bigint");
}
 
Example 12
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createInt() {
    return TypeInfoFactory.getPrimitiveTypeInfo("int");
}
 
Example 13
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createFloat() {
    return TypeInfoFactory.getPrimitiveTypeInfo("float");
}
 
Example 14
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createBinary() {
    return TypeInfoFactory.getPrimitiveTypeInfo("binary");
}
 
Example 15
Source File: TestNiFiOrcUtils.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createBinary() {
    return TypeInfoFactory.getPrimitiveTypeInfo("binary");
}
 
Example 16
Source File: TestNiFiOrcUtils.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createDouble() {
    return TypeInfoFactory.getPrimitiveTypeInfo("double");
}
 
Example 17
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createInt() {
    return TypeInfoFactory.getPrimitiveTypeInfo("int");
}
 
Example 18
Source File: TestNiFiOrcUtils.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createBoolean() {
    return TypeInfoFactory.getPrimitiveTypeInfo("boolean");
}
 
Example 19
Source File: TestNiFiOrcUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createDouble() {
    return TypeInfoFactory.getPrimitiveTypeInfo("double");
}
 
Example 20
Source File: TestNiFiOrcUtils.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
static TypeInfo createInt() {
    return TypeInfoFactory.getPrimitiveTypeInfo("int");
}