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());
}
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;
}
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);
}
}
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())));
}
}
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);
}
Aggregations