Search in sources :

Example 1 with VerifyException

use of com.google.common.base.VerifyException in project presto by prestodb.

the class JoinFilterFunctionCompiler method generateMethodsForLambdaAndTry.

private PreGeneratedExpressions generateMethodsForLambdaAndTry(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, int leftBlocksSize, RowExpression filter) {
    Set<RowExpression> lambdaAndTryExpressions = ImmutableSet.copyOf(extractLambdaAndTryExpressions(filter));
    ImmutableMap.Builder<CallExpression, MethodDefinition> tryMethodMap = ImmutableMap.builder();
    ImmutableMap.Builder<LambdaDefinitionExpression, FieldDefinition> lambdaFieldMap = ImmutableMap.builder();
    int counter = 0;
    for (RowExpression expression : lambdaAndTryExpressions) {
        if (expression instanceof CallExpression) {
            CallExpression tryExpression = (CallExpression) expression;
            verify(!Signatures.TRY.equals(tryExpression.getSignature().getName()));
            Parameter session = arg("session", ConnectorSession.class);
            Parameter leftPosition = arg("leftPosition", int.class);
            Parameter leftBlocks = arg("leftBlocks", Block[].class);
            Parameter rightPosition = arg("rightPosition", int.class);
            Parameter rightBlocks = arg("rightBlocks", Block[].class);
            BytecodeExpressionVisitor innerExpressionVisitor = new BytecodeExpressionVisitor(callSiteBinder, cachedInstanceBinder, fieldReferenceCompiler(callSiteBinder, leftPosition, leftBlocks, rightPosition, rightBlocks, leftBlocksSize), metadata.getFunctionRegistry(), new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build()));
            List<Parameter> inputParameters = ImmutableList.<Parameter>builder().add(session).add(leftPosition).add(leftBlocks).add(rightPosition).add(rightBlocks).build();
            MethodDefinition tryMethod = defineTryMethod(innerExpressionVisitor, containerClassDefinition, "try_" + counter, inputParameters, Primitives.wrap(tryExpression.getType().getJavaType()), tryExpression, callSiteBinder);
            tryMethodMap.put(tryExpression, tryMethod);
        } else if (expression instanceof LambdaDefinitionExpression) {
            LambdaDefinitionExpression lambdaExpression = (LambdaDefinitionExpression) expression;
            PreGeneratedExpressions preGeneratedExpressions = new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build());
            FieldDefinition methodHandleField = LambdaBytecodeGenerator.preGenerateLambdaExpression(lambdaExpression, "lambda_" + counter, containerClassDefinition, preGeneratedExpressions, callSiteBinder, cachedInstanceBinder, metadata.getFunctionRegistry());
            lambdaFieldMap.put(lambdaExpression, methodHandleField);
        } else {
            throw new VerifyException(format("unexpected expression: %s", expression.toString()));
        }
        counter++;
    }
    return new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build());
}
Also used : FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) RowExpression(com.facebook.presto.sql.relational.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) VerifyException(com.google.common.base.VerifyException) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter) Block(com.facebook.presto.spi.block.Block) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) CallExpression(com.facebook.presto.sql.relational.CallExpression) LambdaDefinitionExpression(com.facebook.presto.sql.relational.LambdaDefinitionExpression)

Example 2 with VerifyException

use of com.google.common.base.VerifyException in project presto by prestodb.

the class LambdaBytecodeGenerator method generateLambda.

