org.apache.arrow.vector.TinyIntVector Java Examples

The following examples show how to use org.apache.arrow.vector.TinyIntVector. 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: TestData.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private Pair<TinyIntVector, ResultVerifier> testTinyIntVector() {
  final String colName = "colTinyInt";
  final List<Byte> values =  asList((byte)0, (byte)-1, (byte)1, null, (byte)-54);

  TinyIntVector valuesVector = new TinyIntVector(colName, allocator);
  valuesVector.allocateNew(values.size());
  for (int i = 0; i < values.size(); i++) {
    if (values.get(i) == null) {
      valuesVector.setNull(i);
    } else {
      valuesVector.set(i, values.get(i));
    }
  }

  ResultVerifier verifier = new ResultVerifier() {
    @Override
    public void verify(DataPOJO output) {
      verifyIntValues(values, output, colName);
    }
  };

  return Pair.of(valuesVector, verifier);
}
 
Example #2
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 #3
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 #4
Source File: TinyIntWriter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void doWrite(T in, int ordinal) {
	if (isNullAt(in, ordinal)) {
		((TinyIntVector) getValueVector()).setNull(getCount());
	} else {
		((TinyIntVector) getValueVector()).setSafe(getCount(), readByte(in, ordinal));
	}
}
 
Example #5
Source File: TinyIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBooleanNoScale() throws SFException
{
  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);

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

  ArrowVectorConverter converter = new TinyIntToFixedConverter(vector, 0, this);

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

  vector.close();
}
 
Example #6
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 #7
Source File: TestArrowByteConnector.java    From yosegi with Apache License 2.0 5 votes vote down vote up
@Test
public void T_convert_1() throws IOException{
  BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 );
  TinyIntVector vector = new TinyIntVector( "test" , allocator );
  vector.allocateNew();
  vector.setSafe( 0 , (byte)0 );
  vector.setSafe( 1 , (byte)1 );
  vector.setSafe( 2 , (byte)0 );
  vector.setNull( 3 );
  vector.setSafe( 4 , (byte)1 );
  vector.setSafe( 5 , (byte)1 );
  vector.setSafe( 6 , (byte)1 );
  vector.setNull( 7 );
  vector.setValueCount( 8 );

  IColumn column = ArrowColumnFactory.convert( "test" , vector );
  assertEquals( column.getColumnName() , "test" );
  assertEquals( column.size() , 8 );
  assertTrue( ( column.getColumnType() == ColumnType.BYTE ) );
  assertEquals( ( (PrimitiveObject)( column.get(0).getRow() ) ).getByte() , (byte)0  );
  assertEquals( ( (PrimitiveObject)( column.get(1).getRow() ) ).getByte() , (byte)1  );
  assertEquals( ( (PrimitiveObject)( column.get(2).getRow() ) ).getByte() , (byte)0  );
  assertEquals( column.get(3).getRow() , null  );
  assertEquals( ( (PrimitiveObject)( column.get(4).getRow() ) ).getByte() , (byte)1 );
  assertEquals( ( (PrimitiveObject)( column.get(5).getRow() ) ).getByte() , (byte)1 );
  assertEquals( ( (PrimitiveObject)( column.get(6).getRow() ) ).getByte() , (byte)1 );
  assertEquals( column.get(7).getRow() , null  );
}
 
Example #8
Source File: RowTinyIntWriter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void doWrite(Row value, int ordinal) {
	if (value.getField(ordinal) == null) {
		((TinyIntVector) getValueVector()).setNull(getCount());
	} else {
		((TinyIntVector) getValueVector()).setSafe(getCount(), (byte) value.getField(ordinal));
	}
}
 
Example #9
Source File: TinyIntToFixedConverter.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] toBytes(int index) throws SFException
{
  if (tinyIntVector.isNull(index))
  {
    return null;
  }
  ByteBuffer bytes = ByteBuffer.allocate(TinyIntVector.TYPE_WIDTH);
  tinyIntVector.getDataBuffer().getBytes(index, bytes);
  return bytes.array();
}
 
