Java Code Examples for org.apache.arrow.vector.types.pojo.FieldType#nullable()

The following examples show how to use org.apache.arrow.vector.types.pojo.FieldType#nullable() . 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: BatchSchemaFieldTest.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Test
public void testFromFieldWithStructTypes() {
  List<Field> fields = new ArrayList<>();
  fields.add(new Field("string_field", FieldType.nullable(ArrowType.Utf8.INSTANCE), null));
  fields.add(new Field("int_field", FieldType.nullable(
    new ArrowType.Int(32, true)), null));
  fields.add(new Field("bigint_field", FieldType.nullable(
    new ArrowType.Int(64, true)), null));
  fields.add(new Field("float_field", FieldType.nullable(
    new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), null));
  fields.add(new Field("double_field", FieldType.nullable(
    new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), null));
  fields.add(new Field("decimal_field", FieldType.nullable(
    new ArrowType.Decimal(10,5)), null));

  Field struct_field = new Field("struct_field", FieldType.nullable(
    new ArrowType.Struct()), fields);

  String expected = "struct_field: STRUCT<string_field: VARCHAR, " +
    "int_field: INTEGER, bigint_field: BIGINT, float_field: FLOAT, " +
    "double_field: DOUBLE, decimal_field: DECIMAL>";
  Assert.assertEquals(expected, BatchSchemaField.fromField(struct_field).toString());
}
 
Example 2
Source File: ArrowConverter.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param allocator
 * @param name
 * @param data
 * @return
 */
public static IntVector vectorFor(BufferAllocator allocator,String name,int[] data) {
    IntVector float8Vector = new IntVector(name,FieldType.nullable(new ArrowType.Int(32,true)),allocator);
    float8Vector.allocateNew(data.length);
    for(int i = 0; i < data.length; i++) {
        float8Vector.setSafe(i,data[i]);
    }

    float8Vector.setValueCount(data.length);

    return float8Vector;
}
 
Example 3
Source File: FieldBuilder.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new LIST child field with the given name to the builder.
 *
 * @param fieldName The name to use for the newly added child field.
 * @param type The concrete type for values in the List
 * @return This FieldBuilder itself.
 */
public FieldBuilder addListField(String fieldName, ArrowType type)
{
    Field baseField = new Field("", FieldType.nullable(type), null);
    Field field = new Field(fieldName,
            FieldType.nullable(Types.MinorType.LIST.getType()),
            Collections.singletonList(baseField));
    this.children.put(fieldName, field);
    return this;
}
 
Example 4
Source File: ArrowConverter.java    From DataVec with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param allocator
 * @param name
 * @param data
 * @return
 */
public static BigIntVector vectorFor(BufferAllocator allocator,String name,long[] data) {
    BigIntVector float8Vector = new BigIntVector(name,FieldType.nullable(new ArrowType.Int(64,true)),allocator);
    float8Vector.allocateNew(data.length);
    for(int i = 0; i < data.length; i++) {
        float8Vector.setSafe(i,data[i]);
    }

    float8Vector.setValueCount(data.length);

    return float8Vector;
}
 
Example 5
Source File: ArrowConverter.java    From DataVec with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param allocator
 * @param name
 * @return
 */
public static IntVector intVectorOf(BufferAllocator allocator,String name,int length) {
    IntVector float8Vector = new IntVector(name,FieldType.nullable(new ArrowType.Int(32,true)),allocator);
    float8Vector.allocateNew(length);

    float8Vector.setValueCount(length);

    return float8Vector;
}
 
Example 6
Source File: ArrowConverter.java    From DataVec with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param allocator
 * @param name
 * @param data
 * @return
 */
public static IntVector vectorFor(BufferAllocator allocator,String name,int[] data) {
    IntVector float8Vector = new IntVector(name,FieldType.nullable(new ArrowType.Int(32,true)),allocator);
    float8Vector.allocateNew(data.length);
    for(int i = 0; i < data.length; i++) {
        float8Vector.setSafe(i,data[i]);
    }

    float8Vector.setValueCount(data.length);

    return float8Vector;
}
 
Example 7
Source File: ArrowConverter.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param allocator
 * @param name
 * @param data
 * @return
 */
