private TopKSelector(Comparator<? super T> comparator, int k) { this.comparator = checkNotNull(comparator, "comparator"); this.k = k; checkArgument(k >= 0, "k must be nonnegative, was %s", k); this.buffer = (T[]) new Object[k * 2]; this.bufferSize = 0; this.threshold = null; }
public GroupedExecutionProperties(boolean currentNodeCapable, boolean subTreeUseful, List<PlanNodeId> capableTableScanNodes) { this.currentNodeCapable = currentNodeCapable; this.subTreeUseful = subTreeUseful; this.capableTableScanNodes = ImmutableList.copyOf(requireNonNull(capableTableScanNodes, "capableTableScanNodes is null")); // Verify that `subTreeUseful` implies `currentNodeCapable` checkArgument(!subTreeUseful || currentNodeCapable); checkArgument(currentNodeCapable == !capableTableScanNodes.isEmpty()); }
public ClientResourceEstimate(String resourceEstimate) { List<String> nameValue = NAME_VALUE_SPLITTER.splitToList(resourceEstimate); checkArgument(nameValue.size() == 2, "Resource estimate: %s", resourceEstimate); this.resource = nameValue.get(0); this.estimate = nameValue.get(1); checkArgument(!resource.isEmpty(), "Resource name is empty"); checkArgument(!estimate.isEmpty(), "Resource estimate is empty"); checkArgument(PRINTABLE_ASCII.matchesAllOf(resource), "Resource contains spaces or is not US_ASCII: %s", resource); checkArgument(resource.indexOf('=') < 0, "Resource must not contain '=': %s", resource); checkArgument(PRINTABLE_ASCII.matchesAllOf(estimate), "Resource estimate contains spaces or is not US_ASCII: %s", resource); }
@JsonCreator public OrderingScheme(@JsonProperty("orderBy") List<Symbol> orderBy, @JsonProperty("orderings") Map<Symbol, SortOrder> orderings) { requireNonNull(orderBy, "orderBy is null"); requireNonNull(orderings, "orderings is null"); checkArgument(!orderBy.isEmpty(), "orderBy is empty"); checkArgument(orderings.keySet().equals(ImmutableSet.copyOf(orderBy)), "orderBy keys and orderings don't match"); this.orderBy = ImmutableList.copyOf(orderBy); this.orderings = ImmutableMap.copyOf(orderings); }
public static List<Node> selectNodes(int limit, Iterator<Node> candidates) { checkArgument(limit > 0, "limit must be at least 1"); List<Node> selected = new ArrayList<>(limit); while (selected.size() < limit && candidates.hasNext()) { selected.add(candidates.next()); } return selected; }
@JsonCreator protected SetOperationNode( @JsonProperty("id") PlanNodeId id, @JsonProperty("sources") List<PlanNode> sources, @JsonProperty("outputToInputs") ListMultimap<Symbol, Symbol> outputToInputs, @JsonProperty("outputs") List<Symbol> outputs) { super(id); requireNonNull(sources, "sources is null"); checkArgument(!sources.isEmpty(), "Must have at least one source"); requireNonNull(outputToInputs, "outputToInputs is null"); requireNonNull(outputs, "outputs is null"); this.sources = ImmutableList.copyOf(sources); this.outputToInputs = ImmutableListMultimap.copyOf(outputToInputs); this.outputs = ImmutableList.copyOf(outputs); for (Collection<Symbol> inputs : this.outputToInputs.asMap().values()) { checkArgument(inputs.size() == this.sources.size(), "Every source needs to map its symbols to an output %s operation symbol", this.getClass().getSimpleName()); } // Make sure each source positionally corresponds to their Symbol values in the Multimap for (int i = 0; i < sources.size(); i++) { for (Collection<Symbol> expectedInputs : this.outputToInputs.asMap().values()) { checkArgument(sources.get(i).getOutputSymbols().contains(Iterables.get(expectedInputs, i)), "Source does not provide required symbols"); } } }
/** * Returns a hash function which computes its hash code by concatenating the hash codes of the * underlying hash functions together. This can be useful if you need to generate hash codes of a * specific length. * * <p>For example, if you need 1024-bit hash codes, you could join two {@link Hashing#sha512} hash * functions together: {@code Hashing.concatenating(Hashing.sha512(), Hashing.sha512())}. * * @since 19.0 */ public static HashFunction concatenating(Iterable<HashFunction> hashFunctions) { checkNotNull(hashFunctions); // We can't use Iterables.toArray() here because there's no hash->collect dependency List<HashFunction> list = new ArrayList<>(); for (HashFunction hashFunction : hashFunctions) { list.add(hashFunction); } checkArgument(list.size() > 0, "number of hash functions (%s) must be > 0", list.size()); return new ConcatenatedHashFunction(list.toArray(new HashFunction[0])); }
private static Optional<Method> getAggregationStateSerializerFactory(Class<?> aggregationDefinition, Class<?> stateClass) { // Only include methods that match this state class List<Method> stateSerializerFactories = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(aggregationDefinition, AggregationStateSerializerFactory.class).stream() .filter(method -> ((AggregationStateSerializerFactory) method.getAnnotation(AggregationStateSerializerFactory.class)).value().equals(stateClass)) .collect(toImmutableList()); if (stateSerializerFactories.isEmpty()) { return Optional.empty(); } checkArgument(stateSerializerFactories.size() == 1, String.format( "Expect at most 1 @AggregationStateSerializerFactory(%s.class) annotation, found %s in %s", stateClass.toGenericString(), stateSerializerFactories.size(), aggregationDefinition.toGenericString())); return Optional.of(getOnlyElement(stateSerializerFactories)); }
/** * Associates the specified range with the specified value. * * @throws IllegalArgumentException if {@code range} is empty */ @CanIgnoreReturnValue public Builder<K, V> put(Range<K> range, V value) { checkNotNull(range); checkNotNull(value); checkArgument(!range.isEmpty(), "Range must not be empty, but was %s", range); entries.add(Maps.immutableEntry(range, value)); return this; }
JoinUsingAnalysis(List<Integer> leftJoinFields, List<Integer> rightJoinFields, List<Integer> otherLeftFields, List<Integer> otherRightFields) { this.leftJoinFields = ImmutableList.copyOf(leftJoinFields); this.rightJoinFields = ImmutableList.copyOf(rightJoinFields); this.otherLeftFields = ImmutableList.copyOf(otherLeftFields); this.otherRightFields = ImmutableList.copyOf(otherRightFields); checkArgument(leftJoinFields.size() == rightJoinFields.size(), "Expected join fields for left and right to have the same size"); }
public StaticHiveCluster(List<URI> metastoreUris, String metastoreUsername, HiveMetastoreClientFactory clientFactory) { requireNonNull(metastoreUris, "metastoreUris is null"); checkArgument(!metastoreUris.isEmpty(), "metastoreUris must specify at least one URI"); this.addresses = metastoreUris.stream() .map(StaticHiveCluster::checkMetastoreUri) .map(uri -> HostAndPort.fromParts(uri.getHost(), uri.getPort())) .collect(toList()); this.metastoreUsername = metastoreUsername; this.clientFactory = requireNonNull(clientFactory, "clientFactory is null"); }
@JsonCreator public ResourceGroupIdTemplate(String fullId) { List<String> segments = Splitter.on(".").splitToList(requireNonNull(fullId, "fullId is null")); checkArgument(!segments.isEmpty(), "Resource group id is empty"); this.segments = segments.stream() .map(ResourceGroupNameTemplate::new) .collect(Collectors.toList()); }
@JsonCreator public ConnectorId(String catalogName) { this.catalogName = requireNonNull(catalogName, "catalogName is null"); checkArgument(!catalogName.isEmpty(), "catalogName is empty"); }
public DelegatingSystemTablesProvider(List<SystemTablesProvider> delegates) { requireNonNull(delegates, "delegates is null"); checkArgument(delegates.size() >= 1, "empty delegates"); this.delegates = ImmutableList.copyOf(delegates); }
@Override public Type getType(int field) { checkArgument(field < columnHandles.size(), "Invalid field index"); return columnHandles.get(field).getType(); }
@JsonCreator public TpchTableHandle(@JsonProperty("tableName") String tableName, @JsonProperty("scaleFactor") double scaleFactor) { this.tableName = requireNonNull(tableName, "tableName is null"); checkArgument(scaleFactor > 0, "Scale factor must be larger than 0"); this.scaleFactor = scaleFactor; }
private static void binRanges(int numRangesPerBin, List<Range> splitRanges, List<TabletSplitMetadata> prestoSplits) { checkArgument(numRangesPerBin > 0, "number of ranges per bin must positivebe greater than zero"); int toAdd = splitRanges.size(); int fromIndex = 0; int toIndex = Math.min(toAdd, numRangesPerBin); do { // Add the sublist of range handles // Use an empty location because we are binning multiple Ranges spread across many tablet servers prestoSplits.add(new TabletSplitMetadata(Optional.empty(), splitRanges.subList(fromIndex, toIndex))); toAdd -= toIndex - fromIndex; fromIndex = toIndex; toIndex += Math.min(toAdd, numRangesPerBin); } while (toAdd > 0); }
private static Map<String, PartitionStatistics> getPartitionsStatistics(SemiTransactionalHiveMetastore metastore, SchemaTableName table, List<HivePartition> hivePartitions) { if (hivePartitions.isEmpty()) { return ImmutableMap.of(); } boolean unpartitioned = hivePartitions.stream().anyMatch(partition -> partition.getPartitionId().equals(UNPARTITIONED_ID)); if (unpartitioned) { checkArgument(hivePartitions.size() == 1, "expected only one hive partition"); return ImmutableMap.of(UNPARTITIONED_ID, metastore.getTableStatistics(table.getSchemaName(), table.getTableName())); } Set<String> partitionNames = hivePartitions.stream() .map(HivePartition::getPartitionId) .collect(toImmutableSet()); return metastore.getPartitionStatistics(table.getSchemaName(), table.getTableName(), partitionNames); }
private GroupingSets(Optional<NodeLocation> location, List<List<Expression>> sets) { super(location); requireNonNull(sets, "sets is null"); checkArgument(!sets.isEmpty(), "grouping sets cannot be empty"); this.sets = sets.stream().map(ImmutableList::copyOf).collect(toImmutableList()); }
LimitedInputStream(InputStream in, long limit) { super(in); checkNotNull(in); checkArgument(limit >= 0, "limit must be non-negative"); left = limit; }