Search in sources :

Example 6 with NullableIntVector

use of org.apache.drill.exec.vector.NullableIntVector in project drill by apache.

the class ParquetGroupScan method populatePruningVector.

public void populatePruningVector(ValueVector v, int index, SchemaPath column, String file) {
    String f = Path.getPathWithoutSchemeAndAuthority(new Path(file)).toString();
    MinorType type = getTypeForColumn(column).getMinorType();
    switch(type) {
        case INT:
            {
                NullableIntVector intVector = (NullableIntVector) v;
                Integer value = (Integer) partitionValueMap.get(f).get(column);
                intVector.getMutator().setSafe(index, value);
                return;
            }
        case SMALLINT:
            {
                NullableSmallIntVector smallIntVector = (NullableSmallIntVector) v;
                Integer value = (Integer) partitionValueMap.get(f).get(column);
                smallIntVector.getMutator().setSafe(index, value.shortValue());
                return;
            }
        case TINYINT:
            {
                NullableTinyIntVector tinyIntVector = (NullableTinyIntVector) v;
                Integer value = (Integer) partitionValueMap.get(f).get(column);
                tinyIntVector.getMutator().setSafe(index, value.byteValue());
                return;
            }
        case UINT1:
            {
                NullableUInt1Vector intVector = (NullableUInt1Vector) v;
                Integer value = (Integer) partitionValueMap.get(f).get(column);
                intVector.getMutator().setSafe(index, value.byteValue());
                return;
            }
        case UINT2:
            {
                NullableUInt2Vector intVector = (NullableUInt2Vector) v;
                Integer value = (Integer) partitionValueMap.get(f).get(column);
                intVector.getMutator().setSafe(index, (char) value.shortValue());
                return;
            }
        case UINT4:
            {
                NullableUInt4Vector intVector = (NullableUInt4Vector) v;
                Integer value = (Integer) partitionValueMap.get(f).get(column);
                intVector.getMutator().setSafe(index, value);
                return;
            }
        case BIGINT:
            {
                NullableBigIntVector bigIntVector = (NullableBigIntVector) v;
                Long value = (Long) partitionValueMap.get(f).get(column);
                bigIntVector.getMutator().setSafe(index, value);
                return;
            }
        case FLOAT4:
            {
                NullableFloat4Vector float4Vector = (NullableFloat4Vector) v;
                Float value = (Float) partitionValueMap.get(f).get(column);
                float4Vector.getMutator().setSafe(index, value);
                return;
            }
        case FLOAT8:
            {
                NullableFloat8Vector float8Vector = (NullableFloat8Vector) v;
                Double value = (Double) partitionValueMap.get(f).get(column);
                float8Vector.getMutator().setSafe(index, value);
                return;
            }
        case VARBINARY:
            {
                NullableVarBinaryVector varBinaryVector = (NullableVarBinaryVector) v;
                Object s = partitionValueMap.get(f).get(column);
                byte[] bytes;
                if (s instanceof Binary) {
                    bytes = ((Binary) s).getBytes();
                } else if (s instanceof String) {
                    bytes = ((String) s).getBytes();
                } else if (s instanceof byte[]) {
                    bytes = (byte[]) s;
                } else {
                    throw new UnsupportedOperationException("Unable to create column data for type: " + type);
                }
                varBinaryVector.getMutator().setSafe(index, bytes, 0, bytes.length);
                return;
            }
        case DECIMAL18:
            {
                NullableDecimal18Vector decimalVector = (NullableDecimal18Vector) v;
                Long value = (Long) partitionValueMap.get(f).get(column);
                decimalVector.getMutator().setSafe(index, value);
                return;
            }
        case DATE:
            {
                NullableDateVector dateVector = (NullableDateVector) v;
                Integer value = (Integer) partitionValueMap.get(f).get(column);
                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);
                timeVector.getMutator().setSafe(index, value);
                return;
            }
        case TIMESTAMP:
            {
                NullableTimeStampVector timeStampVector = (NullableTimeStampVector) v;
                Long value = (Long) partitionValueMap.get(f).get(column);
                timeStampVector.getMutator().setSafe(index, value);
                return;
            }
        case VARCHAR:
            {
                NullableVarCharVector varCharVector = (NullableVarCharVector) v;
                Object s = partitionValueMap.get(f).get(column);
                byte[] bytes;
                if (s instanceof String) {
                    // if the metadata was read from a JSON cache file it maybe a string type
                    bytes = ((String) s).getBytes();
                } else if (s instanceof Binary) {
                    bytes = ((Binary) s).getBytes();
                } else if (s instanceof byte[]) {
                    bytes = (byte[]) s;
                } else {
                    throw new UnsupportedOperationException("Unable to create column data for type: " + type);
                }
                varCharVector.getMutator().setSafe(index, bytes, 0, bytes.length);
                return;
            }
        default:
            throw new UnsupportedOperationException("Unsupported type: " + type);
    }
}
Also used : NullableTinyIntVector(org.apache.drill.exec.vector.NullableTinyIntVector) NullableFloat8Vector(org.apache.drill.exec.vector.NullableFloat8Vector) NullableVarBinaryVector(org.apache.drill.exec.vector.NullableVarBinaryVector) NullableUInt1Vector(org.apache.drill.exec.vector.NullableUInt1Vector) NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) NullableFloat4Vector(org.apache.drill.exec.vector.NullableFloat4Vector) NullableUInt4Vector(org.apache.drill.exec.vector.NullableUInt4Vector) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) NullableDecimal18Vector(org.apache.drill.exec.vector.NullableDecimal18Vector) Path(org.apache.hadoop.fs.Path) SchemaPath(org.apache.drill.common.expression.SchemaPath) ReadEntryWithPath(org.apache.drill.exec.store.dfs.ReadEntryWithPath) NullableDateVector(org.apache.drill.exec.vector.NullableDateVector) NullableTimeStampVector(org.apache.drill.exec.vector.NullableTimeStampVector) NullableSmallIntVector(org.apache.drill.exec.vector.NullableSmallIntVector) NullableUInt2Vector(org.apache.drill.exec.vector.NullableUInt2Vector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) Binary(org.apache.parquet.io.api.Binary) NullableTimeVector(org.apache.drill.exec.vector.NullableTimeVector)

