org.apache.arrow.vector.types.pojo.FieldType Java Examples

The following examples show how to use org.apache.arrow.vector.types.pojo.FieldType. 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: BaseRepeatedValueVectorHelper.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void load(SerializedField metadata, ArrowBuf buffer) {
  /* release the current buffers (if any) */
  vector.clear();

  /* get the metadata for all children */
  final SerializedField offsetMetadata = metadata.getChild(0);
  final SerializedField vectorMetadata = metadata.getChild(1);
  final int offsetLength = offsetMetadata.getBufferLength();
  final int vectorLength = vectorMetadata.getBufferLength();

  /* load inner offset buffer */
  loadOffsetBuffer(offsetMetadata, buffer);

  /* load inner data vector */
  if (vector.getDataVector() == BaseRepeatedValueVector.DEFAULT_DATA_VECTOR) {
    vector.addOrGetVector(FieldType.nullable(getArrowMinorType(metadata.getMajorType().getMinorType()).getType()));
  }

  TypeHelper.load(vector.vector, vectorMetadata, buffer.slice(offsetLength, vectorLength));
}
 
Example #2
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 #3
Source File: ListVectorHelper.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void load(SerializedField metadata, ArrowBuf buffer) {
  /* release the current buffers (if any) */
  listVector.clear();

  /* load inner offset buffer */
  final SerializedField offsetMetadata = metadata.getChild(0);
  final int offsetLength = offsetMetadata.getBufferLength();
  loadOffsetBuffer(offsetMetadata, buffer);

  /* load inner validity buffer */
  final SerializedField bitMetadata = metadata.getChild(1);
  final int bitLength = bitMetadata.getBufferLength();
  loadValidityBuffer(bitMetadata, buffer.slice(offsetLength, bitLength));

  /* load inner data vector */
  final SerializedField vectorMetadata = metadata.getChild(2);
  if (listVector.getDataVector() == BaseRepeatedValueVector.DEFAULT_DATA_VECTOR) {
    listVector.addOrGetVector(FieldType.nullable(getArrowMinorType(vectorMetadata.getMajorType().getMinorType()).getType()));
  }

  final int vectorLength = vectorMetadata.getBufferLength();
  TypeHelper.load(listVector.vector, vectorMetadata, buffer.slice(offsetLength + bitLength, vectorLength));
  listVector.setLastSet(metadata.getValueCount() - 1);
  listVector.valueCount = metadata.getValueCount();
}
 
Example #4
Source File: ArrowUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
private static Field toArrowField(String fieldName, LogicalType logicalType) {
	FieldType fieldType = new FieldType(
		logicalType.isNullable(),
		logicalType.accept(LogicalTypeToArrowTypeConverter.INSTANCE),
		null);
	List<Field> children = null;
	if (logicalType instanceof ArrayType) {
		children = Collections.singletonList(toArrowField(
			"element", ((ArrayType) logicalType).getElementType()));
	} else if (logicalType instanceof RowType) {
		RowType rowType = (RowType) logicalType;
		children = new ArrayList<>(rowType.getFieldCount());
		for (RowType.RowField field : rowType.getFields()) {
			children.add(toArrowField(field.getName(), field.getType()));
		}
	}
	return new Field(fieldName, fieldType, children);
}
 
Example #5
Source File: CustomGeneratorWithSV2.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public CustomGeneratorWithSV2(int numRows, BufferAllocator allocator, SelectionVariant variant) {
  Preconditions.checkState(numRows > 0);
  this.numRows = numRows;
  this.stringValues = listOfStrings(numRows);
  this.intValues = randomListOfInts(numRows);
  this.longValues = randomListOfLongs(numRows);
  this.decimalValues = randomListOfDecimals(numRows);
  this.listValues = listOfLists(numRows);
  this.bitValues = randomBits(numRows);
  this.selectedBitSet = new BitSet(numRows);
  this.totalSelectedRows = 0;
  computeSelection(variant);

  this.sv2 = new SelectionVector2(allocator);
  this.container = new VectorContainerWithSV(allocator, sv2);
  this.bitVector = container.addOrGet(BITF);
  this.intVector = container.addOrGet(INTF);
  this.bigIntVector = container.addOrGet(BIGINTF);
  this.decimalVector = container.addOrGet(DECIMALF);
  this.stringVector = container.addOrGet(STRINGF);
  this.listVector = container.addOrGet(LISTF);
  container.buildSchema(SelectionVectorMode.TWO_BYTE);
  listVector.addOrGetVector(FieldType.nullable(MinorType.BIGINT.getType()));
}
 