Example #10
Source File: TinyIntToFixedConverter.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
public TinyIntToFixedConverter(ValueVector fieldVector, int columnIndex, DataConversionContext context)
{
  super(String.format("%s(%s,%s)", SnowflakeType.FIXED,
                      fieldVector.getField().getMetadata().get("precision"),
                      fieldVector.getField().getMetadata().get("scale")),
        fieldVector,
        columnIndex,
        context);
  this.tinyIntVector = (TinyIntVector) fieldVector;
}
 
Example #11
Source File: TestArrowByteConnector.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
@Test
public void T_convert_1() throws IOException{
  BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 );
  TinyIntVector vector = new TinyIntVector( "test" , allocator );
  vector.allocateNew();
  vector.setSafe( 0 , (byte)0 );  
  vector.setSafe( 1 , (byte)1 );  
  vector.setSafe( 2 , (byte)0 );  
  vector.setNull( 3 );  
  vector.setSafe( 4 , (byte)1 );  
  vector.setSafe( 5 , (byte)1 );  
  vector.setSafe( 6 , (byte)1 );  
  vector.setNull( 7 );  
  vector.setValueCount( 8 );

  IColumn column = ArrowColumnFactory.convert( "test" , vector );
  assertEquals( column.getColumnName() , "test" );
  assertEquals( column.size() , 8 );
  assertTrue( ( column.getColumnType() == ColumnType.BYTE ) );
  assertEquals( ( (PrimitiveObject)( column.get(0).getRow() ) ).getByte() , (byte)0  );
  assertEquals( ( (PrimitiveObject)( column.get(1).getRow() ) ).getByte() , (byte)1  );
  assertEquals( ( (PrimitiveObject)( column.get(2).getRow() ) ).getByte() , (byte)0  );
  assertEquals( column.get(3).getRow() , null  );
  assertEquals( ( (PrimitiveObject)( column.get(4).getRow() ) ).getByte() , (byte)1 );
  assertEquals( ( (PrimitiveObject)( column.get(5).getRow() ) ).getByte() , (byte)1 );
  assertEquals( ( (PrimitiveObject)( column.get(6).getRow() ) ).getByte() , (byte)1 );
  assertEquals( column.get(7).getRow() , null  );
}
 
Example #12
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static ArrowFieldWriter<ArrayData> createArrowFieldWriterForArray(ValueVector vector, LogicalType fieldType) {
	if (vector instanceof TinyIntVector) {
		return TinyIntWriter.forArray((TinyIntVector) vector);
	} else if (vector instanceof SmallIntVector) {
		return SmallIntWriter.forArray((SmallIntVector) vector);
	} else if (vector instanceof IntVector) {
		return IntWriter.forArray((IntVector) vector);
	} else if (vector instanceof BigIntVector) {
		return BigIntWriter.forArray((BigIntVector) vector);
	} else if (vector instanceof BitVector) {
		return BooleanWriter.forArray((BitVector) vector);
	} else if (vector instanceof Float4Vector) {
		return FloatWriter.forArray((Float4Vector) vector);
	} else if (vector instanceof Float8Vector) {
		return DoubleWriter.forArray((Float8Vector) vector);
	} else if (vector instanceof VarCharVector) {
		return VarCharWriter.forArray((VarCharVector) vector);
	} else if (vector instanceof VarBinaryVector) {
		return VarBinaryWriter.forArray((VarBinaryVector) vector);
	} else if (vector instanceof DecimalVector) {
		DecimalVector decimalVector = (DecimalVector) vector;
		return DecimalWriter.forArray(decimalVector, getPrecision(decimalVector), decimalVector.getScale());
	} else if (vector instanceof DateDayVector) {
		return DateWriter.forArray((DateDayVector) vector);
	} else if (vector instanceof TimeSecVector || vector instanceof TimeMilliVector ||
		vector instanceof TimeMicroVector || vector instanceof TimeNanoVector) {
		return TimeWriter.forArray(vector);
	} else if (vector instanceof TimeStampVector && ((ArrowType.Timestamp) vector.getField().getType()).getTimezone() == null) {
		int precision;
		if (fieldType instanceof LocalZonedTimestampType) {
			precision = ((LocalZonedTimestampType) fieldType).getPrecision();
		} else {
			precision = ((TimestampType) fieldType).getPrecision();
		}
		return TimestampWriter.forArray(vector, precision);
	} else if (vector instanceof ListVector) {
		ListVector listVector = (ListVector) vector;
		LogicalType elementType = ((ArrayType) fieldType).getElementType();
		return ArrayWriter.forArray(listVector, createArrowFieldWriterForArray(listVector.getDataVector(), elementType));
	} else if (vector instanceof StructVector) {
		RowType rowType = (RowType) fieldType;
		ArrowFieldWriter<RowData>[] fieldsWriters = new ArrowFieldWriter[rowType.getFieldCount()];
		for (int i = 0; i < fieldsWriters.length; i++) {
			fieldsWriters[i] = createArrowFieldWriterForRow(
				((StructVector) vector).getVectorById(i),
				rowType.getTypeAt(i));
		}
		return RowWriter.forArray((StructVector) vector, fieldsWriters);
	} else {
		throw new UnsupportedOperationException(String.format(
			"Unsupported type %s.", fieldType));
	}
}
 