public static BytecodeNode generateLambda(BytecodeGeneratorContext context, List<RowExpression> captureExpressions, CompiledLambda compiledLambda, Class lambdaInterface) {
    if (!lambdaInterface.isAnnotationPresent(FunctionalInterface.class)) {
        // lambdaInterface is checked to be annotated with FunctionalInterface when generating ScalarFunctionImplementation
        throw new VerifyException("lambda should be generated as class annotated with FunctionalInterface");
    }
    BytecodeBlock block = new BytecodeBlock().setDescription("Partial apply");
    Scope scope = context.getScope();
    Variable wasNull = scope.getVariable("wasNull");
    // generate values to be captured
    ImmutableList.Builder<BytecodeExpression> captureVariableBuilder = ImmutableList.builder();
    for (RowExpression captureExpression : captureExpressions) {
        Class<?> valueType = Primitives.wrap(captureExpression.getType().getJavaType());
        Variable valueVariable = scope.createTempVariable(valueType);
        block.append(context.generate(captureExpression, Optional.empty()));
        block.append(boxPrimitiveIfNecessary(scope, valueType));
        block.putVariable(valueVariable);
        block.append(wasNull.set(constantFalse()));
        captureVariableBuilder.add(valueVariable);
    }
    List<BytecodeExpression> captureVariables = ImmutableList.<BytecodeExpression>builder().add(scope.getThis(), scope.getVariable("properties")).addAll(captureVariableBuilder.build()).build();
    Type instantiatedMethodAsmType = getMethodType(compiledLambda.getReturnType().getAsmType(), compiledLambda.getParameterTypes().stream().skip(// skip capture variables and ConnectorSession
    captureExpressions.size() + 1).map(ParameterizedType::getAsmType).collect(toImmutableList()).toArray(new Type[0]));
    block.append(invokeDynamic(LAMBDA_CAPTURE_METHOD, ImmutableList.of(getType(getSingleApplyMethod(lambdaInterface)), compiledLambda.getLambdaAsmHandle(), instantiatedMethodAsmType), "apply", type(lambdaInterface), captureVariables));
    return block;
}
Also used : Type(org.objectweb.asm.Type) Type.getType(org.objectweb.asm.Type.getType) Type.getMethodType(org.objectweb.asm.Type.getMethodType) ParameterizedType(com.facebook.presto.bytecode.ParameterizedType) Variable(com.facebook.presto.bytecode.Variable) Scope(com.facebook.presto.bytecode.Scope) VerifyException(com.google.common.base.VerifyException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) RowExpression(com.facebook.presto.spi.relation.RowExpression) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Example 3 with VerifyException

use of com.google.common.base.VerifyException in project presto by prestodb.

the class LdapAuthenticator method checkForGroupMembership.

private void checkForGroupMembership(String user, DirContext context) {
    if (!groupAuthorizationSearchPattern.isPresent()) {
        return;
    }
    String userBase = userBaseDistinguishedName.orElseThrow(VerifyException::new);
    String searchFilter = replaceUser(groupAuthorizationSearchPattern.get(), user);
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    boolean authorized;
    try {
        NamingEnumeration<SearchResult> search = context.search(userBase, searchFilter, searchControls);
        authorized = search.hasMoreElements();
        search.close();
    } catch (NamingException e) {
        log.debug("Authentication error for user [%s]: %s", user, e.getMessage());
        throw new RuntimeException("Authentication error");
    }
    if (!authorized) {
        String message = format("User [%s] not a member of the authorized group", user);
        log.debug(message);
        throw new AccessDeniedException(message);
    }
}
Also used : AccessDeniedException(com.facebook.presto.spi.security.AccessDeniedException) VerifyException(com.google.common.base.VerifyException) SearchControls(javax.naming.directory.SearchControls) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException)

Example 4 with VerifyException

use of com.google.common.base.VerifyException in project presto by prestodb.

the class SqlQueryScheduler method addStateChangeListeners.

