Search in sources :

Example 56 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by axbaretto.

the class TestDateTypes method testInterval.

@Test
public void testInterval() throws Exception {
    try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
        Drillbit bit = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(DrillFileUtils.getResourceAsFile("/record/vector/test_interval.json"), Charsets.UTF_8).replace("#{TEST_FILE}", "/test_simple_interval.json"));
        RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
        QueryDataBatch batch = results.get(0);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();
        ValueVector.Accessor accessor = itr.next().getValueVector().getAccessor();
        // Check the interval type
        assertEquals((accessor.getObject(0).toString()), ("2 years 2 months 1 day 1:20:35.0"));
        assertEquals((accessor.getObject(1).toString()), ("2 years 2 months 0 days 0:0:0.0"));
        assertEquals((accessor.getObject(2).toString()), ("0 years 0 months 0 days 1:20:35.0"));
        assertEquals((accessor.getObject(3).toString()), ("2 years 2 months 1 day 1:20:35.897"));
        assertEquals((accessor.getObject(4).toString()), ("0 years 0 months 0 days 0:0:35.4"));
        assertEquals((accessor.getObject(5).toString()), ("1 year 10 months 1 day 0:-39:-25.0"));
        accessor = itr.next().getValueVector().getAccessor();
        // Check the interval year type
        assertEquals((accessor.getObject(0).toString()), ("2 years 2 months "));
        assertEquals((accessor.getObject(1).toString()), ("2 years 2 months "));
        assertEquals((accessor.getObject(2).toString()), ("0 years 0 months "));
        assertEquals((accessor.getObject(3).toString()), ("2 years 2 months "));
        assertEquals((accessor.getObject(4).toString()), ("0 years 0 months "));
        assertEquals((accessor.getObject(5).toString()), ("1 year 10 months "));
        accessor = itr.next().getValueVector().getAccessor();
        // Check the interval day type
        assertEquals((accessor.getObject(0).toString()), ("1 day 1:20:35.0"));
        assertEquals((accessor.getObject(1).toString()), ("0 days 0:0:0.0"));
        assertEquals((accessor.getObject(2).toString()), ("0 days 1:20:35.0"));
        assertEquals((accessor.getObject(3).toString()), ("1 day 1:20:35.897"));
        assertEquals((accessor.getObject(4).toString()), ("0 days 0:0:35.4"));
        assertEquals((accessor.getObject(5).toString()), ("1 day 0:-39:-25.0"));
        batchLoader.clear();
        for (QueryDataBatch b : results) {
            b.release();
        }
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test) SlowTest(org.apache.drill.categories.SlowTest) VectorTest(org.apache.drill.categories.VectorTest)

Example 57 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by axbaretto.

the class TestOutputMutator method replace.

private void replace(ValueVector newVector, SchemaPath schemaPath) {
    List<ValueVector> vectors = Lists.newArrayList();
    for (VectorWrapper w : container) {
        ValueVector vector = w.getValueVector();
        if (vector.getField().getName().equals(schemaPath.getRootSegmentPath())) {
            vectors.add(newVector);
        } else {
            vectors.add(w.getValueVector());
        }
        container.remove(vector);
    }
    container.addCollection(vectors);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) VectorWrapper(org.apache.drill.exec.record.VectorWrapper)

Example 58 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by axbaretto.

the class ParquetRecordReaderTest method testNullableFilter.

@Test
public void testNullableFilter() throws Exception {
    final List<QueryDataBatch> result = testSqlWithResults("select count(wr_return_quantity) as row_count from dfs.`tmp/web_returns` where wr_return_quantity = 1");
    assertEquals("Only expected one batch with data, and then the empty finishing batch.", 2, result.size());
    final RecordBatchLoader loader = new RecordBatchLoader(getDrillbitContext().getAllocator());
    final QueryDataBatch b = result.get(0);
    loader.load(b.getHeader().getDef(), b.getData());
    final VectorWrapper vw = loader.getValueAccessorById(BigIntVector.class, loader.getValueVectorId(SchemaPath.getCompoundPath("row_count")).getFieldIds());
    assertEquals(3573l, vw.getValueVector().getAccessor().getObject(0));
    b.release();
    loader.clear();
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) Test(org.junit.Test)

Example 59 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by axbaretto.

the class ParquetResultListener method dataArrived.