Example #13
Source File: ArrowTinyIntColumnVector.java    From flink with Apache License 2.0 4 votes vote down vote up
public ArrowTinyIntColumnVector(TinyIntVector tinyIntVector) {
	this.tinyIntVector = Preconditions.checkNotNull(tinyIntVector);
}
 
Example #14
Source File: TinyIntFieldReader.java    From flink with Apache License 2.0 4 votes vote down vote up
public TinyIntFieldReader(TinyIntVector tinyIntVector) {
	super(tinyIntVector);
}
 
Example #15
Source File: TinyIntFieldReader.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Byte read(int index) {
	return ((TinyIntVector) getValueVector()).getObject(index);
}
 
Example #16
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static ArrowFieldWriter<Row> createRowArrowFieldWriter(ValueVector vector, LogicalType fieldType) {
	if (vector instanceof TinyIntVector) {
		return new RowTinyIntWriter((TinyIntVector) vector);
	} else if (vector instanceof SmallIntVector) {
		return new RowSmallIntWriter((SmallIntVector) vector);
	} else if (vector instanceof IntVector) {
		return new RowIntWriter((IntVector) vector);
	} else if (vector instanceof BigIntVector) {
		return new RowBigIntWriter((BigIntVector) vector);
	} else if (vector instanceof BitVector) {
		return new RowBooleanWriter((BitVector) vector);
	} else if (vector instanceof Float4Vector) {
		return new RowFloatWriter((Float4Vector) vector);
	} else if (vector instanceof Float8Vector) {
		return new RowDoubleWriter((Float8Vector) vector);
	} else if (vector instanceof VarCharVector) {
		return new RowVarCharWriter((VarCharVector) vector);
	} else if (vector instanceof VarBinaryVector) {
		return new RowVarBinaryWriter((VarBinaryVector) vector);
	} else if (vector instanceof DecimalVector) {
		DecimalVector decimalVector = (DecimalVector) vector;
		return new RowDecimalWriter(decimalVector, getPrecision(decimalVector), decimalVector.getScale());
	} else if (vector instanceof DateDayVector) {
		return new RowDateWriter((DateDayVector) vector);
	} else if (vector instanceof TimeSecVector || vector instanceof TimeMilliVector ||
		vector instanceof TimeMicroVector || vector instanceof TimeNanoVector) {
		return new RowTimeWriter(vector);
	} else if (vector instanceof TimeStampVector && ((ArrowType.Timestamp) vector.getField().getType()).getTimezone() == null) {
		return new RowTimestampWriter(vector);
	} else if (vector instanceof ListVector) {
		ListVector listVector = (ListVector) vector;
		LogicalType elementType = ((ArrayType) fieldType).getElementType();
		return new RowArrayWriter(listVector, createRowArrowFieldWriter(listVector.getDataVector(), elementType));
	} else if (vector instanceof StructVector) {
		RowType rowType = (RowType) fieldType;
		ArrowFieldWriter<Row>[] fieldsWriters = new ArrowFieldWriter[rowType.getFieldCount()];
		for (int i = 0; i < fieldsWriters.length; i++) {
			fieldsWriters[i] = createRowArrowFieldWriter(
				((StructVector) vector).getVectorById(i),
				rowType.getTypeAt(i));
		}
		return new RowRowWriter((StructVector) vector, fieldsWriters);
	} else {
		throw new UnsupportedOperationException(String.format(
			"Unsupported type %s.", fieldType));
	}
}
 
