Search in sources :

Example 6 with VarCharVector

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

the class BatchValidator method validateNullableVector.

private void validateNullableVector(String name, NullableVector vector) {
    if (vector instanceof NullableVarCharVector) {
        @SuppressWarnings("resource") VarCharVector values = ((NullableVarCharVector) vector).getValuesVector();
        validateVarCharVector(name + "-values", values, rowCount);
    }
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector)

Example 7 with VarCharVector

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

the class TestHiveUDFs method testUDF.

@Test
public void testUDF() throws Throwable {
    int numRecords = 0;
    String planString = Resources.toString(Resources.getResource("functions/hive/UDF.json"), Charsets.UTF_8);
    List<QueryDataBatch> results = testPhysicalWithResults(planString);
    RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
    for (QueryDataBatch result : results) {
        batchLoader.load(result.getHeader().getDef(), result.getData());
        if (batchLoader.getRecordCount() <= 0) {
            result.release();
            batchLoader.clear();
            continue;
        }
        // Output columns and types
        // 1. str1 : VarChar
        // 2. str1Length : Int
        // 3. str1Ascii : Int
        // 4. flt1 : Float4
        // 5. pow : Float8
        VarCharVector str1V = (VarCharVector) batchLoader.getValueAccessorById(VarCharVector.class, 0).getValueVector();
        BigIntVector str1LengthV = (BigIntVector) batchLoader.getValueAccessorById(BigIntVector.class, 1).getValueVector();
        IntVector str1AsciiV = (IntVector) batchLoader.getValueAccessorById(IntVector.class, 2).getValueVector();
        Float4Vector flt1V = (Float4Vector) batchLoader.getValueAccessorById(Float4Vector.class, 3).getValueVector();
        NullableFloat8Vector powV = (NullableFloat8Vector) batchLoader.getValueAccessorById(NullableFloat8Vector.class, 4).getValueVector();
        for (int i = 0; i < batchLoader.getRecordCount(); i++) {
            String str1 = new String(str1V.getAccessor().get(i), Charsets.UTF_8);
            long str1Length = str1LengthV.getAccessor().get(i);
            assertTrue(str1.length() == str1Length);
            int str1Ascii = str1AsciiV.getAccessor().get(i);
            float flt1 = flt1V.getAccessor().get(i);
            double pow = 0;
            if (!powV.getAccessor().isNull(i)) {
                pow = powV.getAccessor().get(i);
                assertTrue(Math.pow(flt1, 2.0) == pow);
            }
            System.out.println(str1 + ", " + str1Length + ", " + str1Ascii + ", " + flt1 + ", " + pow);
            numRecords++;
        }
        result.release();
        batchLoader.clear();
    }
    System.out.println("Processed " + numRecords + " records");
}
Also used : NullableFloat8Vector(org.apache.drill.exec.vector.NullableFloat8Vector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) IntVector(org.apache.drill.exec.vector.IntVector) Float4Vector(org.apache.drill.exec.vector.Float4Vector) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Test(org.junit.Test)

Example 8 with VarCharVector

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

the class StringGen method setValue.

@Override
public void setValue(ValueVector v, int index) {
    VarCharVector vector = (VarCharVector) v;
    vector.getMutator().setSafe(index, value().getBytes());
}
Also used : VarCharVector(org.apache.drill.exec.vector.VarCharVector)

Example 9 with VarCharVector

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

the class DateGen method setValue.

@Override
public void setValue(ValueVector v, int index) {
    VarCharVector vector = (VarCharVector) v;
    long randTime = baseTime + value();
    String str = fmt.format(new Date(randTime));
    vector.getMutator().setSafe(index, str.getBytes());
}
Also used : VarCharVector(org.apache.drill.exec.vector.VarCharVector) Date(java.util.Date)

Example 10 with VarCharVector

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

the class TestBatchValidator method testRepeatedBadValueOffset.

@Test
public void testRepeatedBadValueOffset() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR, DataMode.REPEATED).build();
    SingleRowSet batch = fixture.rowSetBuilder(schema).add((Object) new String[] {}).add((Object) new String[] { "fred", "barney", "wilma" }).add((Object) new String[] { "dino" }).build();
    VectorAccessible va = batch.vectorAccessible();
    @SuppressWarnings("resource") ValueVector v = va.iterator().next().getValueVector();
    RepeatedVarCharVector rvc = (RepeatedVarCharVector) v;
    @SuppressWarnings("resource") VarCharVector vc = rvc.getDataVector();
    @SuppressWarnings("resource") UInt4Vector ov = vc.getOffsetVector();
    ov.getMutator().set(4, 100_000);
    BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
    validator.validate();
    List<String> errors = validator.errors();
    assertEquals(1, errors.size());
    assertTrue(errors.get(0).contains("Invalid offset"));
    batch.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) ValueVector(org.apache.drill.exec.vector.ValueVector) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) BatchValidator(org.apache.drill.exec.physical.impl.validate.BatchValidator) Test(org.junit.Test)

Aggregations

VarCharVector (org.apache.drill.exec.vector.VarCharVector)20 ValueVector (org.apache.drill.exec.vector.ValueVector)9 Test (org.junit.Test)9 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)7 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)6 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)5 RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)4 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)4 ExecTest (org.apache.drill.exec.ExecTest)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)3 BigIntVector (org.apache.drill.exec.vector.BigIntVector)3 DrillBuf (io.netty.buffer.DrillBuf)2 ArrayList (java.util.ArrayList)2 BatchValidator (org.apache.drill.exec.physical.impl.validate.BatchValidator)2 BatchSchema (org.apache.drill.exec.record.BatchSchema)2 Float4Vector (org.apache.drill.exec.vector.Float4Vector)2 IntVector (org.apache.drill.exec.vector.IntVector)2 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)2 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)2