Search in sources :

Example 11 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 12 with VarCharVector

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

the class TestOrderedBytesConvertFunctions method getRunResult.

protected Object[] getRunResult(QueryType queryType, String planString) throws Exception {
    List<QueryDataBatch> resultList = testRunAndReturn(queryType, planString);
    List<Object> res = new ArrayList<Object>();
    RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
    for (QueryDataBatch result : resultList) {
        if (result.getData() != null) {
            loader.load(result.getHeader().getDef(), result.getData());
            ValueVector v = loader.iterator().next().getValueVector();
            for (int j = 0; j < v.getAccessor().getValueCount(); j++) {
                if (v instanceof VarCharVector) {
                    res.add(new String(((VarCharVector) v).getAccessor().get(j)));
                } else {
                    res.add(v.getAccessor().getObject(j));
                }
            }
            loader.clear();
            result.release();
        }
    }
    return res.toArray();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) ArrayList(java.util.ArrayList) VarCharVector(org.apache.drill.exec.vector.VarCharVector)

Example 13 with VarCharVector

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

the class VaryingStringGen 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 14 with VarCharVector

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

the class TestWriter method simpleCsv.

@Test
public void simpleCsv() throws Exception {
    // before executing the test deleting the existing CSV files in /tmp/csvtest
    Path path = new Path("/tmp/csvtest");
    if (fs.exists(path)) {
        fs.delete(path, true);
    }
    String plan = Files.toString(FileUtils.getResourceAsFile("/writer/simple_csv_writer.json"), Charsets.UTF_8);
    List<QueryDataBatch> results = testPhysicalWithResults(plan);
    RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
    QueryDataBatch batch = results.get(0);
    assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
    VarCharVector fragmentIdV = (VarCharVector) batchLoader.getValueAccessorById(VarCharVector.class, 0).getValueVector();
    BigIntVector recordWrittenV = (BigIntVector) batchLoader.getValueAccessorById(BigIntVector.class, 1).getValueVector();
    // expected only one row in output
    assertEquals(1, batchLoader.getRecordCount());
    assertEquals("0_0", fragmentIdV.getAccessor().getObject(0).toString());
    assertEquals(132000, recordWrittenV.getAccessor().get(0));
    // now verify csv files are written to disk
    assertTrue(fs.exists(path));
    // expect two files
    FileStatus[] fileStatuses = fs.globStatus(new Path(path.toString(), "*.csv"));
    assertTrue(2 == fileStatuses.length);
    for (QueryDataBatch b : results) {
        b.release();
    }
    batchLoader.clear();
}
Also used : Path(org.apache.hadoop.fs.Path) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) FileStatus(org.apache.hadoop.fs.FileStatus) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VarCharVector(org.apache.drill.exec.vector.VarCharVector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) Test(org.junit.Test)

Example 15 with VarCharVector

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

the class TestConvertFunctions method getRunResult.

protected Object[] getRunResult(QueryType queryType, String planString) throws Exception {
    List<QueryDataBatch> resultList = testRunAndReturn(queryType, planString);
    List<Object> res = new ArrayList<Object>();
    RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
    for (QueryDataBatch result : resultList) {
        if (result.getData() != null) {
            loader.load(result.getHeader().getDef(), result.getData());
            @SuppressWarnings("resource") ValueVector v = loader.iterator().next().getValueVector();
            for (int j = 0; j < v.getAccessor().getValueCount(); j++) {
                if (v instanceof VarCharVector) {
                    res.add(new String(((VarCharVector) v).getAccessor().get(j)));
                } else {
                    res.add(v.getAccessor().getObject(j));
                }
            }
            loader.clear();
            result.release();
        }
    }
    return res.toArray();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) ArrayList(java.util.ArrayList) VarCharVector(org.apache.drill.exec.vector.VarCharVector)

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