Example #17
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static ArrowFieldWriter<RowData> createArrowFieldWriterForRow(ValueVector vector, LogicalType fieldType) {
	if (vector instanceof TinyIntVector) {
		return TinyIntWriter.forRow((TinyIntVector) vector);
	} else if (vector instanceof SmallIntVector) {
		return SmallIntWriter.forRow((SmallIntVector) vector);
	} else if (vector instanceof IntVector) {
		return IntWriter.forRow((IntVector) vector);
	} else if (vector instanceof BigIntVector) {
		return BigIntWriter.forRow((BigIntVector) vector);
	} else if (vector instanceof BitVector) {
		return BooleanWriter.forRow((BitVector) vector);
	} else if (vector instanceof Float4Vector) {
		return FloatWriter.forRow((Float4Vector) vector);
	} else if (vector instanceof Float8Vector) {
		return DoubleWriter.forRow((Float8Vector) vector);
	} else if (vector instanceof VarCharVector) {
		return VarCharWriter.forRow((VarCharVector) vector);
	} else if (vector instanceof VarBinaryVector) {
		return VarBinaryWriter.forRow((VarBinaryVector) vector);
	} else if (vector instanceof DecimalVector) {
		DecimalVector decimalVector = (DecimalVector) vector;
		return DecimalWriter.forRow(decimalVector, getPrecision(decimalVector), decimalVector.getScale());
	} else if (vector instanceof DateDayVector) {
		return DateWriter.forRow((DateDayVector) vector);
	} else if (vector instanceof TimeSecVector || vector instanceof TimeMilliVector ||
		vector instanceof TimeMicroVector || vector instanceof TimeNanoVector) {
		return TimeWriter.forRow(vector);
	} else if (vector instanceof TimeStampVector && ((ArrowType.Timestamp) vector.getField().getType()).getTimezone() == null) {
		int precision;
		if (fieldType instanceof LocalZonedTimestampType) {
			precision = ((LocalZonedTimestampType) fieldType).getPrecision();
		} else {
			precision = ((TimestampType) fieldType).getPrecision();
		}
		return TimestampWriter.forRow(vector, precision);
	} else if (vector instanceof ListVector) {
		ListVector listVector = (ListVector) vector;
		LogicalType elementType = ((ArrayType) fieldType).getElementType();
		return ArrayWriter.forRow(listVector, createArrowFieldWriterForArray(listVector.getDataVector(), elementType));
	} else if (vector instanceof StructVector) {
		RowType rowType = (RowType) fieldType;
		ArrowFieldWriter<RowData>[] fieldsWriters = new ArrowFieldWriter[rowType.getFieldCount()];
		for (int i = 0; i < fieldsWriters.length; i++) {
			fieldsWriters[i] = createArrowFieldWriterForRow(
				((StructVector) vector).getVectorById(i),
				rowType.getTypeAt(i));
		}
		return RowWriter.forRow((StructVector) vector, fieldsWriters);
	} else {
		throw new UnsupportedOperationException(String.format(
			"Unsupported type %s.", fieldType));
	}
}
 