Example 7 with NullableIntVector

use of org.apache.drill.exec.vector.NullableIntVector in project drill by axbaretto.

the class TestToNullable method testFixedWidth.

@SuppressWarnings("resource")
@Test
public void testFixedWidth() {
    MaterializedField intSchema = SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED);
    IntVector intVector = new IntVector(intSchema, fixture.allocator());
    IntVector.Mutator intMutator = intVector.getMutator();
    intVector.allocateNew(100);
    for (int i = 0; i < 100; i++) {
        intMutator.set(i, i * 10);
    }
    intMutator.setValueCount(100);
    MaterializedField nullableIntSchema = SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.OPTIONAL);
    NullableIntVector nullableIntVector = new NullableIntVector(nullableIntSchema, fixture.allocator());
    intVector.toNullable(nullableIntVector);
    assertEquals(0, intVector.getAccessor().getValueCount());
    NullableIntVector.Accessor niAccessor = nullableIntVector.getAccessor();
    assertEquals(100, niAccessor.getValueCount());
    for (int i = 0; i < 100; i++) {
        assertFalse(niAccessor.isNull(i));
        assertEquals(i * 10, niAccessor.get(i));
    }
    nullableIntVector.clear();
// Don't clear the intVector, it should be empty.
// If it is not, the test will fail with a memory leak error.
}
Also used : NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) IntVector(org.apache.drill.exec.vector.IntVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 8 with NullableIntVector

use of org.apache.drill.exec.vector.NullableIntVector in project drill by axbaretto.

the class TestToNullable method testNullable.

@SuppressWarnings("resource")
@Test
public void testNullable() {
    MaterializedField nullableIntSchema = SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.OPTIONAL);
    NullableIntVector sourceVector = new NullableIntVector(nullableIntSchema, fixture.allocator());
    NullableIntVector.Mutator sourceMutator = sourceVector.getMutator();
    sourceVector.allocateNew(100);
    for (int i = 0; i < 100; i++) {
        sourceMutator.set(i, i * 10);
    }
    sourceMutator.setValueCount(100);
    NullableIntVector destVector = new NullableIntVector(nullableIntSchema, fixture.allocator());
    sourceVector.toNullable(destVector);
    assertEquals(0, sourceVector.getAccessor().getValueCount());
    NullableIntVector.Accessor destAccessor = destVector.getAccessor();
    assertEquals(100, destAccessor.getValueCount());
    for (int i = 0; i < 100; i++) {
        assertFalse(destAccessor.isNull(i));
        assertEquals(i * 10, destAccessor.get(i));
    }
    destVector.clear();
// Don't clear the intVector, it should be empty.
// If it is not, the test will fail with a memory leak error.
}
Also used : NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 9 with NullableIntVector

