result.outputNames.add(EMPTY_STRING);
}
}
private void classifyExpr(NamedExpression ex, RecordBatch incoming, ClassifierResult result) {
NameSegment expr = ((SchemaPath)ex.getExpr()).getRootSegment();
NameSegment ref = ex.getRef().getRootSegment();
boolean exprHasPrefix = expr.getPath().contains(StarColumnHelper.PREFIX_DELIMITER);
boolean refHasPrefix = ref.getPath().contains(StarColumnHelper.PREFIX_DELIMITER);
boolean exprIsStar = expr.getPath().equals(StarColumnHelper.STAR_COLUMN);
boolean refIsStar = ref.getPath().equals(StarColumnHelper.STAR_COLUMN);
boolean exprContainsStar = expr.getPath().contains(StarColumnHelper.STAR_COLUMN);
boolean refEndsWithStar = ref.getPath().endsWith(StarColumnHelper.STAR_COLUMN);
String exprPrefix = EMPTY_STRING;
if (exprHasPrefix) {
// get the prefix of the expr
String[] exprComponents = expr.getPath().split(StarColumnHelper.PREFIX_DELIMITER, 2);
assert(exprComponents.length == 2);
exprPrefix = exprComponents[0];
result.prefix = exprPrefix;
}
if (exprContainsStar) {
result.isStar = true;
Integer value = (Integer) result.prefixMap.get(exprPrefix);
if (value == null) {
Integer n = 1;
result.prefixMap.put(exprPrefix, n);
} else {
Integer n = value + 1;
result.prefixMap.put(exprPrefix, n);
}
}
int incomingSchemaSize = incoming.getSchema().getFieldCount();
// for debugging..
// if (incomingSchemaSize > 9) {
// assert false;
// }
// input is '*' and output is 'prefix_*'
if (exprIsStar && refHasPrefix && refEndsWithStar) {
String[] components = ref.getPath().split(StarColumnHelper.PREFIX_DELIMITER, 2);
assert(components.length == 2);
String prefix = components[0];
result.outputNames = Lists.newArrayList();
for(VectorWrapper<?> wrapper : incoming) {
ValueVector vvIn = wrapper.getValueVector();
String name = vvIn.getField().getPath().getRootSegment().getPath();
// add the prefix to the incoming column name
String newName = prefix + StarColumnHelper.PREFIX_DELIMITER + name;
addToResultMaps(newName, result, false);
}
}
// input and output are the same
else if (expr.getPath().equals(ref.getPath())) {
if (exprContainsStar && exprHasPrefix) {
assert exprPrefix != null;
int k = 0;
result.outputNames = Lists.newArrayListWithCapacity(incomingSchemaSize);
for (int j=0; j < incomingSchemaSize; j++) {
result.outputNames.add(EMPTY_STRING); // initialize
}
for(VectorWrapper<?> wrapper : incoming) {
ValueVector vvIn = wrapper.getValueVector();
String incomingName = vvIn.getField().getPath().getRootSegment().getPath();
// get the prefix of the name
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;
}
String namePrefix = nameComponents[0];
if (exprPrefix.equals(namePrefix)) {
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 (exprIsStar) {
for (VectorWrapper<?> wrapper : incoming) {
ValueVector vvIn = wrapper.getValueVector();
String incomingName = vvIn.getField().getPath().getRootSegment().getPath();
if (refIsStar) {
addToResultMaps(incomingName, result, true); // allow dups since this is likely top-level project
} else {
addToResultMaps(incomingName, result, false);
}
}
} else {
String newName = expr.getPath();
if (!refHasPrefix && !exprHasPrefix) {
addToResultMaps(newName, result, true); // allow dups since this is likely top-level project
} else {
addToResultMaps(newName, result, false);
}
}
}
}
// only the output has prefix
else if (!exprHasPrefix && refHasPrefix) {
result.outputNames = Lists.newArrayList();
String newName = ref.getPath();
addToResultMaps(newName, result, false);
}
// input has prefix but output does not; this would happen for a top-level project
else if (exprHasPrefix && !refHasPrefix) {
int k = 0;