Example #18
Source File: TinyIntToFixedConverterTest.java    From snowflake-jdbc with Apache License 2.0 4 votes vote down vote up
@Test
public void testFixedNoScale() throws SFException
{
  final int rowCount = 1000;
  List<Byte> expectedValues = new ArrayList<>();
  Set<Integer> nullValIndex = new HashSet<>();
  for (int i = 0; i < rowCount; i++)
  {
    expectedValues.add((byte) random.nextInt(1 << 8));
  }

  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);

  TinyIntVector vector = new TinyIntVector("col_one", fieldType, allocator);
  for (int i = 0; i < rowCount; i++)
  {
    boolean isNull = random.nextBoolean();
    if (isNull)
    {
      vector.setNull(i);
      nullValIndex.add(i);
    }
    else
    {
      vector.setSafe(i, expectedValues.get(i));
    }
  }

  ArrowVectorConverter converter = new TinyIntToFixedConverter(vector, 0, this);

  for (int i = 0; i < rowCount; i++)
  {
    byte byteVal = converter.toByte(i);
    Object longObject = converter.toObject(i); // the logical type is long
    String byteString = converter.toString(i);

    if (nullValIndex.contains(i))
    {
      assertThat(byteVal, is((byte) 0));
      assertThat(longObject, is(nullValue()));
      assertThat(byteString, is(nullValue()));
    }
    else
    {
      assertThat(byteVal, is(expectedValues.get(i)));
      assertEquals(longObject, (long) expectedValues.get(i));
      assertThat(byteString, is(expectedValues.get(i).toString()));
    }
  }
  vector.clear();
}
 
Example #19
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
public static ArrowFieldReader createRowArrowFieldReader(ValueVector vector, LogicalType fieldType) {
	if (vector instanceof TinyIntVector) {
		return new TinyIntFieldReader((TinyIntVector) vector);
	} else if (vector instanceof SmallIntVector) {
		return new SmallIntFieldReader((SmallIntVector) vector);
	} else if (vector instanceof IntVector) {
		return new IntFieldReader((IntVector) vector);
	} else if (vector instanceof BigIntVector) {
		return new BigIntFieldReader((BigIntVector) vector);
	} else if (vector instanceof BitVector) {
		return new BooleanFieldReader((BitVector) vector);
	} else if (vector instanceof Float4Vector) {
		return new FloatFieldReader((Float4Vector) vector);
	} else if (vector instanceof Float8Vector) {
		return new DoubleFieldReader((Float8Vector) vector);
	} else if (vector instanceof VarCharVector) {
		return new VarCharFieldReader((VarCharVector) vector);
	} else if (vector instanceof VarBinaryVector) {
		return new VarBinaryFieldReader((VarBinaryVector) vector);
	} else if (vector instanceof DecimalVector) {
		return new DecimalFieldReader((DecimalVector) vector);
	} else if (vector instanceof DateDayVector) {
		return new DateFieldReader((DateDayVector) vector);
	} else if (vector instanceof TimeSecVector || vector instanceof TimeMilliVector ||
		vector instanceof TimeMicroVector || vector instanceof TimeNanoVector) {
		return new TimeFieldReader(vector);
	} else if (vector instanceof TimeStampVector && ((ArrowType.Timestamp) vector.getField().getType()).getTimezone() == null) {
		return new TimestampFieldReader(vector);
	} else if (vector instanceof ListVector) {
		ListVector listVector = (ListVector) vector;
		LogicalType elementType = ((ArrayType) fieldType).getElementType();
		return new ArrayFieldReader(listVector,
			createRowArrowFieldReader(listVector.getDataVector(), elementType),
			elementType);
	} else if (vector instanceof StructVector) {
		StructVector structVector = (StructVector) vector;
		ArrowFieldReader[] fieldReaders = new ArrowFieldReader[structVector.size()];
		for (int i = 0; i < fieldReaders.length; i++) {
			fieldReaders[i] = createRowArrowFieldReader(structVector.getVectorById(i), ((RowType) fieldType).getTypeAt(i));
		}
		return new RowFieldReader(structVector, fieldReaders);
	} else {
		throw new UnsupportedOperationException(String.format(
			"Unsupported type %s.", fieldType));
	}
}
 