Example #6
Source File: CustomGenerator.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public CustomGenerator(int numRows, BufferAllocator allocator) {
  Preconditions.checkState(numRows > 0);
  values = listOfStrings(numRows);
  rowIds = randomListOfInts(numRows);
  listValues = listOfLists(numRows);

  BatchSchema schema = BatchSchema.newBuilder()
          .addField(ID)
          .addField(VALUE)
          .addField(MYLIST)
          .build();

  container = VectorContainer.create(allocator, schema);
  id = container.addOrGet(ID);
  value = container.addOrGet(VALUE);
  list = container.addOrGet(MYLIST);
  Types.MinorType type = Types.MinorType.BIGINT;
  list.addOrGetVector(FieldType.nullable(type.getType()));
}
 
Example #7
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 #8
Source File: IntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBooleanWithScale() throws SFException
{
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");
  customFieldMeta.put("precision", "10");
  customFieldMeta.put("scale", "3");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.INT.getType(),
                                      null, customFieldMeta);

  IntVector vector = new IntVector("col_one", fieldType, allocator);
  vector.setSafe(0, 0);
  vector.setSafe(1, 1);
  vector.setNull(2);
  vector.setSafe(3, 5);

  final ArrowVectorConverter converter = new IntToScaledFixedConverter(vector, 0, this, 3);

  assertThat(false, is(converter.toBoolean(0)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));
  assertThat(false, is(converter.toBoolean(2)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));

  vector.close();
}
 
Example #9
Source File: ArrowResultChunkIndexSorter.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
/**
 * initialize original indices
 */
private void initIndices()
{
  BufferAllocator rootAllocator = resultChunk.get(0).getAllocator();
  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.INT.getType(),
                                      null, null);

  indices = new IntVector("indices", fieldType, rootAllocator);
  IntStream.range(0, resultChunk.get(0).getValueCount()).forEach(i -> indices.setSafe(i, i));
}
 
Example #10
Source File: BatchSchemaFieldTest.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromFieldWithPrimitiveTypes() {
  List<Field> fields = new ArrayList<>();
  List<String> expectedType = new ArrayList<>();
  fields.add(new Field("string_field", FieldType.nullable(ArrowType.Utf8.INSTANCE), null));
  expectedType.add("string_field: VARCHAR");

  fields.add(new Field("int_field", FieldType.nullable(
    new ArrowType.Int(32, true)), null));
  expectedType.add("int_field: INTEGER");

  fields.add(new Field("bigint_field", FieldType.nullable(
    new ArrowType.Int(64, true)), null));
  expectedType.add("bigint_field: BIGINT");

  fields.add(new Field("float_field", FieldType.nullable(
    new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), null));
  expectedType.add("float_field: FLOAT");

  fields.add(new Field("double_field", FieldType.nullable(
    new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), null));
  expectedType.add("double_field: DOUBLE");

  fields.add(new Field("decimal_field", FieldType.nullable(
    new ArrowType.Decimal(10,5)), null));
  expectedType.add("decimal_field: DECIMAL");

  Assert.assertEquals(fields.size(), expectedType.size());
  for(int pos = 0; pos < fields.size(); ++pos) {
    Assert.assertEquals(expectedType.get(pos), BatchSchemaField.fromField(fields.get(pos)).toString());
  }
}
 
Example #11
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 #12
Source File: BackwardCompatibleSchemaDe.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Field deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
  JsonNode node = jsonParser.getCodec().readTree(jsonParser);

  JsonNode nameNode = node.get("name");
  final String name;
  if (nameNode instanceof NullNode) {
    name = null;
  } else {
    name = nameNode.asText();
  }

  boolean nullable = node.get("nullable").asBoolean();

  JsonNode arrowTypeNode = node.get("type");
  ArrowType arrowType = mapper.convertValue(arrowTypeNode, ArrowType.class);
  JsonNode dictionaryNode = node.get("dictionary");
  DictionaryEncoding dictionary = mapper.convertValue(dictionaryNode, DictionaryEncoding.class);
  JsonNode childrenNode = node.get("children");

  List<Field> children = fieldsReader.readValue(childrenNode);

  JsonNode metadataNode = node.get("metadata");
  Map<String,String> metadata = mapper.convertValue(metadataNode, Map.class);

  FieldType fieldType = new FieldType(nullable, arrowType, dictionary, metadata);
  return new Field(name, fieldType, children);
}
 
Example #13
Source File: TestArrowFileReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/** Helper method which creates a empty list vector */
private static ListVector testEmptyListVector(BufferAllocator allocator) {
  final ListVector vector =
      new ListVector("emptyListVector", allocator, FieldType.nullable(ArrowType.Null.INSTANCE), null);
  vector.allocateNew();
  return vector;
}
 