public static BigIntVector vectorFor(BufferAllocator allocator,String name,long[] data) {
    BigIntVector float8Vector = new BigIntVector(name,FieldType.nullable(new ArrowType.Int(64,true)),allocator);
    float8Vector.allocateNew(data.length);
    for(int i = 0; i < data.length; i++) {
        float8Vector.setSafe(i,data[i]);
    }

    float8Vector.setValueCount(data.length);

    return float8Vector;
}
 
Example 8
Source File: ArrowUtils.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static BigIntVector vectorFor(BufferAllocator allocator, String name, long[] data) {
    BigIntVector float8Vector = new BigIntVector(name, FieldType.nullable(new ArrowType.Int(64, true)), allocator);
    float8Vector.allocateNew(data.length);

    for (int i = 0; i < data.length; ++i) {
        float8Vector.setSafe(i, data[i]);
    }

    float8Vector.setValueCount(data.length);
    return float8Vector;
}
 
Example 9
Source File: ArrowUtils.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static IntVector vectorFor(BufferAllocator allocator, String name, int[] data) {
    IntVector float8Vector = new IntVector(name, FieldType.nullable(new ArrowType.Int(32, true)), allocator);
    float8Vector.allocateNew(data.length);

    for (int i = 0; i < data.length; ++i) {
        float8Vector.setSafe(i, data[i]);
    }

    float8Vector.setValueCount(data.length);
    return float8Vector;
}
 
Example 10
Source File: ArrowConverter.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param allocator
 * @param name
 * @return
 */
public static IntVector intVectorOf(BufferAllocator allocator,String name,int length) {
    IntVector float8Vector = new IntVector(name,FieldType.nullable(new ArrowType.Int(32,true)),allocator);
    float8Vector.allocateNew(length);

    float8Vector.setValueCount(length);

    return float8Vector;
}
 
Example 11
Source File: DDBTypeUtils.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
/**
 * Converts from DynamoDB Attribute Type to Arrow type.
 *
 * @param attributeName the DDB Attribute name
 * @param attributeType the DDB Attribute type
 * @return the converted-to Arrow Field
 */
public static Field getArrowFieldFromDDBType(String attributeName, String attributeType)
{
    switch (attributeType) {
        case STRING:
            return new Field(attributeName, FieldType.nullable(Types.MinorType.VARCHAR.getType()), null);
        case NUMBER:
            return new Field(attributeName, FieldType.nullable(new ArrowType.Decimal(38, 9)), null);
        case BOOLEAN:
            return new Field(attributeName, FieldType.nullable(Types.MinorType.BIT.getType()), null);
        case BINARY:
            return new Field(attributeName, FieldType.nullable(Types.MinorType.VARBINARY.getType()), null);
        case STRING_SET:
            return new Field(attributeName, FieldType.nullable(Types.MinorType.LIST.getType()),
                    Collections.singletonList(new Field("", FieldType.nullable(Types.MinorType.VARCHAR.getType()), null)));
        case NUMBER_SET:
            return new Field(attributeName, FieldType.nullable(Types.MinorType.LIST.getType()),
                    Collections.singletonList(new Field("", FieldType.nullable(new ArrowType.Decimal(38, 9)), null)));
        case BINARY_SET:
            return new Field(attributeName, FieldType.nullable(Types.MinorType.LIST.getType()),
                    Collections.singletonList(new Field("", FieldType.nullable(Types.MinorType.VARBINARY.getType()), null)));
        case LIST:
            return new Field(attributeName, FieldType.nullable(Types.MinorType.LIST.getType()), null);
        case MAP:
            return new Field(attributeName, FieldType.nullable(Types.MinorType.STRUCT.getType()), null);
        default:
            throw new RuntimeException("Unknown type[" + attributeType + "] for field[" + attributeName + "]");
    }
}
 
Example 12
Source File: ArrowUtils.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
public static BigIntVector longVectorOf(BufferAllocator allocator, String name, int length) {
    BigIntVector float8Vector = new BigIntVector(name, FieldType.nullable(new ArrowType.Int(64, true)), allocator);
    float8Vector.allocateNew(length);
    float8Vector.setValueCount(length);
    return float8Vector;
}
 
Example 13
Source File: ArrowUtils.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
public static IntVector intVectorOf(BufferAllocator allocator, String name, int length) {
    IntVector float8Vector = new IntVector(name, FieldType.nullable(new ArrowType.Int(32, true)), allocator);
    float8Vector.allocateNew(length);
    float8Vector.setValueCount(length);
    return float8Vector;
}
 