use of org.apache.drill.exec.vector.NullableIntVector in project drill by axbaretto.

the class TestVectorLimits method testNullableFixedVector.

@Test
public void testNullableFixedVector() {
    @SuppressWarnings("resource") NullableIntVector vector = new NullableIntVector(makeField(MinorType.INT, DataMode.OPTIONAL), fixture.allocator());
    vector.allocateNew();
    NullableIntVector.Mutator mutator = vector.getMutator();
    for (int i = 0; i < 2 * ValueVector.MAX_ROW_COUNT; i++) {
        try {
            mutator.setScalar(i, i);
        } catch (VectorOverflowException e) {
            assertEquals(IntVector.MAX_SCALAR_COUNT, i);
            break;
        }
    }
    vector.close();
}
Also used : NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) VectorOverflowException(org.apache.drill.exec.vector.VectorOverflowException) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest) DrillTest(org.apache.drill.test.DrillTest)

Example 10 with NullableIntVector

use of org.apache.drill.exec.vector.NullableIntVector in project drill by apache.

the class TestToNullable method testFixedWidth.

@Test
public void testFixedWidth() {
    MaterializedField intSchema = SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED);
    @SuppressWarnings("resource") IntVector intVector = new IntVector(intSchema, fixture.allocator());
    IntVector.Mutator intMutator = intVector.getMutator();
    intVector.allocateNew(100);
    for (int i = 0; i < 100; i++) {
        intMutator.set(i, i * 10);
    }
    intMutator.setValueCount(100);
    MaterializedField nullableIntSchema = SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.OPTIONAL);
    NullableIntVector nullableIntVector = new NullableIntVector(nullableIntSchema, fixture.allocator());
    intVector.toNullable(nullableIntVector);
    assertEquals(0, intVector.getAccessor().getValueCount());
    NullableIntVector.Accessor niAccessor = nullableIntVector.getAccessor();
    assertEquals(100, niAccessor.getValueCount());
    for (int i = 0; i < 100; i++) {
        assertFalse(niAccessor.isNull(i));
        assertEquals(i * 10, niAccessor.get(i));
    }
    nullableIntVector.clear();
// Don't clear the intVector, it should be empty.
// If it is not, the test will fail with a memory leak error.
}
Also used : NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) IntVector(org.apache.drill.exec.vector.IntVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

NullableIntVector (org.apache.drill.exec.vector.NullableIntVector)11 Test (org.junit.Test)8 SubOperatorTest (org.apache.drill.test.SubOperatorTest)7 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)5 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)5 MaterializedField (org.apache.drill.exec.record.MaterializedField)4 NullableFloat8Vector (org.apache.drill.exec.vector.NullableFloat8Vector)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)3 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)3 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)3 NullableDateVector (org.apache.drill.exec.vector.NullableDateVector)3 NullableFloat4Vector (org.apache.drill.exec.vector.NullableFloat4Vector)3 NullableSmallIntVector (org.apache.drill.exec.vector.NullableSmallIntVector)3 NullableTimeStampVector (org.apache.drill.exec.vector.NullableTimeStampVector)3 NullableTimeVector (org.apache.drill.exec.vector.NullableTimeVector)3 NullableTinyIntVector (org.apache.drill.exec.vector.NullableTinyIntVector)3 NullableUInt1Vector (org.apache.drill.exec.vector.NullableUInt1Vector)3 NullableUInt2Vector (org.apache.drill.exec.vector.NullableUInt2Vector)3