use of org.apache.asterix.lang.common.expression.FieldBinding in project asterixdb by apache.
the class InlineColumnAliasVisitor method mapRecordConstructor.
private Map<Expression, Expression> mapRecordConstructor(RecordConstructor rc) {
Map<Expression, Expression> exprMap = new HashMap<>();
for (FieldBinding binding : rc.getFbList()) {
Expression leftExpr = binding.getLeftExpr();
// (e.g., foo.name AS name) in regular SQL SELECT.
if (leftExpr.getKind() != Kind.LITERAL_EXPRESSION) {
continue;
}
LiteralExpr literalExpr = (LiteralExpr) leftExpr;
if (literalExpr.getValue().getLiteralType() == Literal.Type.STRING) {
String fieldName = SqlppVariableUtil.toInternalVariableName(literalExpr.getValue().getStringValue());
exprMap.put(new VariableExpr(new VarIdentifier(fieldName)), binding.getRightExpr());
}
}
return exprMap;
}
use of org.apache.asterix.lang.common.expression.FieldBinding in project asterixdb by apache.
the class QueryPrintVisitor method visit.
@Override
public Void visit(RecordConstructor rc, Integer step) throws CompilationException {
out.println(skip(step) + "RecordConstructor [");
// fbList accept visitor
for (FieldBinding fb : rc.getFbList()) {
out.println(skip(step + 1) + "(");
fb.getLeftExpr().accept(this, step + 2);
out.println(skip(step + 2) + ":");
fb.getRightExpr().accept(this, step + 2);
out.println(skip(step + 1) + ")");
}
out.println(skip(step) + "]");
return null;
}
use of org.apache.asterix.lang.common.expression.FieldBinding in project asterixdb by apache.
the class SqlppExpressionToPlanTranslator method generateReturnExpr.
// Generates the return expression for a select clause.
private Expression generateReturnExpr(SelectClause selectClause, SelectBlock selectBlock) {
SelectRegular selectRegular = selectClause.getSelectRegular();
List<FieldBinding> fieldBindings = new ArrayList<>();
List<Projection> projections = selectRegular.getProjections();
for (Projection projection : projections) {
if (projection.star()) {
if (selectBlock.hasGroupbyClause()) {
fieldBindings.addAll(getGroupBindings(selectBlock.getGroupbyClause()));
} else if (selectBlock.hasFromClause()) {
fieldBindings.addAll(getFromBindings(selectBlock.getFromClause()));
}
} else {
fieldBindings.add(new FieldBinding(new LiteralExpr(new StringLiteral(projection.getName())), projection.getExpression()));
}
}
return new RecordConstructor(fieldBindings);
}
use of org.apache.asterix.lang.common.expression.FieldBinding in project asterixdb by apache.
the class LangRecordParseUtil method parseRecord.
public static void parseRecord(RecordConstructor recordValue, ArrayBackedValueStorage serialized, boolean tagged, List<Pair<String, String>> defaults) throws HyracksDataException {
AMutableString fieldNameString = new AMutableString(null);
ArrayBackedValueStorage fieldName = new ArrayBackedValueStorage();
ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
RecordBuilder recordBuilder = new RecordBuilder();
recordBuilder.reset(RecordUtil.FULLY_OPEN_RECORD_TYPE);
recordBuilder.init();
List<FieldBinding> fbList = recordValue.getFbList();
HashSet<String> fieldNames = new HashSet<>();
for (FieldBinding fb : fbList) {
fieldName.reset();
fieldValue.reset();
// get key
fieldNameString.setValue(exprToStringLiteral(fb.getLeftExpr()).getStringValue());
if (!fieldNames.add(fieldNameString.getStringValue())) {
throw new HyracksDataException("Field " + fieldNameString.getStringValue() + " was specified multiple times");
}
stringSerde.serialize(fieldNameString, fieldName.getDataOutput());
// get value
parseExpression(fb.getRightExpr(), fieldValue);
recordBuilder.addField(fieldName, fieldValue);
}
// defaults
for (Pair<String, String> kv : defaults) {
if (!fieldNames.contains(kv.first)) {
fieldName.reset();
fieldValue.reset();
stringSerde.serialize(new AString(kv.first), fieldName.getDataOutput());
stringSerde.serialize(new AString(kv.second), fieldValue.getDataOutput());
recordBuilder.addField(fieldName, fieldValue);
}
}
recordBuilder.write(serialized.getDataOutput(), tagged);
}
use of org.apache.asterix.lang.common.expression.FieldBinding in project asterixdb by apache.
the class FormatPrintVisitor method visit.
@Override
public Void visit(RecordConstructor rc, Integer step) throws CompilationException {
out.print("{");
// print all field bindings
int size = rc.getFbList().size();
int index = 0;
for (FieldBinding fb : rc.getFbList()) {
fb.getLeftExpr().accept(this, step + 2);
out.print(":");
fb.getRightExpr().accept(this, step + 2);
if (++index < size) {
out.print(COMMA);
}
}
out.print("}");
return null;
}
Aggregations