use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.
the class TestOptiqPlans method testOrderVarbinary.
@Test
public void testOrderVarbinary() throws Exception {
final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
try (final Drillbit bit1 = new Drillbit(config, serviceSet);
final DrillClient client = new DrillClient(config, serviceSet.getCoordinator())) {
bit1.run();
client.connect();
final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Resources.toString(Resources.getResource("physical_order_varbinary.json"), Charsets.UTF_8));
final RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator());
for (final QueryDataBatch b : results) {
System.out.println(String.format("Got %d results", b.getHeader().getRowCount()));
loader.load(b.getHeader().getDef(), b.getData());
for (final VectorWrapper vw : loader) {
System.out.println(vw.getValueVector().getField().getPath());
final ValueVector vv = vw.getValueVector();
for (int i = 0; i < vv.getAccessor().getValueCount(); i++) {
final Object o = vv.getAccessor().getObject(i);
if (vv instanceof VarBinaryVector) {
final VarBinaryVector.Accessor x = ((VarBinaryVector) vv).getAccessor();
final VarBinaryHolder vbh = new VarBinaryHolder();
x.get(i, vbh);
System.out.printf("%d..%d", vbh.start, vbh.end);
System.out.println("[" + new String((byte[]) vv.getAccessor().getObject(i)) + "]");
} else {
System.out.println(vv.getAccessor().getObject(i));
}
}
}
loader.clear();
b.release();
}
client.close();
}
}
use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.
the class TestReverseImplicitCast method twoWayCast.
@Test
public void twoWayCast(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
// Function checks for casting from Float, Double to Decimal data types
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(FileUtils.getResourceAsFile("/functions/cast/two_way_implicit_cast.json"), Charsets.UTF_8));
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 intAccessor1 = itr.next().getValueVector().getAccessor();
ValueVector.Accessor varcharAccessor1 = itr.next().getValueVector().getAccessor();
for (int i = 0; i < intAccessor1.getValueCount(); i++) {
System.out.println(intAccessor1.getObject(i));
assertEquals(intAccessor1.getObject(i), 10);
System.out.println(varcharAccessor1.getObject(i));
assertEquals(varcharAccessor1.getObject(i).toString(), "101");
}
batchLoader.clear();
for (QueryDataBatch result : results) {
result.release();
}
}
}
use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.
the class MergeJoinBatch method setRecordCountInContainer.
private void setRecordCountInContainer() {
for (VectorWrapper vw : container) {
Preconditions.checkArgument(!vw.isHyper());
vw.getValueVector().getMutator().setValueCount(getRecordCount());
}
}
use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.
the class ProjectRecordBatch method classifyExpr.
private void classifyExpr(final NamedExpression ex, final RecordBatch incoming, final ClassifierResult result) {
final NameSegment expr = ((SchemaPath) ex.getExpr()).getRootSegment();
final NameSegment ref = ex.getRef().getRootSegment();
final boolean exprHasPrefix = expr.getPath().contains(StarColumnHelper.PREFIX_DELIMITER);
final boolean refHasPrefix = ref.getPath().contains(StarColumnHelper.PREFIX_DELIMITER);
final boolean exprIsStar = expr.getPath().equals(StarColumnHelper.STAR_COLUMN);
final boolean refContainsStar = ref.getPath().contains(StarColumnHelper.STAR_COLUMN);
final boolean exprContainsStar = expr.getPath().contains(StarColumnHelper.STAR_COLUMN);
final boolean refEndsWithStar = ref.getPath().endsWith(StarColumnHelper.STAR_COLUMN);
String exprPrefix = EMPTY_STRING;
String exprSuffix = expr.getPath();
if (exprHasPrefix) {
// get the prefix of the expr
final String[] exprComponents = expr.getPath().split(StarColumnHelper.PREFIX_DELIMITER, 2);
assert (exprComponents.length == 2);
exprPrefix = exprComponents[0];
exprSuffix = exprComponents[1];
result.prefix = exprPrefix;
}
boolean exprIsFirstWildcard = false;
if (exprContainsStar) {
result.isStar = true;
final Integer value = (Integer) result.prefixMap.get(exprPrefix);
if (value == null) {
final Integer n = 1;
result.prefixMap.put(exprPrefix, n);
exprIsFirstWildcard = true;
} else {
final Integer n = value + 1;
result.prefixMap.put(exprPrefix, n);
}
}
final int incomingSchemaSize = incoming.getSchema().getFieldCount();
// input is '*' and output is 'prefix_*'
if (exprIsStar && refHasPrefix && refEndsWithStar) {
final String[] components = ref.getPath().split(StarColumnHelper.PREFIX_DELIMITER, 2);
assert (components.length == 2);
final String prefix = components[0];
result.outputNames = Lists.newArrayList();
for (final VectorWrapper<?> wrapper : incoming) {
final ValueVector vvIn = wrapper.getValueVector();
final String name = vvIn.getField().getPath();
// add the prefix to the incoming column name
final String newName = prefix + StarColumnHelper.PREFIX_DELIMITER + name;
addToResultMaps(newName, result, false);
}
} else // input and output are the same
if (expr.getPath().equalsIgnoreCase(ref.getPath()) && (!exprContainsStar || exprIsFirstWildcard)) {
if (exprContainsStar && exprHasPrefix) {
assert exprPrefix != null;
int k = 0;
result.outputNames = Lists.newArrayListWithCapacity(incomingSchemaSize);
for (int j = 0; j < incomingSchemaSize; j++) {
// initialize
result.outputNames.add(EMPTY_STRING);
}
for (final VectorWrapper<?> wrapper : incoming) {
final ValueVector vvIn = wrapper.getValueVector();
final String incomingName = vvIn.getField().getPath();
// get the prefix of the name
final String[] nameComponents = incomingName.split(StarColumnHelper.PREFIX_DELIMITER, 2);
// if incoming valuevector does not have a prefix, ignore it since this expression is not referencing it
if (nameComponents.length <= 1) {
k++;
continue;
}
final String namePrefix = nameComponents[0];
if (exprPrefix.equalsIgnoreCase(namePrefix)) {
final String newName = incomingName;
if (!result.outputMap.containsKey(newName)) {
result.outputNames.set(k, newName);
result.outputMap.put(newName, newName);
}
}
k++;
}
} else {
result.outputNames = Lists.newArrayList();
if (exprContainsStar) {
for (final VectorWrapper<?> wrapper : incoming) {
final ValueVector vvIn = wrapper.getValueVector();
final String incomingName = vvIn.getField().getPath();
if (refContainsStar) {
// allow dups since this is likely top-level project
addToResultMaps(incomingName, result, true);
} else {
addToResultMaps(incomingName, result, false);
}
}
} else {
final String newName = expr.getPath();
if (!refHasPrefix && !exprHasPrefix) {
// allow dups since this is likely top-level project
addToResultMaps(newName, result, true);
} else {
addToResultMaps(newName, result, false);
}
}
}
} else // input is wildcard and it is not the first wildcard
if (exprIsStar) {
result.outputNames = Lists.newArrayList();
for (final VectorWrapper<?> wrapper : incoming) {
final ValueVector vvIn = wrapper.getValueVector();
final String incomingName = vvIn.getField().getPath();
// allow dups since this is likely top-level project
addToResultMaps(incomingName, result, true);
}
} else // only the output has prefix
if (!exprHasPrefix && refHasPrefix) {
result.outputNames = Lists.newArrayList();
final String newName = ref.getPath();
addToResultMaps(newName, result, false);
} else // input has prefix but output does not
if (exprHasPrefix && !refHasPrefix) {
int k = 0;
result.outputNames = Lists.newArrayListWithCapacity(incomingSchemaSize);
for (int j = 0; j < incomingSchemaSize; j++) {
// initialize
result.outputNames.add(EMPTY_STRING);
}
for (final VectorWrapper<?> wrapper : incoming) {
final ValueVector vvIn = wrapper.getValueVector();
final String name = vvIn.getField().getPath();
final String[] components = name.split(StarColumnHelper.PREFIX_DELIMITER, 2);
if (components.length <= 1) {
k++;
continue;
}
final String namePrefix = components[0];
final String nameSuffix = components[1];
if (exprPrefix.equalsIgnoreCase(namePrefix)) {
// // case insensitive matching of prefix.
if (refContainsStar) {
// remove the prefix from the incoming column names
// for top level we need to make names unique
final String newName = getUniqueName(nameSuffix, result);
result.outputNames.set(k, newName);
} else if (exprSuffix.equalsIgnoreCase(nameSuffix)) {
// case insensitive matching of field name.
// example: ref: $f1, expr: T0<PREFIX><column_name>
final String newName = ref.getPath();
result.outputNames.set(k, newName);
}
} else {
result.outputNames.add(EMPTY_STRING);
}
k++;
}
} else // input and output have prefixes although they could be different...
if (exprHasPrefix && refHasPrefix) {
final String[] input = expr.getPath().split(StarColumnHelper.PREFIX_DELIMITER, 2);
assert (input.length == 2);
// not handled yet
assert false : "Unexpected project expression or reference";
} else {
// if the incoming schema's column name matches the expression name of the Project,
// then we just want to pick the ref name as the output column name
result.outputNames = Lists.newArrayList();
for (final VectorWrapper<?> wrapper : incoming) {
final ValueVector vvIn = wrapper.getValueVector();
final String incomingName = vvIn.getField().getPath();
if (expr.getPath().equalsIgnoreCase(incomingName)) {
// case insensitive matching of field name.
final String newName = ref.getPath();
addToResultMaps(newName, result, true);
}
}
}
}
use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.
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().getPath().equals(schemaPath)) {
vectors.add(newVector);
} else {
vectors.add(w.getValueVector());
}
container.remove(vector);
}
container.addCollection(vectors);
}
Aggregations