Tabnine Logo
LambdaExpression
Code IndexAdd Tabnine to your IDE (free)

How to use
LambdaExpression
in
com.facebook.presto.sql.tree

Best Java code snippets using com.facebook.presto.sql.tree.LambdaExpression (Showing top 20 results out of 315)

origin: prestodb/presto

  @Override
  public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
  {
    return new LambdaExpression(node.getArguments(), treeRewriter.rewrite(node.getBody(), context));
  }
}, expression);
origin: prestodb/presto

@Override
protected String visitLambdaExpression(LambdaExpression node, Void context)
{
  StringBuilder builder = new StringBuilder();
  builder.append('(');
  Joiner.on(", ").appendTo(builder, node.getArguments());
  builder.append(") -> ");
  builder.append(process(node.getBody(), context));
  return builder.toString();
}
origin: prestodb/presto

  @Override
  public Expression rewriteTryExpression(TryExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
  {
    Expression expression = treeRewriter.rewrite(node.getInnerExpression(), context);
    return new FunctionCall(
        QualifiedName.of("$internal$try"),
        ImmutableList.of(new LambdaExpression(ImmutableList.of(), expression)));
  }
}
origin: prestodb/presto

@Override
protected Boolean visitLambdaExpression(LambdaExpression node, Void context)
{
  return process(node.getBody(), context);
}
origin: prestodb/presto

  @Override
  public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
  {
    for (LambdaArgumentDeclaration argument : node.getArguments()) {
      String argumentName = argument.getName().getValue();
      // Symbol names are unique. As a result, a symbol should never be excluded multiple times.
      checkArgument(!excludedNames.contains(argumentName));
      excludedNames.add(argumentName);
    }
    Expression result = treeRewriter.defaultRewrite(node, context);
    for (LambdaArgumentDeclaration argument : node.getArguments()) {
      excludedNames.remove(argument.getName().getValue());
    }
    return result;
  }
}
origin: prestodb/presto

  @Override
  protected Void visitLambdaExpression(LambdaExpression node, Set<String> lambdaArgumentNames)
  {
    return process(node.getBody(), ImmutableSet.<String>builder()
        .addAll(lambdaArgumentNames)
        .addAll(node.getArguments().stream()
            .map(LambdaArgumentDeclaration::getName)
            .map(Identifier::getValue)
            .collect(toImmutableSet()))
        .build());
  }
}
origin: prestodb/presto

@Override
public Node visitLambda(SqlBaseParser.LambdaContext context)
{
  List<LambdaArgumentDeclaration> arguments = visit(context.identifier(), Identifier.class).stream()
      .map(LambdaArgumentDeclaration::new)
      .collect(toList());
  Expression body = (Expression) visit(context.expression());
  return new LambdaExpression(getLocation(context), arguments, body);
}
origin: prestodb/presto

@Override
protected RowExpression visitLambdaExpression(LambdaExpression node, Void context)
{
  RowExpression body = process(node.getBody(), context);
  Type type = getType(node);
  List<Type> typeParameters = type.getTypeParameters();
  List<Type> argumentTypes = typeParameters.subList(0, typeParameters.size() - 1);
  List<String> argumentNames = node.getArguments().stream()
      .map(LambdaArgumentDeclaration::getName)
      .map(Identifier::getValue)
      .collect(toImmutableList());
  return new LambdaDefinitionExpression(argumentTypes, argumentNames, body);
}
origin: prestodb/presto

@Override
public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
{
  checkState(analysis.getCoercion(node) == null, "cannot coerce a lambda expression");
  ImmutableList.Builder<LambdaArgumentDeclaration> newArguments = ImmutableList.builder();
  for (LambdaArgumentDeclaration argument : node.getArguments()) {
    Symbol symbol = lambdaDeclarationToSymbolMap.get(NodeRef.of(argument));
    newArguments.add(new LambdaArgumentDeclaration(new Identifier(symbol.getName())));
  }
  Expression rewrittenBody = treeRewriter.rewrite(node.getBody(), null);
  return new LambdaExpression(newArguments.build(), rewrittenBody);
}
origin: prestodb/presto

  @Test
  public void testRewriteBasicLambda()
  {
    final Map<Symbol, Type> symbols = ImmutableMap.of(new Symbol("a"), BigintType.BIGINT);
    final SymbolAllocator allocator = new SymbolAllocator(symbols);

    assertEquals(rewrite(expression("x -> a + x"), allocator.getTypes(), allocator),
        new BindExpression(
            ImmutableList.of(expression("a")),
            new LambdaExpression(
                Stream.of("a_0", "x")
                    .map(Identifier::new)
                    .map(LambdaArgumentDeclaration::new)
                    .collect(toList()),
                expression("a_0 + x"))));
  }
}
origin: prestodb/presto

@Override
protected Object visitLambdaExpression(LambdaExpression node, Object context)
{
  if (optimize) {
    // TODO: enable optimization related to lambda expression
    // A mechanism to convert function type back into lambda expression need to exist to enable optimization
    return node;
  }
  Expression body = node.getBody();
  List<String> argumentNames = node.getArguments().stream()
      .map(LambdaArgumentDeclaration::getName)
      .map(Identifier::getValue)
      .collect(toImmutableList());
  FunctionType functionType = (FunctionType) expressionTypes.get(NodeRef.<Expression>of(node));
  checkArgument(argumentNames.size() == functionType.getArgumentTypes().size());
  return generateVarArgsToMapAdapter(
      Primitives.wrap(functionType.getReturnType().getJavaType()),
      functionType.getArgumentTypes().stream()
          .map(Type::getJavaType)
          .map(Primitives::wrap)
          .collect(toImmutableList()),
      argumentNames,
      map -> process(body, new LambdaSymbolResolver(map)));
}
origin: prestodb/presto

