List of usage examples for com.google.common.base VerifyException VerifyException
public VerifyException(@Nullable Throwable cause)
From source file:com.facebook.presto.sql.gen.PageFunctionCompiler.java
private PreGeneratedExpressions generateMethodsForLambdaAndTry(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, RowExpression expression) { Set<RowExpression> lambdaAndTryExpressions = ImmutableSet .copyOf(extractLambdaAndTryExpressions(expression)); ImmutableMap.Builder<CallExpression, MethodDefinition> tryMethodMap = ImmutableMap.builder(); ImmutableMap.Builder<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = ImmutableMap.builder(); int counter = 0; for (RowExpression lambdaOrTryExpression : lambdaAndTryExpressions) { if (lambdaOrTryExpression instanceof CallExpression) { CallExpression tryExpression = (CallExpression) lambdaOrTryExpression; verify(!Signatures.TRY.equals(tryExpression.getSignature().getName())); Parameter session = arg("session", ConnectorSession.class); List<Parameter> blocks = toBlockParameters(getInputChannels(tryExpression.getArguments())); Parameter position = arg("position", int.class); RowExpressionCompiler innerExpressionCompiler = new RowExpressionCompiler(callSiteBinder, cachedInstanceBinder, fieldReferenceCompiler(callSiteBinder), metadata.getFunctionRegistry(), new PreGeneratedExpressions(tryMethodMap.build(), compiledLambdaMap.build())); List<Parameter> inputParameters = ImmutableList.<Parameter>builder().add(session).addAll(blocks) .add(position).build(); MethodDefinition tryMethod = defineTryMethod(innerExpressionCompiler, containerClassDefinition, "try_" + counter, inputParameters, Primitives.wrap(tryExpression.getType().getJavaType()), tryExpression, callSiteBinder); tryMethodMap.put(tryExpression, tryMethod); } else if (lambdaOrTryExpression instanceof LambdaDefinitionExpression) { LambdaDefinitionExpression lambdaExpression = (LambdaDefinitionExpression) lambdaOrTryExpression; 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 {//from www . ja v a 2s . c om throw new VerifyException(format("unexpected expression: %s", lambdaOrTryExpression.toString())); } counter++; } return new PreGeneratedExpressions(tryMethodMap.build(), compiledLambdaMap.build()); }
From source file:io.prestosql.plugin.hive.HiveUtil.java
public static NullableValue parsePartitionValue(String partitionName, String value, Type type, DateTimeZone timeZone) {// ww w.j a va 2s .co m verifyPartitionTypeSupported(partitionName, type); boolean isNull = HIVE_DEFAULT_DYNAMIC_PARTITION.equals(value); if (type instanceof DecimalType) { DecimalType decimalType = (DecimalType) type; if (isNull) { return NullableValue.asNull(decimalType); } if (decimalType.isShort()) { if (value.isEmpty()) { return NullableValue.of(decimalType, 0L); } return NullableValue.of(decimalType, shortDecimalPartitionKey(value, decimalType, partitionName)); } else { if (value.isEmpty()) { return NullableValue.of(decimalType, Decimals.encodeUnscaledValue(BigInteger.ZERO)); } return NullableValue.of(decimalType, longDecimalPartitionKey(value, decimalType, partitionName)); } } if (BOOLEAN.equals(type)) { if (isNull) { return NullableValue.asNull(BOOLEAN); } if (value.isEmpty()) { return NullableValue.of(BOOLEAN, false); } return NullableValue.of(BOOLEAN, booleanPartitionKey(value, partitionName)); } if (TINYINT.equals(type)) { if (isNull) { return NullableValue.asNull(TINYINT); } if (value.isEmpty()) { return NullableValue.of(TINYINT, 0L); } return NullableValue.of(TINYINT, tinyintPartitionKey(value, partitionName)); } if (SMALLINT.equals(type)) { if (isNull) { return NullableValue.asNull(SMALLINT); } if (value.isEmpty()) { return NullableValue.of(SMALLINT, 0L); } return NullableValue.of(SMALLINT, smallintPartitionKey(value, partitionName)); } if (INTEGER.equals(type)) { if (isNull) { return NullableValue.asNull(INTEGER); } if (value.isEmpty()) { return NullableValue.of(INTEGER, 0L); } return NullableValue.of(INTEGER, integerPartitionKey(value, partitionName)); } if (BIGINT.equals(type)) { if (isNull) { return NullableValue.asNull(BIGINT); } if (value.isEmpty()) { return NullableValue.of(BIGINT, 0L); } return NullableValue.of(BIGINT, bigintPartitionKey(value, partitionName)); } if (DATE.equals(type)) { if (isNull) { return NullableValue.asNull(DATE); } return NullableValue.of(DATE, datePartitionKey(value, partitionName)); } if (TIMESTAMP.equals(type)) { if (isNull) { return NullableValue.asNull(TIMESTAMP); } return NullableValue.of(TIMESTAMP, timestampPartitionKey(value, timeZone, partitionName)); } if (REAL.equals(type)) { if (isNull) { return NullableValue.asNull(REAL); } if (value.isEmpty()) { return NullableValue.of(REAL, (long) floatToRawIntBits(0.0f)); } return NullableValue.of(REAL, floatPartitionKey(value, partitionName)); } if (DOUBLE.equals(type)) { if (isNull) { return NullableValue.asNull(DOUBLE); } if (value.isEmpty()) { return NullableValue.of(DOUBLE, 0.0); } return NullableValue.of(DOUBLE, doublePartitionKey(value, partitionName)); } if (isVarcharType(type)) { if (isNull) { return NullableValue.asNull(type); } return NullableValue.of(type, varcharPartitionKey(value, partitionName, type)); } if (isCharType(type)) { if (isNull) { return NullableValue.asNull(type); } return NullableValue.of(type, charPartitionKey(value, partitionName, type)); } throw new VerifyException(format("Unhandled type [%s] for partition: %s", type, partitionName)); }
From source file:io.prestosql.plugin.hive.statistics.MetastoreHiveStatisticsProvider.java
@VisibleForTesting static Estimate calculateNullsFraction(String column, Collection<PartitionStatistics> partitionStatistics) { List<PartitionStatistics> statisticsWithKnownRowCountAndNullsCount = partitionStatistics.stream() .filter(statistics -> {//from w w w .ja v a2 s. c om if (!statistics.getBasicStatistics().getRowCount().isPresent()) { return false; } HiveColumnStatistics columnStatistics = statistics.getColumnStatistics().get(column); if (columnStatistics == null) { return false; } return columnStatistics.getNullsCount().isPresent(); }).collect(toImmutableList()); if (statisticsWithKnownRowCountAndNullsCount.isEmpty()) { return Estimate.unknown(); } long totalNullsCount = 0; long totalRowCount = 0; for (PartitionStatistics statistics : statisticsWithKnownRowCountAndNullsCount) { long rowCount = statistics.getBasicStatistics().getRowCount() .orElseThrow(() -> new VerifyException("rowCount is not present")); verify(rowCount >= 0, "rowCount must be greater than or equal to zero"); HiveColumnStatistics columnStatistics = statistics.getColumnStatistics().get(column); verify(columnStatistics != null, "columnStatistics is null"); long nullsCount = columnStatistics.getNullsCount() .orElseThrow(() -> new VerifyException("nullsCount is not present")); verify(nullsCount >= 0, "nullsCount must be greater than or equal to zero"); verify(nullsCount <= rowCount, "nullsCount must be less than or equal to rowCount. nullsCount: %s. rowCount: %s.", nullsCount, rowCount); totalNullsCount += nullsCount; totalRowCount += rowCount; } if (totalRowCount == 0) { return Estimate.zero(); } verify(totalNullsCount <= totalRowCount, "totalNullsCount must be less than or equal to totalRowCount. totalNullsCount: %s. totalRowCount: %s.", totalNullsCount, totalRowCount); return Estimate.of(((double) totalNullsCount) / totalRowCount); }
From source file:io.prestosql.plugin.hive.statistics.MetastoreHiveStatisticsProvider.java
@VisibleForTesting static Estimate calculateDataSize(String column, Collection<PartitionStatistics> partitionStatistics, double totalRowCount) { List<PartitionStatistics> statisticsWithKnownRowCountAndDataSize = partitionStatistics.stream() .filter(statistics -> {/* w ww. j a v a2 s . c o m*/ if (!statistics.getBasicStatistics().getRowCount().isPresent()) { return false; } HiveColumnStatistics columnStatistics = statistics.getColumnStatistics().get(column); if (columnStatistics == null) { return false; } return columnStatistics.getTotalSizeInBytes().isPresent(); }).collect(toImmutableList()); if (statisticsWithKnownRowCountAndDataSize.isEmpty()) { return Estimate.unknown(); } long knownRowCount = 0; long knownDataSize = 0; for (PartitionStatistics statistics : statisticsWithKnownRowCountAndDataSize) { long rowCount = statistics.getBasicStatistics().getRowCount() .orElseThrow(() -> new VerifyException("rowCount is not present")); verify(rowCount >= 0, "rowCount must be greater than or equal to zero"); HiveColumnStatistics columnStatistics = statistics.getColumnStatistics().get(column); verify(columnStatistics != null, "columnStatistics is null"); long dataSize = columnStatistics.getTotalSizeInBytes() .orElseThrow(() -> new VerifyException("totalSizeInBytes is not present")); verify(dataSize >= 0, "dataSize must be greater than or equal to zero"); knownRowCount += rowCount; knownDataSize += dataSize; } if (totalRowCount == 0) { return Estimate.zero(); } if (knownRowCount == 0) { return Estimate.unknown(); } double averageValueDataSizeInBytes = ((double) knownDataSize) / knownRowCount; return Estimate.of(averageValueDataSizeInBytes * totalRowCount); }
From source file:com.facebook.presto.plugin.geospatial.GeoFunctions.java
private static Block spatialPartitions(KdbTree kdbTree, Rectangle envelope) { Map<Integer, Rectangle> partitions = kdbTree.findIntersectingLeaves(envelope); if (partitions.isEmpty()) { return EMPTY_ARRAY_OF_INTS; }//from w w w .j a va 2 s . com // For input rectangles that represent a single point, return at most one partition // by excluding right and upper sides of partition rectangles. The logic that builds // KDB tree needs to make sure to add some padding to the right and upper sides of the // overall extent of the tree to avoid missing right-most and top-most points. boolean point = (envelope.getWidth() == 0 && envelope.getHeight() == 0); if (point) { for (Map.Entry<Integer, Rectangle> partition : partitions.entrySet()) { if (envelope.getXMin() < partition.getValue().getXMax() && envelope.getYMin() < partition.getValue().getYMax()) { BlockBuilder blockBuilder = IntegerType.INTEGER.createFixedSizeBlockBuilder(1); blockBuilder.writeInt(partition.getKey()); return blockBuilder.build(); } } throw new VerifyException(format("Cannot find half-open partition extent for a point: (%s, %s)", envelope.getXMin(), envelope.getYMin())); } BlockBuilder blockBuilder = IntegerType.INTEGER.createFixedSizeBlockBuilder(partitions.size()); for (int id : partitions.keySet()) { blockBuilder.writeInt(id); } return blockBuilder.build(); }
From source file:io.prestosql.plugin.hive.HiveMetadata.java
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);/*from ww w .ja v a2s.c o m*/ }