Example 14
Source File: UserDefinedFunctionHandlerTest.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
private Field getArrowField(Class type, String columnName)
{
    if (type == Integer.class) {
        return new Field(columnName, FieldType.nullable(new ArrowType.Int(32, true)), null);
    }

    if (type == Float.class) {
        return new Field(columnName, FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), null);
    }

    if (type == Double.class) {
        return new Field(columnName, FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), null);
    }

    if (type == String.class) {
        return new Field(columnName, FieldType.nullable(new ArrowType.Utf8()), null);
    }

    if (type == Boolean.class) {
        return new Field(columnName, FieldType.nullable(new ArrowType.Bool()), null);
    }

    if (type == List.class) {
        Field childField = new Field(columnName, FieldType.nullable(new ArrowType.Int(32, true)), null);
        return new Field(columnName, FieldType.nullable(Types.MinorType.LIST.getType()),
                Collections.singletonList(childField));
    }

    if (type == Map.class) {
        FieldBuilder fieldBuilder = FieldBuilder.newBuilder(columnName, Types.MinorType.STRUCT.getType());

        Field childField1 = new Field("intVal", FieldType.nullable(new ArrowType.Int(32, true)), null);
        Field childField2 = new Field("doubleVal", FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), null);
        ;

        fieldBuilder.addField(childField1);
        fieldBuilder.addField(childField2);

        return fieldBuilder.build();
    }

    throw new IllegalArgumentException("Unsupported type " + type);
}
 
Example 15
Source File: ArrowConverter.java    From deeplearning4j with Apache License 2.0 3 votes vote down vote up
/**
 *
 * @param allocator
 * @param name
 * @param length the number of rows in the column vector
 * @return
 */
public static BigIntVector longVectorOf(BufferAllocator allocator,String name,int length) {
    BigIntVector float8Vector = new BigIntVector(name,FieldType.nullable(new ArrowType.Int(64,true)),allocator);
    float8Vector.allocateNew(length);
    float8Vector.setValueCount(length);
    return float8Vector;
}
 
Example 16
Source File: ArrowConverter.java    From DataVec with Apache License 2.0 3 votes vote down vote up
/**
 *
 * @param allocator
 * @param name
 * @param length the number of rows in the column vector
 * @return
 */
public static BigIntVector longVectorOf(BufferAllocator allocator,String name,int length) {
    BigIntVector float8Vector = new BigIntVector(name,FieldType.nullable(new ArrowType.Int(64,true)),allocator);
    float8Vector.allocateNew(length);
    float8Vector.setValueCount(length);
    return float8Vector;
}
 
Example 17
Source File: MutableVarcharVector.java    From dremio-oss with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiate a MutableVarcharVector. This doesn't allocate any memory for
 * the data in vector.
 *
 * @param name                name of the vector
 * @param allocator           allocator for memory management.
 * @param compactionThreshold this value bounds the ratio of garbage data to capacity of the buffer. If the ratio
 *                            is more than the threshold, then compaction gets triggered on next update.
 */
public MutableVarcharVector(String name, BufferAllocator allocator, double compactionThreshold) {
  this(name, FieldType.nullable(MinorType.VARCHAR.getType()), allocator, compactionThreshold);
}
 
Example 18
Source File: ArrowConverter.java    From DataVec with Apache License 2.0 2 votes vote down vote up
/**
 * Shortcut method for returning a field
 * given an arrow type and name
 * with no sub fields
 * @param name the name of the field
 * @param arrowType the arrow type of the field
 * @return the resulting field
 */
public static Field field(String name,ArrowType arrowType) {
    return new Field(name,FieldType.nullable(arrowType), new ArrayList<Field>());
}
 
Example 19
Source File: ArrowConverter.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Shortcut method for returning a field
 * given an arrow type and name
 * with no sub fields
 * @param name the name of the field
 * @param arrowType the arrow type of the field
 * @return the resulting field
 */
public static Field field(String name,ArrowType arrowType) {
    return new Field(name,FieldType.nullable(arrowType), new ArrayList<Field>());
}
 
Example 20
Source File: FieldBuilder.java    From aws-athena-query-federation with Apache License 2.0 2 votes vote down vote up
/**
 * Builds the fields.
 *
 * @return The newly constructed Field.
 */
public Field build()
{
    return new Field(name, FieldType.nullable(type), new ArrayList<>(children.values()));
}