List of usage examples for com.google.common.base VerifyException VerifyException
public VerifyException(@Nullable Throwable cause)
From source file:com.facebook.presto.sql.gen.LambdaBytecodeGenerator.java
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"); }/*from w w w. j a v a2 s . c o m*/ 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)); 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("session")).addAll(captureVariableBuilder.build()).build(); Type instantiatedMethodAsmType = getMethodType(compiledLambda.getReturnType().getAsmType(), compiledLambda.getParameterTypes().stream().skip(captureExpressions.size() + 1) // skip capture variables and ConnectorSession .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; }
From source file:io.airlift.drift.idl.generator.ThriftIdlGenerator.java
private boolean verifyTypes() { SuccessAndResult<ThriftType> output = topologicalSort(thriftTypes, type -> { ThriftProtocolType proto = type.getProtocolType(); if (proto == ThriftProtocolType.ENUM || proto == ThriftProtocolType.STRUCT) { return verifyStruct(type, true); }/*from w ww .j a va 2s . co m*/ throw new VerifyException("Top-level non-enum and non-struct?"); }); if (output.isSuccess()) { thriftTypes = output.getResult(); return true; } for (ThriftType type : output.getResult()) { // we know it's gonna fail, we just want the precise error message verifyStruct(type, false); } return false; }
From source file:com.shieldsbetter.sbomg.Cli.java
private static ProjectDescriptor findProjectDescriptor(File start) throws OperationException { ProjectDescriptor result;//from www .ja v a2s.c om boolean isFile; try { isFile = start.isFile(); } catch (SecurityException se) { throw new OperationException( "Reached non-readable directory " + start.getPath() + " without finding sbomg.yaml file."); } if (isFile) { result = findProjectDescriptorInParent(start); } else { FileFilter ff = (File file) -> file.getName().equals("sbomg.yaml"); File[] files = start.listFiles(ff); switch (files.length) { case 0: { result = findProjectDescriptorInParent(start); break; } case 1: { result = parseProjectDescriptor(files[0]); break; } default: { throw new VerifyException("More than one file with the same name?"); } } } return result; }
From source file:org.sosy_lab.java_smt.solvers.z3.Z3Model.java
private void checkReturnValue(long value, long funcDecl) { if (value == 0) { throw new VerifyException("Z3 unexpectedly claims that the value of " + Native.funcDeclToString(z3context, funcDecl) + " does not matter in model."); }//from w w w . java 2 s.c o m }
From source file:com.facebook.presto.raptor.storage.BucketBalancer.java
private static Multimap<String, BucketAssignment> computeAssignmentChanges(ClusterState clusterState) { Multimap<String, BucketAssignment> sourceToAllocationChanges = HashMultimap.create(); Map<String, Long> allocationBytes = new HashMap<>(clusterState.getAssignedBytes()); Set<String> activeNodes = clusterState.getActiveNodes(); for (Distribution distribution : clusterState.getDistributionAssignments().keySet()) { // number of buckets in this distribution assigned to a node Multiset<String> allocationCounts = HashMultiset.create(); Collection<BucketAssignment> distributionAssignments = clusterState.getDistributionAssignments() .get(distribution);/*www .j av a2s .c om*/ distributionAssignments.stream().map(BucketAssignment::getNodeIdentifier) .forEach(allocationCounts::add); int currentMin = allocationBytes.keySet().stream().mapToInt(allocationCounts::count).min().getAsInt(); int currentMax = allocationBytes.keySet().stream().mapToInt(allocationCounts::count).max().getAsInt(); int numBuckets = distributionAssignments.size(); int targetMin = (int) Math.floor((numBuckets * 1.0) / clusterState.getActiveNodes().size()); int targetMax = (int) Math.ceil((numBuckets * 1.0) / clusterState.getActiveNodes().size()); log.info("Distribution %s: Current bucket skew: min %s, max %s. Target bucket skew: min %s, max %s", distribution.getId(), currentMin, currentMax, targetMin, targetMax); for (String source : ImmutableSet.copyOf(allocationCounts)) { List<BucketAssignment> existingAssignments = distributionAssignments.stream() .filter(assignment -> assignment.getNodeIdentifier().equals(source)).collect(toList()); for (BucketAssignment existingAssignment : existingAssignments) { if (activeNodes.contains(source) && allocationCounts.count(source) <= targetMin) { break; } // identify nodes with bucket counts lower than the computed target, and greedily select from this set based on projected disk utilization. // greediness means that this may produce decidedly non-optimal results if one looks at the global distribution of buckets->nodes. // also, this assumes that nodes in a cluster have identical storage capacity String target = activeNodes.stream() .filter(candidate -> !candidate.equals(source) && allocationCounts.count(candidate) < targetMax) .sorted(comparingInt(allocationCounts::count)) .min(Comparator.comparingDouble(allocationBytes::get)) .orElseThrow(() -> new VerifyException("unable to find target for rebalancing")); long bucketSize = clusterState.getDistributionBucketSize().get(distribution); // only move bucket if it reduces imbalance if (activeNodes.contains(source) && (allocationCounts.count(source) == targetMax && allocationCounts.count(target) == targetMin)) { break; } allocationCounts.remove(source); allocationCounts.add(target); allocationBytes.compute(source, (k, v) -> v - bucketSize); allocationBytes.compute(target, (k, v) -> v + bucketSize); sourceToAllocationChanges.put(existingAssignment.getNodeIdentifier(), new BucketAssignment( existingAssignment.getDistributionId(), existingAssignment.getBucketNumber(), target)); } } } return sourceToAllocationChanges; }
From source file:io.prestosql.plugin.hive.HivePartitionManager.java
public HivePartitionResult getPartitions(SemiTransactionalHiveMetastore metastore, ConnectorTableHandle tableHandle, List<List<String>> partitionValuesList) { HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle; SchemaTableName tableName = hiveTableHandle.getSchemaTableName(); Table table = getTable(metastore, tableName); List<HiveColumnHandle> partitionColumns = getPartitionKeyColumnHandles(table); List<Type> partitionColumnTypes = partitionColumns.stream() .map(column -> typeManager.getType(column.getTypeSignature())).collect(toImmutableList()); List<HivePartition> partitionList = partitionValuesList.stream() .map(partitionValues -> makePartName(table.getPartitionColumns(), partitionValues)) .map(partitionName -> parseValuesAndFilterPartition(tableName, partitionName, partitionColumns, partitionColumnTypes, alwaysTrue())) .map(partition -> partition.orElseThrow(() -> new VerifyException("partition must exist"))) .collect(toImmutableList()); return new HivePartitionResult(partitionColumns, partitionList, all(), all(), none(), getHiveBucketHandle(table), Optional.empty()); }
From source file:com.facebook.presto.sql.gen.JoinFilterFunctionCompiler.java
private PreGeneratedExpressions generateMethodsForLambdaAndTry(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, int leftBlocksSize, RowExpression filter) {//w w w.ja va 2 s. c o m Set<RowExpression> lambdaAndTryExpressions = ImmutableSet.copyOf(extractLambdaAndTryExpressions(filter)); ImmutableMap.Builder<CallExpression, MethodDefinition> tryMethodMap = ImmutableMap.builder(); ImmutableMap.Builder<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = 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); RowExpressionCompiler innerExpressionCompiler = new RowExpressionCompiler(callSiteBinder, cachedInstanceBinder, fieldReferenceCompiler(callSiteBinder, leftPosition, leftBlocks, rightPosition, rightBlocks, leftBlocksSize), metadata.getFunctionRegistry(), new PreGeneratedExpressions(tryMethodMap.build(), compiledLambdaMap.build())); List<Parameter> inputParameters = ImmutableList.<Parameter>builder().add(session).add(leftPosition) .add(leftBlocks).add(rightPosition).add(rightBlocks).build(); MethodDefinition tryMethod = defineTryMethod(innerExpressionCompiler, 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(), compiledLambdaMap.build()); CompiledLambda compiledLambda = LambdaBytecodeGenerator.preGenerateLambdaExpression( lambdaExpression, "lambda_" + counter, containerClassDefinition, preGeneratedExpressions, callSiteBinder, cachedInstanceBinder, metadata.getFunctionRegistry()); compiledLambdaMap.put(lambdaExpression, compiledLambda); } else { throw new VerifyException(format("unexpected expression: %s", expression.toString())); } counter++; } return new PreGeneratedExpressions(tryMethodMap.build(), compiledLambdaMap.build()); }
From source file:com.facebook.presto.metadata.SignatureBinder.java
private Optional<BoundVariables> iterativeSolve(List<TypeConstraintSolver> constraints) { BoundVariables.Builder boundVariablesBuilder = BoundVariables.builder(); for (int i = 0; true; i++) { if (i == SOLVE_ITERATION_LIMIT) { throw new VerifyException( format("SignatureBinder.iterativeSolve does not converge after %d iterations.", SOLVE_ITERATION_LIMIT)); }/*w ww . ja v a 2 s. co m*/ SolverReturnStatusMerger statusMerger = new SolverReturnStatusMerger(); for (TypeConstraintSolver constraint : constraints) { statusMerger.add(constraint.update(boundVariablesBuilder)); if (statusMerger.getCurrent() == SolverReturnStatus.UNSOLVABLE) { return Optional.empty(); } } switch (statusMerger.getCurrent()) { case UNCHANGED_SATISFIED: break; case UNCHANGED_NOT_SATISFIED: return Optional.empty(); case CHANGED: continue; case UNSOLVABLE: throw new VerifyException(); default: throw new UnsupportedOperationException("unknown status"); } break; } calculateVariableValuesForLongConstraints(boundVariablesBuilder); BoundVariables boundVariables = boundVariablesBuilder.build(); if (!allTypeVariablesBound(boundVariables)) { return Optional.empty(); } return Optional.of(boundVariables); }
From source file:com.google.devtools.build.lib.analysis.config.ConfigurationResolver.java
/** * Variation of {@link Multimap#put} that triggers an exception if a value already exists. *///from w w w . j a va 2s . c o m @VisibleForTesting public static <K, V> void putOnlyEntry(Multimap<K, V> map, K key, V value) { // Performance note: while "Verify.verify(!map.containsKey(key, value), String.format(...)))" // is simpler code, profiling shows a substantial performance penalty to that approach // (~10% extra analysis phase time on a simple cc_binary). Most of that is from the cost of // evaluating value.toString() on every call. This approach essentially eliminates the overhead. if (map.containsKey(key)) { throw new VerifyException( String.format("couldn't insert %s: map already has key %s", value.toString(), key.toString())); } map.put(key, value); }
From source file:com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.java
/** * Variation of {@link Multimap#put} that triggers an exception if a value already exists. *//* www .j a v a 2 s. c o m*/ @VisibleForTesting static <K, V> void putOnlyEntry(Multimap<K, V> map, K key, V value) { // Performance note: while "Verify.verify(!map.containsKey(key, value), String.format(...)))" // is simpler code, profiling shows a substantial performance penalty to that approach // (~10% extra analysis phase time on a simple cc_binary). Most of that is from the cost of // evaluating value.toString() on every call. This approach essentially eliminates the overhead. if (map.containsKey(key)) { throw new VerifyException( String.format("couldn't insert %s: map already has key %s", value.toString(), key.toString())); } map.put(key, value); }