final public Expression Literal() throws ParseException, ParseException { LiteralExpr lit = new LiteralExpr(); String str = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING_LITERAL: str = StringLiteral(); lit.setValue(new StringLiteral(str)); break; case INTEGER_LITERAL: jj_consume_token(INTEGER_LITERAL); lit.setValue(new LongIntegerLiteral(new Long(token.image))); break; case FLOAT_LITERAL: jj_consume_token(FLOAT_LITERAL); lit.setValue(new FloatLiteral(new Float(token.image))); break; case DOUBLE_LITERAL: jj_consume_token(DOUBLE_LITERAL); lit.setValue(new DoubleLiteral(new Double(token.image))); break; case MISSING: jj_consume_token(MISSING); lit.setValue(MissingLiteral.INSTANCE); break; case NULL: jj_consume_token(NULL); lit.setValue(NullLiteral.INSTANCE); break; case TRUE: jj_consume_token(TRUE);
@Override public Void visit(LiteralExpr l, Integer step) { Literal lc = l.getValue(); if (lc.getLiteralType().equals(Literal.Type.TRUE) || lc.getLiteralType().equals(Literal.Type.FALSE) || lc.getLiteralType().equals(Literal.Type.NULL) || lc.getLiteralType().equals(Literal.Type.MISSING)) { out.println(skip(step) + "LiteralExpr [" + l.getValue().getLiteralType() + "]"); } else { out.println(skip(step) + "LiteralExpr [" + l.getValue().getLiteralType() + "] [" + l.getValue().getStringValue() + "]"); } return null; }
@Override public Pair<ILogicalOperator, LogicalVariable> visit(LiteralExpr l, Mutable<ILogicalOperator> tupSource) { SourceLocation sourceLoc = l.getSourceLocation(); LogicalVariable var = context.newVar(); AsterixConstantValue cValue = new AsterixConstantValue(ConstantHelper.objectFromLiteral(l.getValue())); ConstantExpression cExpr = new ConstantExpression(cValue); cExpr.setSourceLocation(sourceLoc); AssignOperator a = new AssignOperator(var, new MutableObject<>(cExpr)); a.setSourceLocation(sourceLoc); if (tupSource != null) { a.getInputs().add(tupSource); } return new Pair<>(a, var); }
public CaseExpression(Expression conditionExpr, List<Expression> whenExprs, List<Expression> thenExprs, Expression elseExpr) { this.conditionExpr = conditionExpr; this.whenExprs.addAll(whenExprs); this.thenExprs.addAll(thenExprs); // If no when expression matches the case expr, we return null this.elseExpr = elseExpr == null ? new LiteralExpr(NullLiteral.INSTANCE) : elseExpr; }
private CaseExpression normalizeCaseExpr(CaseExpression caseExpr) throws CompilationException { LiteralExpr trueLiteral = new LiteralExpr(TrueLiteral.INSTANCE); trueLiteral.setSourceLocation(caseExpr.getSourceLocation()); Expression conditionExpr = caseExpr.getConditionExpr(); if (trueLiteral.equals(conditionExpr)) { return caseExpr; } List<Expression> normalizedWhenExprs = new ArrayList<>(); for (Expression expr : caseExpr.getWhenExprs()) { OperatorExpr operatorExpr = new OperatorExpr(); operatorExpr.addOperand((Expression) SqlppRewriteUtil.deepCopy(expr)); operatorExpr.addOperand(caseExpr.getConditionExpr()); operatorExpr.addOperator(OperatorType.EQ); operatorExpr.setSourceLocation(expr.getSourceLocation()); normalizedWhenExprs.add(operatorExpr); } CaseExpression newCaseExpr = new CaseExpression(trueLiteral, normalizedWhenExprs, caseExpr.getThenExprs(), caseExpr.getElseExpr()); newCaseExpr.setSourceLocation(caseExpr.getSourceLocation()); return newCaseExpr; }
private static List<Expression> addArgs(Object... args) { List<Expression> argExprs = new ArrayList<>(); for (Object arg : args) { if (arg instanceof Integer) { argExprs.add(new LiteralExpr(new IntegerLiteral((Integer) arg))); } else if (arg instanceof String) { argExprs.add(new LiteralExpr(new StringLiteral((String) arg))); } else if (arg instanceof Expression) { argExprs.add((Expression) arg); } } return argExprs; }
final public Expression Literal() throws ParseException, ParseException { LiteralExpr lit = new LiteralExpr(); String str = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING_LITERAL: str = StringLiteral(); lit.setValue(new StringLiteral(str)); break; case INTEGER_LITERAL: jj_consume_token(INTEGER_LITERAL); lit.setValue(new LongIntegerLiteral(new Long(token.image))); break; case FLOAT_LITERAL: jj_consume_token(FLOAT_LITERAL); lit.setValue(new FloatLiteral(new Float(token.image))); break; case DOUBLE_LITERAL: jj_consume_token(DOUBLE_LITERAL); lit.setValue(new DoubleLiteral(new Double(token.image))); break; case MISSING: jj_consume_token(MISSING); lit.setValue(MissingLiteral.INSTANCE); break; case NULL: jj_consume_token(NULL); lit.setValue(NullLiteral.INSTANCE); break; case TRUE: jj_consume_token(TRUE);
public static Literal exprToStringLiteral(Expression expr) throws CompilationException { if (expr.getKind() != Expression.Kind.LITERAL_EXPRESSION) { throw new CompilationException(ErrorCode.PARSE_ERROR, "Expected expression can only be of type %1$s", Expression.Kind.LITERAL_EXPRESSION); } LiteralExpr keyLiteralExpr = (LiteralExpr) expr; Literal keyLiteral = keyLiteralExpr.getValue(); if (keyLiteral.getLiteralType() != Literal.Type.STRING) { throw new CompilationException(ErrorCode.PARSE_ERROR, "Expected Literal can only be of type %1$s", Literal.Type.STRING); } return keyLiteral; }
private FieldBinding generateFieldBinding(String fieldName, Expression fieldValueExpr, Set<String> outFieldNames, SourceLocation sourceLoc) throws CompilationException { if (!outFieldNames.add(fieldName)) { throw new CompilationException(ErrorCode.DUPLICATE_FIELD_NAME, sourceLoc, fieldName); } return new FieldBinding(new LiteralExpr(new StringLiteral(fieldName)), fieldValueExpr); }
final public Expression Literal() throws ParseException, ParseException { LiteralExpr lit = new LiteralExpr(); String str = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING_LITERAL: str = StringLiteral(); lit.setValue(new StringLiteral(str)); break; case INTEGER_LITERAL: jj_consume_token(INTEGER_LITERAL); try { lit.setValue(new LongIntegerLiteral(Long.valueOf(token.image))); } catch (NumberFormatException e) { {if (true) throw new SqlppParseException(getSourceLocation(token), "Could not parse numeric literal \u005c"" + LogRedactionUtil.userData(token.image) +'"');} jj_consume_token(FLOAT_LITERAL); try { lit.setValue(new FloatLiteral(Float.valueOf(token.image))); } catch (NumberFormatException e) { {if (true) throw new SqlppParseException(getSourceLocation(token), "Could not parse numeric literal \u005c"" + LogRedactionUtil.userData(token.image) +'"');} jj_consume_token(DOUBLE_LITERAL); try { lit.setValue(new DoubleLiteral(Double.valueOf(token.image))); } catch (NumberFormatException e) { {if (true) throw new SqlppParseException(getSourceLocation(token), "Could not parse numeric literal \u005c"" + LogRedactionUtil.userData(token.image) +'"');} case MISSING: jj_consume_token(MISSING); lit.setValue(MissingLiteral.INSTANCE);
public static List<List<List<String>>> getFunctionDependencies(IQueryRewriter rewriter, Expression expression, MetadataProvider metadataProvider) throws CompilationException { Set<CallExpr> functionCalls = rewriter.getFunctionCalls(expression); //Get the List of used functions and used datasets List<List<String>> datasourceDependencies = new ArrayList<>(); List<List<String>> functionDependencies = new ArrayList<>(); for (CallExpr functionCall : functionCalls) { FunctionSignature signature = functionCall.getFunctionSignature(); FunctionIdentifier fid = new FunctionIdentifier(signature.getNamespace(), signature.getName(), signature.getArity()); if (fid.equals(BuiltinFunctions.DATASET)) { Pair<String, String> path = DatasetUtil.getDatasetInfo(metadataProvider, ((LiteralExpr) functionCall.getExprList().get(0)).getValue().getStringValue()); datasourceDependencies.add(Arrays.asList(path.first, path.second)); } else if (BuiltinFunctions.isBuiltinCompilerFunction(signature, false)) { continue; } else { functionDependencies.add(Arrays.asList(signature.getNamespace(), signature.getName(), Integer.toString(signature.getArity()))); } } List<List<List<String>>> dependencies = new ArrayList<>(); dependencies.add(datasourceDependencies); dependencies.add(functionDependencies); return dependencies; }
private Expression resolveAsFieldAccess(VariableExpr var, String fieldName, SourceLocation sourceLoc) { List<Expression> argList = new ArrayList<>(2); argList.add(var); argList.add(new LiteralExpr(new StringLiteral(fieldName))); CallExpr callExpr = new CallExpr(new FunctionSignature(BuiltinFunctions.FIELD_ACCESS_BY_NAME), argList); callExpr.setSourceLocation(sourceLoc); return callExpr; }
LiteralExpr ds = new LiteralExpr(); ds.setValue( new StringLiteral(name) ); nameArg = ds; break;
private Map<Expression, ColumnAliasBinding> mapRecordConstructor(RecordConstructor rc) { Map<Expression, ColumnAliasBinding> exprMap = new HashMap<>(); for (FieldBinding binding : rc.getFbList()) { Expression leftExpr = binding.getLeftExpr(); // We only need to deal with the case that the left expression (for a field name) is // a string literal. Otherwise, it is different from a column alias in a projection // (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)), ColumnAliasBinding.of(binding)); } } return exprMap; }
private Expression resolveAsDataset(String dataverseName, String datasetName, SourceLocation sourceLoc) throws CompilationException { if (!datasetExists(dataverseName, datasetName, sourceLoc)) { throwUnresolvableError(dataverseName, datasetName, sourceLoc); } String fullyQualifiedName = dataverseName == null ? datasetName : dataverseName + "." + datasetName; List<Expression> argList = new ArrayList<>(1); argList.add(new LiteralExpr(new StringLiteral(fullyQualifiedName))); CallExpr callExpr = new CallExpr(new FunctionSignature(BuiltinFunctions.DATASET), argList); callExpr.setSourceLocation(sourceLoc); return callExpr; }
LiteralExpr ds = new LiteralExpr(); ds.setValue( new StringLiteral(name) ); nameArg = ds; break;
@Override public Void visit(CallExpr callExpr, Integer step) throws CompilationException { FunctionSignature signature = callExpr.getFunctionSignature(); if (signature.getNamespace() != null && signature.getNamespace().equals("Metadata") && signature.getName().equals("dataset") && signature.getArity() == 1) { LiteralExpr expr = (LiteralExpr) callExpr.getExprList().get(0); out.print(normalize(expr.getValue().getStringValue())); } else { printHints(callExpr.getHints(), step); out.print(generateFullName(callExpr.getFunctionSignature().getNamespace(), callExpr.getFunctionSignature().getName()) + "("); printDelimitedExpressions(callExpr.getExprList(), COMMA, step); out.print(")"); } return null; }
protected AbstractFunctionCallExpression createRecordConstructor(List<Pair<Expression, Identifier>> fieldList, Mutable<ILogicalOperator> inputOp, SourceLocation sourceLoc) throws CompilationException { List<Mutable<ILogicalExpression>> args = new ArrayList<>(); for (Pair<Expression, Identifier> field : fieldList) { ILogicalExpression fieldNameExpr = langExprToAlgExpression(new LiteralExpr(new StringLiteral(field.second.getValue())), inputOp).first; args.add(new MutableObject<>(fieldNameExpr)); ILogicalExpression fieldExpr = langExprToAlgExpression(field.first, inputOp).first; args.add(new MutableObject<>(fieldExpr)); } ScalarFunctionCallExpression recordConstr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR), args); recordConstr.setSourceLocation(sourceLoc); return recordConstr; }
@Override public Void visit(LiteralExpr l, Integer step) { Literal lc = l.getValue(); if (lc.getLiteralType().equals(Literal.Type.TRUE) || lc.getLiteralType().equals(Literal.Type.FALSE) || lc.getLiteralType().equals(Literal.Type.NULL) || lc.getLiteralType().equals(Literal.Type.MISSING)) { out.print(lc.getLiteralType().toString().toLowerCase()); } else if (lc.getLiteralType().equals(Literal.Type.STRING)) { out.print(revertStringToLiteral(lc.getStringValue())); } else { if (lc.getLiteralType().equals(Literal.Type.FLOAT)) { out.printf("%ff", lc.getValue()); } else if (lc.getLiteralType().equals(Literal.Type.DOUBLE)) { DecimalFormat df = new DecimalFormat("#.#"); df.setMinimumFractionDigits(1); df.setMaximumFractionDigits(16); out.print(df.format(lc.getValue())); } else { out.print(lc.getStringValue()); } } return null; }
@Override public Void visit(DeleteStatement deleteStmt, Void visitArg) { List<Expression> arguments = new ArrayList<>(); Identifier dataverseName = deleteStmt.getDataverseName(); Identifier datasetName = deleteStmt.getDatasetName(); String arg = dataverseName == null ? datasetName.getValue() : dataverseName.getValue() + "." + datasetName.getValue(); LiteralExpr argumentLiteral = new LiteralExpr(new StringLiteral(arg)); arguments.add(argumentLiteral); CallExpr callExpression = new CallExpr(new FunctionSignature(BuiltinFunctions.DATASET), arguments); List<Clause> clauseList = new ArrayList<>(); VariableExpr var = deleteStmt.getVariableExpr(); Clause forClause = new ForClause(var, callExpression); clauseList.add(forClause); Clause whereClause = null; Expression condition = deleteStmt.getCondition(); if (condition != null) { whereClause = new WhereClause(condition); clauseList.add(whereClause); } VariableExpr returnExpr = new VariableExpr(var.getVar()); returnExpr.setIsNewVar(false); FLWOGRExpression flowgr = new FLWOGRExpression(clauseList, returnExpr); Query query = new Query(false); query.setBody(flowgr); deleteStmt.setQuery(query); return null; }