Search in sources :

Example 16 with SqlFunctionId

use of com.facebook.presto.spi.function.SqlFunctionId in project presto by prestodb.

the class LambdaBytecodeGenerator method generateMethodsForLambda.

private static Map<LambdaDefinitionExpression, CompiledLambda> generateMethodsForLambda(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, List<RowExpression> expressions, Metadata metadata, SqlFunctionProperties sqlFunctionProperties, Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions, String methodNamePrefix, Set<LambdaDefinitionExpression> existingCompiledLambdas) {
    Set<LambdaDefinitionExpression> lambdaExpressions = expressions.stream().map(LambdaExpressionExtractor::extractLambdaExpressions).flatMap(List::stream).filter(lambda -> !existingCompiledLambdas.contains(lambda)).collect(toImmutableSet());
    ImmutableMap.Builder<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = ImmutableMap.builder();
    int counter = existingCompiledLambdas.size();
    for (LambdaDefinitionExpression lambdaExpression : lambdaExpressions) {
        CompiledLambda compiledLambda = LambdaBytecodeGenerator.preGenerateLambdaExpression(lambdaExpression, methodNamePrefix + "lambda_" + counter, containerClassDefinition, compiledLambdaMap.build(), callSiteBinder, cachedInstanceBinder, metadata, sqlFunctionProperties, sessionFunctions);
        compiledLambdaMap.put(lambdaExpression, compiledLambda);
        counter++;
    }
    return compiledLambdaMap.build();
}
Also used : BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression) Arrays(java.util.Arrays) LambdaProvider(com.facebook.presto.operator.aggregation.LambdaProvider) RowExpressionVisitor(com.facebook.presto.spi.relation.RowExpressionVisitor) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) BytecodeExpressions.invokeDynamic(com.facebook.presto.bytecode.expression.BytecodeExpressions.invokeDynamic) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Type(org.objectweb.asm.Type) Access.a(com.facebook.presto.bytecode.Access.a) CallSiteBinder(com.facebook.presto.bytecode.CallSiteBinder) ParameterizedType.type(com.facebook.presto.bytecode.ParameterizedType.type) BytecodeUtils.boxPrimitiveIfNecessary(com.facebook.presto.sql.gen.BytecodeUtils.boxPrimitiveIfNecessary) Map(java.util.Map) CompilerUtils.makeClassName(com.facebook.presto.util.CompilerUtils.makeClassName) CallExpression(com.facebook.presto.spi.relation.CallExpression) Method(java.lang.reflect.Method) SpecialFormExpression(com.facebook.presto.spi.relation.SpecialFormExpression) Variable(com.facebook.presto.bytecode.Variable) ImmutableSet(com.google.common.collect.ImmutableSet) Parameter(com.facebook.presto.bytecode.Parameter) ImmutableMap(com.google.common.collect.ImmutableMap) Type.getType(org.objectweb.asm.Type.getType) SqlFunctionProperties(com.facebook.presto.common.function.SqlFunctionProperties) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) LambdaDefinitionExpression(com.facebook.presto.spi.relation.LambdaDefinitionExpression) ClassDefinition(com.facebook.presto.bytecode.ClassDefinition) List(java.util.List) Scope(com.facebook.presto.bytecode.Scope) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) Type.getMethodType(org.objectweb.asm.Type.getMethodType) Optional(java.util.Optional) AccumulatorCompiler(com.facebook.presto.operator.aggregation.AccumulatorCompiler) InputReferenceExpression(com.facebook.presto.spi.relation.InputReferenceExpression) Parameter.arg(com.facebook.presto.bytecode.Parameter.arg) PRIVATE(com.facebook.presto.bytecode.Access.PRIVATE) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) BytecodeExpressions.constantFalse(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantFalse) LAMBDA_CAPTURE_METHOD(com.facebook.presto.sql.gen.LambdaCapture.LAMBDA_CAPTURE_METHOD) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) Failures.checkCondition(com.facebook.presto.util.Failures.checkCondition) RowExpression(com.facebook.presto.spi.relation.RowExpression) VerifyException(com.google.common.base.VerifyException) PUBLIC(com.facebook.presto.bytecode.Access.PUBLIC) Opcodes(org.objectweb.asm.Opcodes) Access(com.facebook.presto.bytecode.Access) CompilerUtils.defineClass(com.facebook.presto.util.CompilerUtils.defineClass) Primitives(com.google.common.primitives.Primitives) Handle(org.objectweb.asm.Handle) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) BytecodeUtils.unboxPrimitiveIfNecessary(com.facebook.presto.sql.gen.BytecodeUtils.unboxPrimitiveIfNecessary) COMPILER_ERROR(com.facebook.presto.spi.StandardErrorCode.COMPILER_ERROR) ParameterizedType(com.facebook.presto.bytecode.ParameterizedType) Metadata(com.facebook.presto.metadata.Metadata) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) LambdaDefinitionExpression(com.facebook.presto.spi.relation.LambdaDefinitionExpression)