@Override
public synchronized void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
    logger.debug("result arrived in test batch listener.");
    int columnValCounter = 0;
    FieldInfo currentField;
    count += result.getHeader().getRowCount();
    boolean schemaChanged = false;
    final RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
    try {
        schemaChanged = batchLoader.load(result.getHeader().getDef(), result.getData());
    // TODO:  Clean:  DRILL-2933:  That load(...) no longer throws
    // SchemaChangeException, so check/clean catch clause below.
    } catch (SchemaChangeException e) {
        throw new RuntimeException(e);
    }
    // used to make sure each vector in the batch has the same number of records
    int valueCount = batchLoader.getRecordCount();
    // print headers.
    if (schemaChanged) {
    }
    for (final VectorWrapper vw : batchLoader) {
        final ValueVector vv = vw.getValueVector();
        currentField = props.fields.get(vv.getField().getName());
        if (!valuesChecked.containsKey(vv.getField().getName())) {
            valuesChecked.put(vv.getField().getName(), 0);
            columnValCounter = 0;
        } else {
            columnValCounter = valuesChecked.get(vv.getField().getName());
        }
        printColumnMajor(vv);
        if (testValues) {
            for (int j = 0; j < vv.getAccessor().getValueCount(); j++) {
                assertField(vv, j, currentField.type, currentField.values[columnValCounter % 3], currentField.name + "/");
                columnValCounter++;
            }
        } else {
            columnValCounter += vv.getAccessor().getValueCount();
        }
        valuesChecked.remove(vv.getField().getName());
        assertEquals("Mismatched value count for vectors in the same batch.", valueCount, vv.getAccessor().getValueCount());
        valuesChecked.put(vv.getField().getName(), columnValCounter);
    }
    if (ParquetRecordReaderTest.VERBOSE_DEBUG) {
        printRowMajor(batchLoader);
    }
    batchCounter++;
    batchLoader.clear();
    result.release();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper)

Example 60 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by axbaretto.

the class TestInfoSchema method describeSchemaOutput.

@Test
public void describeSchemaOutput() throws Exception {
    final List<QueryDataBatch> result = testSqlWithResults("describe schema dfs.tmp");
    assertTrue(result.size() == 1);
    final QueryDataBatch batch = result.get(0);
    final RecordBatchLoader loader = new RecordBatchLoader(getDrillbitContext().getAllocator());
    loader.load(batch.getHeader().getDef(), batch.getData());
    // check schema column value
    final VectorWrapper schemaValueVector = loader.getValueAccessorById(NullableVarCharVector.class, loader.getValueVectorId(SchemaPath.getCompoundPath("schema")).getFieldIds());
    String schema = schemaValueVector.getValueVector().getAccessor().getObject(0).toString();
    assertEquals("dfs.tmp", schema);
    // check properties column value
    final VectorWrapper propertiesValueVector = loader.getValueAccessorById(NullableVarCharVector.class, loader.getValueVectorId(SchemaPath.getCompoundPath("properties")).getFieldIds());
    String properties = propertiesValueVector.getValueVector().getAccessor().getObject(0).toString();
    final Map configMap = mapper.readValue(properties, Map.class);
    // check some stable properties existence
    assertTrue(configMap.containsKey("connection"));
    assertTrue(configMap.containsKey("config"));
    assertTrue(configMap.containsKey("formats"));
    assertFalse(configMap.containsKey("workspaces"));
    // check some stable properties values
    assertEquals("file", configMap.get("type"));
    final FileSystemConfig testConfig = (FileSystemConfig) bits[0].getContext().getStorage().getPlugin("dfs").getConfig();
    final String tmpSchemaLocation = testConfig.workspaces.get("tmp").getLocation();
    assertEquals(tmpSchemaLocation, configMap.get("location"));
    batch.release();
    loader.clear();
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig) Map(java.util.Map) Test(org.junit.Test) SqlTest(org.apache.drill.categories.SqlTest)

Aggregations

VectorWrapper (org.apache.drill.exec.record.VectorWrapper)73 ValueVector (org.apache.drill.exec.vector.ValueVector)44 Test (org.junit.Test)39 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)35 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)34 DrillClient (org.apache.drill.exec.client.DrillClient)28 Drillbit (org.apache.drill.exec.server.Drillbit)28 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)28 SlowTest (org.apache.drill.categories.SlowTest)18 SchemaPath (org.apache.drill.common.expression.SchemaPath)11 ExecTest (org.apache.drill.exec.ExecTest)9 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)9 VectorContainer (org.apache.drill.exec.record.VectorContainer)9 MaterializedField (org.apache.drill.exec.record.MaterializedField)7 IOException (java.io.IOException)6 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)6 Stopwatch (com.google.common.base.Stopwatch)5 OperatorTest (org.apache.drill.categories.OperatorTest)5 TypeProtos (org.apache.drill.common.types.TypeProtos)5 TransferPair (org.apache.drill.exec.record.TransferPair)5