use of org.apache.drill.exec.vector.NullableIntVector in project drill by axbaretto.
the class ParquetGroupScan method populatePruningVector.
public void populatePruningVector(ValueVector v, int index, SchemaPath column, String file) {
String f = Path.getPathWithoutSchemeAndAuthority(new Path(file)).toString();
MajorType majorType = getTypeForColumn(column);
MinorType type = majorType.getMinorType();
switch(type) {
case BIT:
{
NullableBitVector bitVector = (NullableBitVector) v;
Boolean value = (Boolean) partitionValueMap.get(f).get(column);
if (value == null) {
bitVector.getMutator().setNull(index);
} else {
bitVector.getMutator().setSafe(index, value ? 1 : 0);
}
return;
}
case INT:
{
NullableIntVector intVector = (NullableIntVector) v;
Integer value = (Integer) partitionValueMap.get(f).get(column);
if (value == null) {
intVector.getMutator().setNull(index);
} else {
intVector.getMutator().setSafe(index, value);
}
return;
}
case SMALLINT:
{
NullableSmallIntVector smallIntVector = (NullableSmallIntVector) v;
Integer value = (Integer) partitionValueMap.get(f).get(column);
if (value == null) {
smallIntVector.getMutator().setNull(index);
} else {
smallIntVector.getMutator().setSafe(index, value.shortValue());
}
return;
}
case TINYINT:
{
NullableTinyIntVector tinyIntVector = (NullableTinyIntVector) v;
Integer value = (Integer) partitionValueMap.get(f).get(column);
if (value == null) {
tinyIntVector.getMutator().setNull(index);
} else {
tinyIntVector.getMutator().setSafe(index, value.byteValue());
}
return;
}
case UINT1:
{
NullableUInt1Vector intVector = (NullableUInt1Vector) v;
Integer value = (Integer) partitionValueMap.get(f).get(column);
if (value == null) {
intVector.getMutator().setNull(index);
} else {
intVector.getMutator().setSafe(index, value.byteValue());
}
return;
}
case UINT2:
{
NullableUInt2Vector intVector = (NullableUInt2Vector) v;
Integer value = (Integer) partitionValueMap.get(f).get(column);
if (value == null) {
intVector.getMutator().setNull(index);
} else {
intVector.getMutator().setSafe(index, (char) value.shortValue());
}
return;
}
case UINT4:
{
NullableUInt4Vector intVector = (NullableUInt4Vector) v;
Integer value = (Integer) partitionValueMap.get(f).get(column);
if (value == null) {
intVector.getMutator().setNull(index);
} else {
intVector.getMutator().setSafe(index, value);
}
return;
}
case BIGINT:
{
NullableBigIntVector bigIntVector = (NullableBigIntVector) v;
Long value = (Long) partitionValueMap.get(f).get(column);
if (value == null) {
bigIntVector.getMutator().setNull(index);
} else {
bigIntVector.getMutator().setSafe(index, value);
}
return;
}
case FLOAT4:
{
NullableFloat4Vector float4Vector = (NullableFloat4Vector) v;
Float value = (Float) partitionValueMap.get(f).get(column);
if (value == null) {
float4Vector.getMutator().setNull(index);
} else {
float4Vector.getMutator().setSafe(index, value);
}
return;
}
case FLOAT8:
{
NullableFloat8Vector float8Vector = (NullableFloat8Vector) v;
Double value = (Double) partitionValueMap.get(f).get(column);
if (value == null) {
float8Vector.getMutator().setNull(index);
} else {
float8Vector.getMutator().setSafe(index, value);
}
return;
}
case VARBINARY:
{
NullableVarBinaryVector varBinaryVector = (NullableVarBinaryVector) v;
Object s = partitionValueMap.get(f).get(column);
byte[] bytes;
if (s == null) {
varBinaryVector.getMutator().setNull(index);
return;
} else {
bytes = getBytes(type, s);
}
varBinaryVector.getMutator().setSafe(index, bytes, 0, bytes.length);
return;
}
case DECIMAL18:
{
NullableDecimal18Vector decimalVector = (NullableDecimal18Vector) v;
Object s = partitionValueMap.get(f).get(column);
byte[] bytes;
if (s == null) {
decimalVector.getMutator().setNull(index);
return;
} else if (s instanceof Integer) {
long value = DecimalUtility.getBigDecimalFromPrimitiveTypes((Integer) s, majorType.getScale(), majorType.getPrecision()).longValue();
decimalVector.getMutator().setSafe(index, value);
return;
} else if (s instanceof Long) {
long value = DecimalUtility.getBigDecimalFromPrimitiveTypes((Long) s, majorType.getScale(), majorType.getPrecision()).longValue();
decimalVector.getMutator().setSafe(index, value);
return;
} else {
bytes = getBytes(type, s);
}
long value = DecimalUtility.getBigDecimalFromByteArray(bytes, 0, bytes.length, majorType.getScale()).longValue();
decimalVector.getMutator().setSafe(index, value);
return;
}
case DATE:
{
NullableDateVector dateVector = (NullableDateVector) v;
Integer value = (Integer) partitionValueMap.get(f).get(column);
if (value == null) {
dateVector.getMutator().setNull(index);
} else {
dateVector.getMutator().setSafe(index, value * (long) DateTimeConstants.MILLIS_PER_DAY);
}
return;
}
case TIME:
{
NullableTimeVector timeVector = (NullableTimeVector) v;
Integer value = (Integer) partitionValueMap.get(f).get(column);
if (value == null) {
timeVector.getMutator().setNull(index);
} else {
timeVector.getMutator().setSafe(index, value);
}
return;
}
case TIMESTAMP:
{
NullableTimeStampVector timeStampVector = (NullableTimeStampVector) v;
Long value = (Long) partitionValueMap.get(f).get(column);
if (value == null) {
timeStampVector.getMutator().setNull(index);
} else {
timeStampVector.getMutator().setSafe(index, value);
}
return;
}
case VARCHAR:
{
NullableVarCharVector varCharVector = (NullableVarCharVector) v;
Object s = partitionValueMap.get(f).get(column);
byte[] bytes;
if (s == null) {
varCharVector.getMutator().setNull(index);
return;
} else {
bytes = getBytes(type, s);
}
varCharVector.getMutator().setSafe(index, bytes, 0, bytes.length);
return;
}
case INTERVAL:
{
NullableIntervalVector intervalVector = (NullableIntervalVector) v;
Object s = partitionValueMap.get(f).get(column);
byte[] bytes;
if (s == null) {
intervalVector.getMutator().setNull(index);
return;
} else {
bytes = getBytes(type, s);
}
intervalVector.getMutator().setSafe(index, 1, ParquetReaderUtility.getIntFromLEBytes(bytes, 0), ParquetReaderUtility.getIntFromLEBytes(bytes, 4), ParquetReaderUtility.getIntFromLEBytes(bytes, 8));
return;
}
default:
throw new UnsupportedOperationException("Unsupported type: " + type);
}
}
use of org.apache.drill.exec.vector.NullableIntVector in project drill by apache.
the class TestResultSetLoaderUnions method testListofListofScalar.
/**
* The semantics of the ListVector are such that it allows
* multi-dimensional lists. In this way, it is like a (slightly
* more normalized) version of the repeated list vector. This form
* allows arrays to be null.
* <p>
* This test verifies that the (non-repeated) list vector can
* be used to create multi-dimensional arrays in the result set
* loader layer. However, the rest of Drill does not support this
* functionality at present, so this test is more of a proof-of-
* concept than a necessity.
*/
@Test
public void testListofListofScalar() {
// JSON equivalent: {a: [[1, 2], [3, 4]]}
final ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator());
final RowSetLoader writer = rsLoader.writer();
// Can write a batch as if this was a repeated Varchar, except
// that any value can also be null.
rsLoader.startBatch();
writer.addColumn(MaterializedField.create("a", Types.optional(MinorType.LIST)));
final ArrayWriter outerArray = writer.array("a");
final VariantWriter outerVariant = outerArray.variant();
outerVariant.addMember(MinorType.LIST);
final ArrayWriter innerArray = outerVariant.array();
final VariantWriter innerVariant = innerArray.variant();
innerVariant.addMember(MinorType.INT);
writer.addSingleCol(listValue(listValue(1, 2), listValue(3, 4)));
final RowSet results = fixture.wrap(rsLoader.harvest());
// Verify metadata
final ListVector outer = (ListVector) results.container().getValueVector(0).getValueVector();
final MajorType outerType = outer.getField().getType();
assertEquals(1, outerType.getSubTypeCount());
assertEquals(MinorType.LIST, outerType.getSubType(0));
assertEquals(1, outer.getField().getChildren().size());
final ListVector inner = (ListVector) outer.getDataVector();
assertSame(inner.getField(), outer.getField().getChildren().iterator().next());
final MajorType innerType = inner.getField().getType();
assertEquals(1, innerType.getSubTypeCount());
assertEquals(MinorType.INT, innerType.getSubType(0));
assertEquals(1, inner.getField().getChildren().size());
final ValueVector data = inner.getDataVector();
assertSame(data.getField(), inner.getField().getChildren().iterator().next());
assertEquals(MinorType.INT, data.getField().getType().getMinorType());
assertEquals(DataMode.OPTIONAL, data.getField().getType().getMode());
assertTrue(data instanceof NullableIntVector);
// Note use of TupleMetadata: BatchSchema can't hold the
// structure of a list.
final TupleMetadata expectedSchema = new SchemaBuilder().addList("a").addList().addType(MinorType.INT).resumeUnion().resumeSchema().buildSchema();
final RowSet expected = new RowSetBuilder(fixture.allocator(), expectedSchema).addSingleCol(listValue(listValue(1, 2), listValue(3, 4))).build();
RowSetUtilities.verify(expected, results);
}
use of org.apache.drill.exec.vector.NullableIntVector in project drill by apache.
the class ParquetPartitionDescriptor method populatePruningVector.
private void populatePruningVector(ValueVector v, int index, SchemaPath column, Path file) {
Path path = Path.getPathWithoutSchemeAndAuthority(file);
TypeProtos.MajorType majorType = getVectorType(column, null);
TypeProtos.MinorType type = majorType.getMinorType();
switch(type) {
case BIT:
{
NullableBitVector bitVector = (NullableBitVector) v;
Boolean value = groupScan.getPartitionValue(path, column, Boolean.class);
if (value == null) {
bitVector.getMutator().setNull(index);
} else {
bitVector.getMutator().setSafe(index, value ? 1 : 0);
}
return;
}
case INT:
{
NullableIntVector intVector = (NullableIntVector) v;
Integer value = groupScan.getPartitionValue(path, column, Integer.class);
if (value == null) {
intVector.getMutator().setNull(index);
} else {
intVector.getMutator().setSafe(index, value);
}
return;
}
case SMALLINT:
{
NullableSmallIntVector smallIntVector = (NullableSmallIntVector) v;
Integer value = groupScan.getPartitionValue(path, column, Integer.class);
if (value == null) {
smallIntVector.getMutator().setNull(index);
} else {
smallIntVector.getMutator().setSafe(index, value.shortValue());
}
return;
}
case TINYINT:
{
NullableTinyIntVector tinyIntVector = (NullableTinyIntVector) v;
Integer value = groupScan.getPartitionValue(path, column, Integer.class);
if (value == null) {
tinyIntVector.getMutator().setNull(index);
} else {
tinyIntVector.getMutator().setSafe(index, value.byteValue());
}
return;
}
case UINT1:
{
NullableUInt1Vector intVector = (NullableUInt1Vector) v;
Integer value = groupScan.getPartitionValue(path, column, Integer.class);
if (value == null) {
intVector.getMutator().setNull(index);
} else {
intVector.getMutator().setSafe(index, value.byteValue());
}
return;
}
case UINT2:
{
NullableUInt2Vector intVector = (NullableUInt2Vector) v;
Integer value = groupScan.getPartitionValue(path, column, Integer.class);
if (value == null) {
intVector.getMutator().setNull(index);
} else {
intVector.getMutator().setSafe(index, (char) value.shortValue());
}
return;
}
case UINT4:
{
NullableUInt4Vector intVector = (NullableUInt4Vector) v;
Integer value = groupScan.getPartitionValue(path, column, Integer.class);
if (value == null) {
intVector.getMutator().setNull(index);
} else {
intVector.getMutator().setSafe(index, value);
}
return;
}
case BIGINT:
{
NullableBigIntVector bigIntVector = (NullableBigIntVector) v;
Long value = groupScan.getPartitionValue(path, column, Long.class);
if (value == null) {
bigIntVector.getMutator().setNull(index);
} else {
bigIntVector.getMutator().setSafe(index, value);
}
return;
}
case FLOAT4:
{
NullableFloat4Vector float4Vector = (NullableFloat4Vector) v;
Float value = groupScan.getPartitionValue(path, column, Float.class);
if (value == null) {
float4Vector.getMutator().setNull(index);
} else {
float4Vector.getMutator().setSafe(index, value);
}
return;
}
case FLOAT8:
{
NullableFloat8Vector float8Vector = (NullableFloat8Vector) v;
Double value = groupScan.getPartitionValue(path, column, Double.class);
if (value == null) {
float8Vector.getMutator().setNull(index);
} else {
float8Vector.getMutator().setSafe(index, value);
}
return;
}
case VARBINARY:
{
NullableVarBinaryVector varBinaryVector = (NullableVarBinaryVector) v;
Object s = groupScan.getPartitionValue(path, column, Object.class);
byte[] bytes;
if (s == null) {
varBinaryVector.getMutator().setNull(index);
return;
} else {
bytes = getBytes(type, s);
}
varBinaryVector.getMutator().setSafe(index, bytes, 0, bytes.length);
return;
}
case VARDECIMAL:
{
NullableVarDecimalVector decimalVector = (NullableVarDecimalVector) v;
Object s = groupScan.getPartitionValue(path, column, Object.class);
byte[] bytes;
if (s == null) {
decimalVector.getMutator().setNull(index);
return;
} else if (s instanceof Integer) {
bytes = Ints.toByteArray((int) s);
} else if (s instanceof Long) {
bytes = Longs.toByteArray((long) s);
} else {
bytes = getBytes(type, s);
}
decimalVector.getMutator().setSafe(index, bytes, 0, bytes.length);
return;
}
case DATE:
{
NullableDateVector dateVector = (NullableDateVector) v;
Long value = groupScan.getPartitionValue(path, column, Long.class);
if (value == null) {
dateVector.getMutator().setNull(index);
} else {
dateVector.getMutator().setSafe(index, value);
}
return;
}
case TIME:
{
NullableTimeVector timeVector = (NullableTimeVector) v;
Integer value = groupScan.getPartitionValue(path, column, Integer.class);
if (value == null) {
timeVector.getMutator().setNull(index);
} else {
timeVector.getMutator().setSafe(index, value);
}
return;
}
case TIMESTAMP:
{
NullableTimeStampVector timeStampVector = (NullableTimeStampVector) v;
Long value = groupScan.getPartitionValue(path, column, Long.class);
if (value == null) {
timeStampVector.getMutator().setNull(index);
} else {
timeStampVector.getMutator().setSafe(index, value);
}
return;
}
case VARCHAR:
{
NullableVarCharVector varCharVector = (NullableVarCharVector) v;
Object s = groupScan.getPartitionValue(path, column, Object.class);
byte[] bytes;
if (s == null) {
varCharVector.getMutator().setNull(index);
return;
} else {
bytes = getBytes(type, s);
}
varCharVector.getMutator().setSafe(index, bytes, 0, bytes.length);
return;
}
case INTERVAL:
{
NullableIntervalVector intervalVector = (NullableIntervalVector) v;
Object s = groupScan.getPartitionValue(path, column, Object.class);
byte[] bytes;
if (s == null) {
intervalVector.getMutator().setNull(index);
return;
} else {
bytes = getBytes(type, s);
}
intervalVector.getMutator().setSafe(index, 1, ParquetReaderUtility.getIntFromLEBytes(bytes, 0), ParquetReaderUtility.getIntFromLEBytes(bytes, 4), ParquetReaderUtility.getIntFromLEBytes(bytes, 8));
return;
}
default:
throw new UnsupportedOperationException("Unsupported type: " + type);
}
}
use of org.apache.drill.exec.vector.NullableIntVector in project drill by apache.
the class TestVariantAccessors method testBuildRowSetUnionArray.
@Test
public void testBuildRowSetUnionArray() {
final TupleMetadata schema = new SchemaBuilder().addList("list1").addType(MinorType.BIGINT).addMap().addNullable("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).resumeUnion().addList().addType(MinorType.FLOAT8).resumeUnion().resumeSchema().buildSchema();
final ExtendableRowSet rowSet = fixture.rowSet(schema);
final VectorContainer vc = rowSet.container();
assertEquals(1, vc.getNumberOfColumns());
// List with complex internal structure
final ValueVector vector = vc.getValueVector(0).getValueVector();
assertTrue(vector instanceof ListVector);
final ListVector list = (ListVector) vector;
assertTrue(list.getDataVector() instanceof UnionVector);
final UnionVector union = (UnionVector) list.getDataVector();
// Union inside the list
final MajorType unionType = union.getField().getType();
final List<MinorType> types = unionType.getSubTypeList();
assertEquals(3, types.size());
assertTrue(types.contains(MinorType.BIGINT));
assertTrue(types.contains(MinorType.MAP));
assertTrue(types.contains(MinorType.LIST));
final MapVector typeMap = union.getTypeMap();
ValueVector member = typeMap.getChild(MinorType.BIGINT.name());
assertTrue(member instanceof NullableBigIntVector);
// Map inside the list
member = typeMap.getChild(MinorType.MAP.name());
assertTrue(member instanceof MapVector);
final MapVector childMap = (MapVector) member;
ValueVector mapMember = childMap.getChild("a");
assertNotNull(mapMember);
assertTrue(mapMember instanceof NullableIntVector);
mapMember = childMap.getChild("b");
assertNotNull(mapMember);
assertTrue(mapMember instanceof NullableVarCharVector);
// Single-type list inside the outer list
member = typeMap.getChild(MinorType.LIST.name());
assertTrue(member instanceof ListVector);
final ListVector childList = (ListVector) member;
assertTrue(childList.getDataVector() instanceof NullableFloat8Vector);
rowSet.clear();
}
use of org.apache.drill.exec.vector.NullableIntVector in project drill by apache.
the class TestVariantAccessors method testBuildRowSetUnion.
@Test
public void testBuildRowSetUnion() {
final TupleMetadata schema = new SchemaBuilder().addUnion("u").addType(MinorType.INT).addMap().addNullable("c", MinorType.BIGINT).addNullable("d", MinorType.VARCHAR).resumeUnion().addList().addType(MinorType.VARCHAR).resumeUnion().resumeSchema().buildSchema();
final ExtendableRowSet rowSet = fixture.rowSet(schema);
final VectorContainer vc = rowSet.container();
assertEquals(1, vc.getNumberOfColumns());
// Single union
final ValueVector vector = vc.getValueVector(0).getValueVector();
assertTrue(vector instanceof UnionVector);
final UnionVector union = (UnionVector) vector;
final MapVector typeMap = union.getTypeMap();
ValueVector member = typeMap.getChild(MinorType.INT.name());
assertTrue(member instanceof NullableIntVector);
// Inner map
member = typeMap.getChild(MinorType.MAP.name());
assertTrue(member instanceof MapVector);
member = typeMap.getChild(MinorType.MAP.name());
assertTrue(member instanceof MapVector);
final MapVector childMap = (MapVector) member;
ValueVector mapMember = childMap.getChild("c");
assertNotNull(mapMember);
assertTrue(mapMember instanceof NullableBigIntVector);
mapMember = childMap.getChild("d");
assertNotNull(mapMember);
assertTrue(mapMember instanceof NullableVarCharVector);
// Inner list
member = typeMap.getChild(MinorType.LIST.name());
assertTrue(member instanceof ListVector);
final ListVector list = (ListVector) member;
assertTrue(list.getDataVector() instanceof NullableVarCharVector);
rowSet.clear();
}
Aggregations