Example 17 with SqlFunctionId

use of com.facebook.presto.spi.function.SqlFunctionId in project presto by prestodb.

the class QueryResourceUtil method toResponse.

public static Response toResponse(Query query, QueryResults queryResults, boolean compressionEnabled) {
    Response.ResponseBuilder response = Response.ok(queryResults);
    // add set catalog and schema
    query.getSetCatalog().ifPresent(catalog -> response.header(PRESTO_SET_CATALOG, catalog));
    query.getSetSchema().ifPresent(schema -> response.header(PRESTO_SET_SCHEMA, schema));
    // add set session properties
    query.getSetSessionProperties().forEach((key, value) -> response.header(PRESTO_SET_SESSION, key + '=' + urlEncode(value)));
    // add clear session properties
    query.getResetSessionProperties().forEach(name -> response.header(PRESTO_CLEAR_SESSION, name));
    // add set roles
    query.getSetRoles().forEach((key, value) -> response.header(PRESTO_SET_ROLE, key + '=' + urlEncode(value.toString())));
    // add added prepare statements
    for (Map.Entry<String, String> entry : query.getAddedPreparedStatements().entrySet()) {
        String encodedKey = urlEncode(entry.getKey());
        String encodedValue = urlEncode(entry.getValue());
        response.header(PRESTO_ADDED_PREPARE, encodedKey + '=' + encodedValue);
    }
    // add deallocated prepare statements
    for (String name : query.getDeallocatedPreparedStatements()) {
        response.header(PRESTO_DEALLOCATED_PREPARE, urlEncode(name));
    }
    // add new transaction ID
    query.getStartedTransactionId().ifPresent(transactionId -> response.header(PRESTO_STARTED_TRANSACTION_ID, transactionId));
    // add clear transaction ID directive
    if (query.isClearTransactionId()) {
        response.header(PRESTO_CLEAR_TRANSACTION_ID, true);
    }
    if (!compressionEnabled) {
        response.encoding("identity");
    }
    // add added session functions
    for (Map.Entry<SqlFunctionId, SqlInvokedFunction> entry : query.getAddedSessionFunctions().entrySet()) {
        response.header(PRESTO_ADDED_SESSION_FUNCTION, format("%s=%s", urlEncode(SQL_FUNCTION_ID_JSON_CODEC.toJson(entry.getKey())), urlEncode(SQL_INVOKED_FUNCTION_JSON_CODEC.toJson(entry.getValue()))));
    }
    // add removed session functions
    for (SqlFunctionId signature : query.getRemovedSessionFunctions()) {
        response.header(PRESTO_REMOVED_SESSION_FUNCTION, urlEncode(SQL_FUNCTION_ID_JSON_CODEC.toJson(signature)));
    }
    return response.build();
}
Also used : Response(javax.ws.rs.core.Response) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) Map(java.util.Map)

Aggregations

SqlFunctionId (com.facebook.presto.spi.function.SqlFunctionId)17 SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)11 Map (java.util.Map)7 PrestoException (com.facebook.presto.spi.PrestoException)6 List (java.util.List)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 PRIVATE (com.facebook.presto.bytecode.Access.PRIVATE)4 PUBLIC (com.facebook.presto.bytecode.Access.PUBLIC)4 Access.a (com.facebook.presto.bytecode.Access.a)4 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)4 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)4 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)4 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)4 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)4 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)4 Parameter (com.facebook.presto.bytecode.Parameter)4 Parameter.arg (com.facebook.presto.bytecode.Parameter.arg)4 ParameterizedType (com.facebook.presto.bytecode.ParameterizedType)4