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();
}
}
}
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);
}
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();
}
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();
}
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();
}
Aggregations