Example #14
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 #15
Source File: SmallIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidConversion()
{
  // try convert to int/long/byte/short with scale > 0
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");
  customFieldMeta.put("precision", "10");
  customFieldMeta.put("scale", "3");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.SMALLINT.getType(),
                                      null, customFieldMeta);

  SmallIntVector vector = new SmallIntVector("col_one", fieldType, allocator);
  vector.setSafe(0, 200);

  final ArrowVectorConverter converter = new SmallIntToScaledFixedConverter(vector, 0, this, 3);
  final int invalidConversionErrorCode =
      ErrorCode.INVALID_VALUE_CONVERT.getMessageCode();

  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toLong(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toInt(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toShort(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toByte(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toDate(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toTime(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toTimestamp(0, TimeZone.getDefault()));
  vector.clear();
}
 
Example #16
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 #17
Source File: BigIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBooleanWithScale() throws SFException
{
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");
  customFieldMeta.put("precision", "10");
  customFieldMeta.put("scale", "3");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.BIGINT.getType(),
                                      null, customFieldMeta);

  BigIntVector vector = new BigIntVector("col_one", fieldType, allocator);
  vector.setSafe(0, 0);
  vector.setSafe(1, 1);
  vector.setNull(2);
  vector.setSafe(3, 5);

  final ArrowVectorConverter converter = new BigIntToScaledFixedConverter(vector, 0, this, 3);

  assertThat(false, is(converter.toBoolean(0)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));
  assertThat(false, is(converter.toBoolean(2)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));

  vector.close();
}
 
Example #18
Source File: SmallIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBooleanWithScale() throws SFException
{
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");
  customFieldMeta.put("precision", "10");
  customFieldMeta.put("scale", "3");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.SMALLINT.getType(),
                                      null, customFieldMeta);

  SmallIntVector vector = new SmallIntVector("col_one", fieldType, allocator);
  vector.setSafe(0, 0);
  vector.setSafe(1, 1);
  vector.setNull(2);
  vector.setSafe(3, 5);

  final ArrowVectorConverter converter = new SmallIntToScaledFixedConverter(vector, 0, this, 3);

  assertThat(false, is(converter.toBoolean(0)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));
  assertThat(false, is(converter.toBoolean(2)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));

  vector.close();
}
 
Example #19
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 #20
Source File: TinyIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidConversion()
{
  // try convert to int/long/byte/short with scale > 0
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");
  customFieldMeta.put("precision", "10");
  customFieldMeta.put("scale", "1");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.TINYINT.getType(),
                                      null, customFieldMeta);

  TinyIntVector vector = new TinyIntVector("col_one", fieldType, allocator);
  vector.setSafe(0, 200);

  final ArrowVectorConverter converter = new TinyIntToScaledFixedConverter(vector, 0, this, 1);
  final int invalidConversionErrorCode =
      ErrorCode.INVALID_VALUE_CONVERT.getMessageCode();

  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toLong(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toInt(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toShort(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toDate(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toTime(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toTimestamp(0, TimeZone.getDefault()));
  vector.clear();
}
 
Example #21
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 #22
Source File: BigIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidConversion()
{
  // try convert to int/long/byte/short with scale > 0
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");
  customFieldMeta.put("precision", "10");
  customFieldMeta.put("scale", "3");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.BIGINT.getType(),
                                      null, customFieldMeta);

  BigIntVector vector = new BigIntVector("col_one", fieldType, allocator);
  vector.setSafe(0, 123456789L);

  final ArrowVectorConverter converter = new BigIntToScaledFixedConverter(vector, 0, this, 3);

  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toLong(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toInt(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toShort(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toByte(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toDate(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toTime(0));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toTimestamp(0, TimeZone.getDefault()));
  vector.clear();
}
 
Example #23
Source File: ElasticsearchQueryUtilsTest.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp()
{
    mapping = SchemaBuilder.newBuilder()
            .addField("mytext", Types.MinorType.VARCHAR.getType())
            .addField("mykeyword", Types.MinorType.VARCHAR.getType())
            .addField(new Field("mylong", FieldType.nullable(Types.MinorType.LIST.getType()),
                    Collections.singletonList(new Field("mylong",
                            FieldType.nullable(Types.MinorType.BIGINT.getType()), null))))
            .addField("myinteger", Types.MinorType.INT.getType())
            .addField("myshort", Types.MinorType.INT.getType())
            .addField("mybyte", Types.MinorType.TINYINT.getType())
            .addField("mydouble", Types.MinorType.FLOAT8.getType())
            .addField(new Field("myscaled",
                    new FieldType(true, Types.MinorType.BIGINT.getType(), null,
                            ImmutableMap.of("scaling_factor", "10.51")), null))
            .addField("myfloat", Types.MinorType.FLOAT4.getType())
            .addField("myhalf", Types.MinorType.FLOAT4.getType())
            .addField("mydatemilli", Types.MinorType.DATEMILLI.getType())
            .addField(new Field("mydatenano", FieldType.nullable(Types.MinorType.LIST.getType()),
                    Collections.singletonList(new Field("mydatenano",
                            FieldType.nullable(Types.MinorType.DATEMILLI.getType()), null))))
            .addField("myboolean", Types.MinorType.BIT.getType())
            .addField("mybinary", Types.MinorType.VARCHAR.getType())
            .addField("mynested", Types.MinorType.STRUCT.getType(), ImmutableList.of(
                    new Field("l1long", FieldType.nullable(Types.MinorType.BIGINT.getType()), null),
                    new Field("l1date", FieldType.nullable(Types.MinorType.DATEMILLI.getType()), null),
                    new Field("l1nested", FieldType.nullable(Types.MinorType.STRUCT.getType()), ImmutableList.of(
                            new Field("l2short", FieldType.nullable(Types.MinorType.LIST.getType()),
                                    Collections.singletonList(new Field("l2short",
                                            FieldType.nullable(Types.MinorType.INT.getType()), null))),
                            new Field("l2binary", FieldType.nullable(Types.MinorType.VARCHAR.getType()),
                                    null))))).build();
}
 
Example #24
Source File: Producer.java    From dremio-flight-connector with Apache License 2.0 5 votes vote down vote up
private Schema fromMetadata(List<ResultColumnMetadata> rcmd) {

      Schema schema = new Schema(rcmd.stream().map(md -> {
        ArrowType arrowType = SqlTypeNameToArrowType.toArrowType(md);
        FieldType fieldType = new FieldType(md.getIsNullable(), arrowType, null, null);
        return new Field(md.getColumnName(), fieldType, null);
      }).collect(Collectors.toList()));
      return schema;
    }
 
Example #25
Source File: DirectArrowLoader.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * FileReader and Arrow memory allocators are set and initialized.
 */
public DirectArrowLoader(
    final IRootMemoryAllocator rootMemoryAllocator ,
    final YosegiReader reader ,
    final BufferAllocator allocator ) {
  this.reader = reader;
  this.allocator = allocator;
  this.rootMemoryAllocator = rootMemoryAllocator;
  SchemaChangeCallBack callBack = new SchemaChangeCallBack();
  rootVector = new StructVector(
      "root" , allocator , new FieldType( true , Struct.INSTANCE , null , null ) , callBack );
}
 
Example #26
Source File: DynamicArrowLoader.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * FileReader and Arrow memory allocators are set and initialized.
 */
public DynamicArrowLoader(
    final IRootMemoryAllocator rootMemoryAllocator ,
    final YosegiReader reader ,
    final BufferAllocator allocator ) {
  this.reader = reader;
  this.allocator = allocator;
  this.rootMemoryAllocator = rootMemoryAllocator;
  SchemaChangeCallBack callBack = new SchemaChangeCallBack();
  rootVector = new StructVector(
      "root" , allocator , new FieldType( true , Struct.INSTANCE , null , null ) , callBack );
}
 
Example #27
Source File: TinyIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBooleanWithScale() throws SFException
{
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");
  customFieldMeta.put("precision", "10");
  customFieldMeta.put("scale", "3");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.TINYINT.getType(),
                                      null, customFieldMeta);

  TinyIntVector vector = new TinyIntVector("col_one", fieldType, allocator);
  vector.setSafe(0, 0);
  vector.setSafe(1, 1);
  vector.setNull(2);
  vector.setSafe(3, 5);

  final ArrowVectorConverter converter = new TinyIntToScaledFixedConverter(vector, 0, this, 3);

  assertThat(false, is(converter.toBoolean(0)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));
  assertThat(false, is(converter.toBoolean(2)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));

  vector.close();
}
 
Example #28
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 #29
Source File: TinyIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSmallerIntegralType() throws SFException
{
  // try convert to int/long/byte/short with scale > 0
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");
  customFieldMeta.put("precision", "10");
  customFieldMeta.put("scale", "0");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.TINYINT.getType(),
                                      null, customFieldMeta);

  // test value which is in range of byte, all get method should return
  TinyIntVector vectorBar = new TinyIntVector("col_one", fieldType,
                                              allocator);
  // set value which is out of range of int, but falls in long
  vectorBar.setSafe(0, 10);
  vectorBar.setSafe(1, -10);

  final ArrowVectorConverter converterBar =
      new TinyIntToFixedConverter(vectorBar, 0, this);

  assertThat(converterBar.toShort(0), is((short) 10));
  assertThat(converterBar.toShort(1), is((short) -10));
  assertThat(converterBar.toInt(0), is(10));
  assertThat(converterBar.toInt(1), is(-10));
  assertThat(converterBar.toLong(0), is(10L));
  assertThat(converterBar.toLong(1), is(-10L));
  vectorBar.clear();
}
 
Example #30
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;
}