Expression rewrittenBody = treeRewriter.rewrite(node.getBody(), context.withReferencedSymbols(referencedSymbols));
List<Symbol> lambdaArguments = node.getArguments().stream()
    .map(LambdaArgumentDeclaration::getName)
    .map(Identifier::getValue)
  newLambdaArguments.add(new LambdaArgumentDeclaration(new Identifier(extraSymbol.getName())));
newLambdaArguments.addAll(node.getArguments());
Expression rewrittenExpression = new LambdaExpression(newLambdaArguments.build(), inlineSymbols(symbolMapping, rewrittenBody));
origin: prestodb/presto

  @Test
  public void testTryExpressionDesugaringRewriter()
  {
    // 1 + try(2)
    Expression before = new ArithmeticBinaryExpression(
        ADD,
        new DecimalLiteral("1"),
        new TryExpression(new DecimalLiteral("2")));

    // 1 + try_function(() -> 2)
    Expression after = new ArithmeticBinaryExpression(
        ADD,
        new DecimalLiteral("1"),
        new FunctionCall(
            QualifiedName.of("$internal$try"),
            ImmutableList.of(new LambdaExpression(ImmutableList.of(), new DecimalLiteral("2")))));
    assertEquals(DesugarTryExpressionRewriter.rewrite(before), after);
  }
}
origin: prestodb/presto

verify(lambdaExpression.getArguments().size() == functionType.getArgumentTypes().size());
Map<NodeRef<Expression>, Type> lambdaArgumentExpressionTypes = new HashMap<>();
Map<Symbol, Type> lambdaArgumentSymbolTypes = new HashMap<>();
for (int j = 0; j < lambdaExpression.getArguments().size(); j++) {
  LambdaArgumentDeclaration argument = lambdaExpression.getArguments().get(j);
  Type type = functionType.getArgumentTypes().get(j);
  lambdaArgumentExpressionTypes.put(NodeRef.of(argument), type);
        sqlParser,
        TypeProvider.copyOf(lambdaArgumentSymbolTypes),
        lambdaExpression.getBody(),
        emptyList(),
        NOOP))
origin: prestodb/presto

@Test
public void testLambda()
{
  assertExpression("() -> x",
      new LambdaExpression(
          ImmutableList.of(),
          new Identifier("x")));
  assertExpression("x -> sin(x)",
      new LambdaExpression(
          ImmutableList.of(new LambdaArgumentDeclaration(identifier("x"))),
          new FunctionCall(QualifiedName.of("sin"), ImmutableList.of(new Identifier("x")))));
  assertExpression("(x, y) -> mod(x, y)",
      new LambdaExpression(
          ImmutableList.of(new LambdaArgumentDeclaration(identifier("x")), new LambdaArgumentDeclaration(identifier("y"))),
          new FunctionCall(
              QualifiedName.of("mod"),
              ImmutableList.of(new Identifier("x"), new Identifier("y")))));
}
origin: prestodb/presto

@Override
protected Type visitLambdaExpression(LambdaExpression node, StackableAstVisitorContext<Context> context)
  verifyNoAggregateWindowOrGroupingFunctions(functionRegistry, node.getBody(), "Lambda expression");
  if (!context.getContext().isExpectingLambda()) {
    throw new SemanticException(STANDALONE_LAMBDA, node, "Lambda expression should always be used inside a function");
  List<LambdaArgumentDeclaration> lambdaArguments = node.getArguments();
  Type returnType = process(node.getBody(), new StackableAstVisitorContext<>(Context.inLambda(lambdaScope, fieldToLambdaArgumentDeclaration.build())));
  FunctionType functionType = new FunctionType(types, returnType);
  return setExpressionType(node, functionType);
origin: uk.co.nichesolutions.presto/presto-parser

@Override
public Node visitLambda(SqlBaseParser.LambdaContext context)
{
  List<String> arguments = context.identifier().stream()
      .map(SqlBaseParser.IdentifierContext::getText)
      .collect(toList());
  Expression body = (Expression) visit(context.expression());
  return new LambdaExpression(arguments, body);
}
origin: rakam-io/rakam

@Override
protected String visitLambdaExpression(LambdaExpression node, Void context) {
  StringBuilder builder = new StringBuilder();
  builder.append('(');
  Joiner.on(", ").appendTo(builder, node.getArguments());
  builder.append(") -> ");
  builder.append(process(node.getBody(), context));
  return builder.toString();
}
origin: com.facebook.presto/presto-parser

@Override
public Node visitLambda(SqlBaseParser.LambdaContext context)
{
  List<LambdaArgumentDeclaration> arguments = visit(context.identifier(), Identifier.class).stream()
      .map(LambdaArgumentDeclaration::new)
      .collect(toList());
  Expression body = (Expression) visit(context.expression());
  return new LambdaExpression(getLocation(context), arguments, body);
}
origin: uk.co.nichesolutions.presto/presto-parser

@Override
protected String visitLambdaExpression(LambdaExpression node, Boolean unmangleNames)
{
  StringBuilder builder = new StringBuilder();
  builder.append('(');
  Joiner.on(", ").appendTo(builder, node.getArguments());
  builder.append(") -> ");
  builder.append(process(node.getBody(), unmangleNames));
  return builder.toString();
}
com.facebook.presto.sql.treeLambdaExpression

Most used methods

  • <init>
  • getArguments
  • getBody

Popular in Java

  • Finding current android device location
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • scheduleAtFixedRate (ScheduledExecutorService)
  • setRequestProperty (URLConnection)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • JLabel (javax.swing)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now