Example #20
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
public static ColumnVector createColumnVector(ValueVector vector, LogicalType fieldType) {
	if (vector instanceof TinyIntVector) {
		return new ArrowTinyIntColumnVector((TinyIntVector) vector);
	} else if (vector instanceof SmallIntVector) {
		return new ArrowSmallIntColumnVector((SmallIntVector) vector);
	} else if (vector instanceof IntVector) {
		return new ArrowIntColumnVector((IntVector) vector);
	} else if (vector instanceof BigIntVector) {
		return new ArrowBigIntColumnVector((BigIntVector) vector);
	} else if (vector instanceof BitVector) {
		return new ArrowBooleanColumnVector((BitVector) vector);
	} else if (vector instanceof Float4Vector) {
		return new ArrowFloatColumnVector((Float4Vector) vector);
	} else if (vector instanceof Float8Vector) {
		return new ArrowDoubleColumnVector((Float8Vector) vector);
	} else if (vector instanceof VarCharVector) {
		return new ArrowVarCharColumnVector((VarCharVector) vector);
	} else if (vector instanceof VarBinaryVector) {
		return new ArrowVarBinaryColumnVector((VarBinaryVector) vector);
	} else if (vector instanceof DecimalVector) {
		return new ArrowDecimalColumnVector((DecimalVector) vector);
	} else if (vector instanceof DateDayVector) {
		return new ArrowDateColumnVector((DateDayVector) vector);
	} else if (vector instanceof TimeSecVector || vector instanceof TimeMilliVector ||
		vector instanceof TimeMicroVector || vector instanceof TimeNanoVector) {
		return new ArrowTimeColumnVector(vector);
	} else if (vector instanceof TimeStampVector && ((ArrowType.Timestamp) vector.getField().getType()).getTimezone() == null) {
		return new ArrowTimestampColumnVector(vector);
	} else if (vector instanceof ListVector) {
		ListVector listVector = (ListVector) vector;
		return new ArrowArrayColumnVector(listVector,
			createColumnVector(listVector.getDataVector(), ((ArrayType) fieldType).getElementType()));
	} else if (vector instanceof StructVector) {
		StructVector structVector = (StructVector) vector;
		ColumnVector[] fieldColumns = new ColumnVector[structVector.size()];
		for (int i = 0; i < fieldColumns.length; ++i) {
			fieldColumns[i] = createColumnVector(structVector.getVectorById(i), ((RowType) fieldType).getTypeAt(i));
		}
		return new ArrowRowColumnVector(structVector, fieldColumns);
	} else {
		throw new UnsupportedOperationException(String.format(
			"Unsupported type %s.", fieldType));
	}
}
 
Example #21
Source File: RowTinyIntWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
public RowTinyIntWriter(TinyIntVector tinyIntVector) {
	super(tinyIntVector);
}
 
Example #22
Source File: TinyIntWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
public static TinyIntWriter<RowData> forRow(TinyIntVector tinyIntVector) {
	return new TinyIntWriterForRow(tinyIntVector);
}
 
Example #23
Source File: TinyIntWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
public static TinyIntWriter<ArrayData> forArray(TinyIntVector tinyIntVector) {
	return new TinyIntWriterForArray(tinyIntVector);
}
 
Example #24
Source File: TinyIntWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
private TinyIntWriter(TinyIntVector tinyIntVector) {
	super(tinyIntVector);
}
 
Example #25
Source File: TinyIntWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
private TinyIntWriterForRow(TinyIntVector tinyIntVector) {
	super(tinyIntVector);
}
 
Example #26
Source File: TinyIntWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
private TinyIntWriterForArray(TinyIntVector tinyIntVector) {
	super(tinyIntVector);
}
 
Example #27
Source File: ArrowByteConnector.java    From multiple-dimension-spread with Apache License 2.0 4 votes vote down vote up
public ArrowByteConnector( final String columnName , final TinyIntVector vector ){
  this.columnName = columnName;
  this.vector = vector;
}
 
Example #28
Source File: BlockUtils.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
/**
 * Used to mark a particular cell as null.
 *
 * @param vector The FieldVector to write the null value to.
 * @param pos The position (row) in the FieldVector to mark as null.
 */
