@Override Expression getExpression() { return fieldBinding.getRightExpr(); }
@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; }
@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; }
public static AdmObjectNode toNode(RecordConstructor recordConstructor) throws CompilationException { AdmObjectNode node = new AdmObjectNode(); final List<FieldBinding> fbList = recordConstructor.getFbList(); for (int i = 0; i < fbList.size(); i++) { FieldBinding binding = fbList.get(i); String key = LangRecordParseUtil.exprToStringLiteral(binding.getLeftExpr()).getStringValue(); IAdmNode value = ExpressionUtils.toNode(binding.getRightExpr()); node.set(key, value); } return node; }
@Override public Boolean visit(RecordConstructor rc, ILangExpression arg) throws CompilationException { for (FieldBinding fb : rc.getFbList()) { if (visit(fb.getLeftExpr(), arg)) { return true; } if (visit(fb.getRightExpr(), arg)) { return true; } } return false; }
@Override public Void visit(RecordConstructor rc, Void arg) throws CompilationException { for (FieldBinding fb : rc.getFbList()) { fb.getLeftExpr().accept(this, arg); fb.getRightExpr().accept(this, arg); } return null; }
@Override public Void visit(RecordConstructor rc, Collection<VariableExpr> freeVars) throws CompilationException { for (FieldBinding binding : rc.getFbList()) { binding.getLeftExpr().accept(this, freeVars); binding.getRightExpr().accept(this, freeVars); } return null; }
@Override public Boolean visit(RecordConstructor rc, ILangExpression parentSelectBlock) throws CompilationException { for (FieldBinding fieldBinding : rc.getFbList()) { ILangExpression leftExpr = fieldBinding.getLeftExpr(); ILangExpression rightExpr = fieldBinding.getRightExpr(); if (leftExpr.accept(this, parentSelectBlock)) { return true; } if (rightExpr.accept(this, parentSelectBlock)) { return true; } } return false; }
@Override public RecordConstructor visit(RecordConstructor rc, Void arg) throws CompilationException { List<FieldBinding> bindings = new ArrayList<>(); for (FieldBinding binding : rc.getFbList()) { FieldBinding fb = new FieldBinding((Expression) binding.getLeftExpr().accept(this, arg), (Expression) binding.getRightExpr().accept(this, arg)); bindings.add(fb); } RecordConstructor copy = new RecordConstructor(bindings); copy.setSourceLocation(rc.getSourceLocation()); copy.addHints(rc.getHints()); return copy; }
@Override public Expression visit(RecordConstructor rc, ILangExpression arg) throws CompilationException { for (FieldBinding binding : rc.getFbList()) { binding.setLeftExpr(visit(binding.getLeftExpr(), rc)); binding.setRightExpr(visit(binding.getRightExpr(), rc)); } return rc; }
@Override public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(RecordConstructor rc, VariableSubstitutionEnvironment env) throws CompilationException { List<FieldBinding> oldFbs = rc.getFbList(); ArrayList<FieldBinding> newFbs = new ArrayList<>(oldFbs.size()); for (FieldBinding fb : oldFbs) { Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fb.getLeftExpr().accept(this, env); Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = fb.getRightExpr().accept(this, env); FieldBinding fb2 = new FieldBinding((Expression) p1.first, (Expression) p2.first); newFbs.add(fb2); } RecordConstructor newRc = new RecordConstructor(newFbs); newRc.setSourceLocation(rc.getSourceLocation()); newRc.addHints(rc.getHints()); return new Pair<>(newRc, env); }
@Override public Boolean visit(RecordConstructor rc, List<FunctionDecl> arg) throws CompilationException { boolean changed = false; for (FieldBinding b : rc.getFbList()) { Pair<Boolean, Expression> leftExprInlined = inlineUdfsInExpr(b.getLeftExpr(), arg); b.setLeftExpr(leftExprInlined.second); changed = changed || leftExprInlined.first; Pair<Boolean, Expression> rightExprInlined = inlineUdfsInExpr(b.getRightExpr(), arg); b.setRightExpr(rightExprInlined.second); changed = changed || rightExprInlined.first; } return changed; }
@Override public Expression visit(RecordConstructor rc, ILangExpression arg) throws CompilationException { for (FieldBinding binding : rc.getFbList()) { binding.setLeftExpr(visit(binding.getLeftExpr(), rc)); binding.setRightExpr(visit(binding.getRightExpr(), rc)); } return rc; }
public static AdmObjectNode parseRecord(RecordConstructor recordValue, List<Pair<String, String>> defaults) throws HyracksDataException, CompilationException { AdmObjectNode record = new AdmObjectNode(); AMutableString fieldNameString = new AMutableString(null); List<FieldBinding> fbList = recordValue.getFbList(); HashSet<String> fieldNames = new HashSet<>(); for (FieldBinding fb : fbList) { // get key fieldNameString.setValue(exprToStringLiteral(fb.getLeftExpr()).getStringValue()); if (!fieldNames.add(fieldNameString.getStringValue())) { throw new HyracksDataException( "Field " + fieldNameString.getStringValue() + " was specified multiple times"); } // get value IAdmNode value = parseExpression(fb.getRightExpr()); record.set(fieldNameString.getStringValue(), value); } // defaults for (Pair<String, String> kv : defaults) { if (!fieldNames.contains(kv.first)) { record.set(kv.first, new AdmStringNode(kv.second)); } } return record; }
@Override public Pair<ILogicalOperator, LogicalVariable> visit(RecordConstructor rc, Mutable<ILogicalOperator> tupSource) throws CompilationException { AbstractFunctionCallExpression f = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR)); f.setSourceLocation(rc.getSourceLocation()); LogicalVariable v1 = context.newVar(); AssignOperator a = new AssignOperator(v1, new MutableObject<>(f)); a.setSourceLocation(rc.getSourceLocation()); Mutable<ILogicalOperator> topOp = tupSource; for (FieldBinding fb : rc.getFbList()) { Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = langExprToAlgExpression(fb.getLeftExpr(), topOp); f.getArguments().add(new MutableObject<>(eo1.first)); topOp = eo1.second; Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = langExprToAlgExpression(fb.getRightExpr(), topOp); f.getArguments().add(new MutableObject<>(eo2.first)); topOp = eo2.second; } a.getInputs().add(topOp); return new Pair<>(a, v1); }