private void addStateChangeListeners(SectionExecution sectionExecution) {
    for (StageExecutionAndScheduler stageExecutionAndScheduler : sectionExecution.getSectionStages()) {
        SqlStageExecution stageExecution = stageExecutionAndScheduler.getStageExecution();
        if (isRootFragment(stageExecution.getFragment())) {
            stageExecution.addStateChangeListener(state -> {
                if (state == FINISHED) {
                    queryStateMachine.transitionToFinishing();
                } else if (state == CANCELED) {
                    // output stage was canceled
                    queryStateMachine.transitionToCanceled();
                }
            });
        }
        stageExecution.addStateChangeListener(state -> {
            if (queryStateMachine.isDone()) {
                return;
            }
            if (state == FAILED) {
                ExecutionFailureInfo failureInfo = stageExecution.getStageExecutionInfo().getFailureCause().orElseThrow(() -> new VerifyException(format("stage execution failed, but the failure info is missing: %s", stageExecution.getStageExecutionId())));
                Exception failureException = failureInfo.toException();
                boolean isRootSection = isRootFragment(sectionExecution.getRootStage().getStageExecution().getFragment());
                // root section directly streams the results to the user, cannot be retried
                if (isRootSection) {
                    queryStateMachine.transitionToFailed(failureException);
                    return;
                }
                if (retriedSections.get() >= maxStageRetries) {
                    queryStateMachine.transitionToFailed(failureException);
                    return;
                }
                if (!RECOVERABLE_ERROR_CODES.contains(failureInfo.getErrorCode())) {
                    queryStateMachine.transitionToFailed(failureException);
                    return;
                }
                try {
                    if (sectionExecution.abort()) {
                        retriedSections.incrementAndGet();
                        nodeManager.refreshNodes();
                        startScheduling();
                    }
                } catch (Throwable t) {
                    if (failureException != t) {
                        failureException.addSuppressed(t);
                    }
                    queryStateMachine.transitionToFailed(failureException);
                }
            } else if (state == FINISHED) {
                // checks if there's any new sections available for execution and starts the scheduling if any
                startScheduling();
            } else if (queryStateMachine.getQueryState() == QueryState.STARTING) {
                // if the stage has at least one task, we are running
                if (stageExecution.hasTasks()) {
                    queryStateMachine.transitionToRunning();
                }
            }
        });
        stageExecution.addFinalStageInfoListener(status -> queryStateMachine.updateQueryInfo(Optional.of(getStageInfo())));
    }
}
Also used : VerifyException(com.google.common.base.VerifyException) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) PrestoException(com.facebook.presto.spi.PrestoException) VerifyException(com.google.common.base.VerifyException) ExecutionFailureInfo(com.facebook.presto.execution.ExecutionFailureInfo)

Example 5 with VerifyException

use of com.google.common.base.VerifyException in project presto by prestodb.

the class HiveMetadata method createPartitionStatistics.

private PartitionStatistics createPartitionStatistics(ConnectorSession session, Map<String, Type> columnTypes, ComputedStatistics computedStatistics) {
    Map<ColumnStatisticMetadata, Block> computedColumnStatistics = computedStatistics.getColumnStatistics();
    Block rowCountBlock = Optional.ofNullable(computedStatistics.getTableStatistics().get(ROW_COUNT)).orElseThrow(() -> new VerifyException("rowCount not present"));
    verify(!rowCountBlock.isNull(0), "rowCount must never be null");
    long rowCount = BIGINT.getLong(rowCountBlock, 0);
    HiveBasicStatistics rowCountOnlyBasicStatistics = new HiveBasicStatistics(OptionalLong.empty(), OptionalLong.of(rowCount), OptionalLong.empty(), OptionalLong.empty());
    return createPartitionStatistics(session, rowCountOnlyBasicStatistics, columnTypes, computedColumnStatistics);
}
Also used : ColumnStatisticMetadata(com.facebook.presto.spi.statistics.ColumnStatisticMetadata) VerifyException(com.google.common.base.VerifyException) Block(com.facebook.presto.common.block.Block)

Aggregations

VerifyException (com.google.common.base.VerifyException)25 ImmutableMap (com.google.common.collect.ImmutableMap)8 PrestoException (com.facebook.presto.spi.PrestoException)6 List (java.util.List)6 Map (java.util.Map)6 Objects.requireNonNull (java.util.Objects.requireNonNull)6 Logger (com.facebook.airlift.log.Logger)5 Type (com.facebook.presto.common.type.Type)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Slice (io.airlift.slice.Slice)5 ArrayList (java.util.ArrayList)5 Optional (java.util.Optional)5 Set (java.util.Set)5 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 String.format (java.lang.String.format)4 Collection (java.util.Collection)4 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)3