private static void setNullValue(FieldVector vector, int pos)
{
    switch (vector.getMinorType()) {
        case TIMESTAMPMILLITZ:
            ((TimeStampMilliTZVector) vector).setNull(pos);
            break;
        case DATEMILLI:
            ((DateMilliVector) vector).setNull(pos);
            break;
        case DATEDAY:
            ((DateDayVector) vector).setNull(pos);
            break;
        case FLOAT8:
            ((Float8Vector) vector).setNull(pos);
            break;
        case FLOAT4:
            ((Float4Vector) vector).setNull(pos);
            break;
        case INT:
            ((IntVector) vector).setNull(pos);
            break;
        case TINYINT:
            ((TinyIntVector) vector).setNull(pos);
            break;
        case SMALLINT:
            ((SmallIntVector) vector).setNull(pos);
            break;
        case UINT1:
            ((UInt1Vector) vector).setNull(pos);
            break;
        case UINT2:
            ((UInt2Vector) vector).setNull(pos);
            break;
        case UINT4:
            ((UInt4Vector) vector).setNull(pos);
            break;
        case UINT8:
            ((UInt8Vector) vector).setNull(pos);
            break;
        case BIGINT:
            ((BigIntVector) vector).setNull(pos);
            break;
        case VARBINARY:
            ((VarBinaryVector) vector).setNull(pos);
            break;
        case DECIMAL:
            ((DecimalVector) vector).setNull(pos);
            break;
        case VARCHAR:
            ((VarCharVector) vector).setNull(pos);
            break;
        case BIT:
            ((BitVector) vector).setNull(pos);
            break;
        default:
            throw new IllegalArgumentException("Unknown type " + vector.getMinorType());
    }
}
 
Example #29
Source File: BlockUtils.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
/**
 * In some filtering situations it can be useful to 'unset' a row as an indication to a later processing stage
 * that the row is irrelevant. The mechanism by which we 'unset' a row is actually field type specific and as such
 * this method is not supported for all field types.
 *
 * @param row The row number to unset in the provided Block.
 * @param block The Block where we'd like to unset the specified row.
 */
public static void unsetRow(int row, Block block)
{
    for (FieldVector vector : block.getFieldVectors()) {
        switch (vector.getMinorType()) {
            case TIMESTAMPMILLITZ:
                ((TimeStampMilliTZVector) vector).setNull(row);
                break;
            case DATEDAY:
                ((DateDayVector) vector).setNull(row);
                break;
            case DATEMILLI:
                ((DateMilliVector) vector).setNull(row);
                break;
            case TINYINT:
                ((TinyIntVector) vector).setNull(row);
                break;
            case UINT1:
                ((UInt1Vector) vector).setNull(row);
                break;
            case SMALLINT:
                ((SmallIntVector) vector).setNull(row);
                break;
            case UINT2:
                ((UInt2Vector) vector).setNull(row);
                break;
            case UINT4:
                ((UInt4Vector) vector).setNull(row);
                break;
            case INT:
                ((IntVector) vector).setNull(row);
                break;
            case UINT8:
                ((UInt8Vector) vector).setNull(row);
                break;
            case BIGINT:
                ((BigIntVector) vector).setNull(row);
                break;
            case FLOAT4:
                ((Float4Vector) vector).setNull(row);
                break;
            case FLOAT8:
                ((Float8Vector) vector).setNull(row);
                break;
            case DECIMAL:
                ((DecimalVector) vector).setNull(row);
                break;
            case VARBINARY:
                ((VarBinaryVector) vector).setNull(row);
                break;
            case VARCHAR:
                ((VarCharVector) vector).setNull(row);
                break;
            case BIT:
                ((BitVector) vector).setNull(row);
                break;
            case STRUCT:
                ((StructVector) vector).setNull(row);
                break;
            case LIST:
                UnionListWriter writer = ((ListVector) vector).getWriter();
                writer.setPosition(row);
                writer.startList();
                writer.endList();
                writer.setValueCount(0);
                break;
            default:
                throw new IllegalArgumentException("Unknown type " + vector.getMinorType());
        }
    }
}
 
Example #30
Source File: ArrowByteConnector.java    From yosegi with Apache License 2.0 4 votes vote down vote up
public ArrowByteConnector( final String columnName , final TinyIntVector vector ) {
  this.columnName = columnName;
  this.vector = vector;
}