public Builder setDistinctValuesCount(long distinctValuesCount) { this.distinctValuesCount = OptionalLong.of(distinctValuesCount); return this; }
public Builder setTotalSizeInBytes(long totalSizeInBytes) { this.totalSizeInBytes = OptionalLong.of(totalSizeInBytes); return this; }
@Override public void setUpdateCount(long count) { updateCount.set(OptionalLong.of(count)); }
@JsonCreator public HiveBasicStatistics( @JsonProperty("fileCount") OptionalLong fileCount, @JsonProperty("rowCount") OptionalLong rowCount, @JsonProperty("inMemoryDataSizeInBytes") OptionalLong inMemoryDataSizeInBytes, @JsonProperty("onDiskDataSizeInBytes") OptionalLong onDiskDataSizeInBytes) { this.fileCount = requireNonNull(fileCount, "fileCount is null"); this.rowCount = requireNonNull(rowCount, "rowCount is null"); this.inMemoryDataSizeInBytes = requireNonNull(inMemoryDataSizeInBytes, "inMemoryDataSizeInBytes is null"); this.onDiskDataSizeInBytes = requireNonNull(onDiskDataSizeInBytes, "onDiskDataSizeInBytes is null"); }
private OptionalLong toOptionalLong(long value) { return (value != -1 ? OptionalLong.of(value) : OptionalLong.empty()); } }
private OptionalLong toOptionalLong(long value) { return value != -1 ? OptionalLong.of(value) : OptionalLong.empty(); }
/** * Impala `COMPUTE STATS` will write -1 as the null count. * * @see <a href="https://issues.apache.org/jira/browse/IMPALA-7497">IMPALA-7497</a> */ public static OptionalLong fromMetastoreNullsCount(long nullsCount) { if (nullsCount == -1L) { return OptionalLong.empty(); } return OptionalLong.of(nullsCount); }
@Generates private OptionalLong generateOptionalLong() { return OptionalLong.of(generateLong()); }
/** * Determine, if possible, the contentLength of the given resource without reading it. * @param resource the resource instance * @return the contentLength of the resource */ private OptionalLong contentLength(Resource resource) { // Don't try to determine contentLength on InputStreamResource - cannot be read afterwards... // Note: custom InputStreamResource subclasses could provide a pre-calculated content length! if (InputStreamResource.class != resource.getClass()) { try { return OptionalLong.of(resource.contentLength()); } catch (IOException ignored) { } } return OptionalLong.empty(); }
/** * Returns the last element of the specified stream, or {@link OptionalLong#empty} if the stream * is empty. * * <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This * method's runtime will be between O(log n) and O(n), performing better on <a * href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a> * streams. * * @see LongStream#findFirst() * @throws NullPointerException if the last element of the stream is null */ public static OptionalLong findLast(LongStream stream) { // findLast(Stream) does some allocation, so we might as well box some more java.util.Optional<Long> boxedLast = findLast(stream.boxed()); return boxedLast.isPresent() ? OptionalLong.of(boxedLast.get()) : OptionalLong.empty(); }
private static OptionalLong toMetastoreDistinctValuesCount(OptionalLong distinctValuesCount, OptionalLong nullsCount) { // metastore counts null as a distinct value if (distinctValuesCount.isPresent() && nullsCount.isPresent()) { return OptionalLong.of(distinctValuesCount.getAsLong() + (nullsCount.getAsLong() > 0 ? 1 : 0)); } return OptionalLong.empty(); }
private static OptionalLong tryParse(String value) { Long number = Longs.tryParse(value); if (number != null) { return OptionalLong.of(number); } return OptionalLong.empty(); }
@Override public OptionalLong contentLength() { long value = delegate().getContentLength(); return (value != -1 ? OptionalLong.of(value) : OptionalLong.empty()); }
public static OptionalLong getTotalSizeInBytes(OptionalDouble averageColumnLength, OptionalLong rowCount, OptionalLong nullsCount) { if (averageColumnLength.isPresent() && rowCount.isPresent() && nullsCount.isPresent()) { long nonNullsCount = rowCount.getAsLong() - nullsCount.getAsLong(); if (nonNullsCount < 0) { return OptionalLong.empty(); } return OptionalLong.of(round(averageColumnLength.getAsDouble() * nonNullsCount)); } return OptionalLong.empty(); }
private static OptionalLong parse(@Nullable String parameterValue) { if (parameterValue == null) { return OptionalLong.empty(); } Long longValue = Longs.tryParse(parameterValue); if (longValue == null || longValue < 0) { return OptionalLong.empty(); } return OptionalLong.of(longValue); }
private OptionalLong toOptionalLong(long value) { return value != -1 ? OptionalLong.of(value) : OptionalLong.empty(); }
public CachingHiveMetastore(ExtendedHiveMetastore delegate, ExecutorService executor, Duration cacheTtl, Duration refreshInterval, long maximumSize) { this( delegate, executor, OptionalLong.of(cacheTtl.toMillis()), refreshInterval.toMillis() >= cacheTtl.toMillis() ? OptionalLong.empty() : OptionalLong.of(refreshInterval.toMillis()), maximumSize); }
@Test public void contentLength() { OptionalLong contentLength = OptionalLong.of(42L); when(mockHeaders.contentLength()).thenReturn(contentLength); assertSame(contentLength, wrapper.contentLength()); }
@Test public void header() { HttpHeaders httpHeaders = new HttpHeaders(); long contentLength = 42L; httpHeaders.setContentLength(contentLength); MediaType contentType = MediaType.TEXT_PLAIN; httpHeaders.setContentType(contentType); InetSocketAddress host = InetSocketAddress.createUnresolved("localhost", 80); httpHeaders.setHost(host); List<HttpRange> range = Collections.singletonList(HttpRange.createByteRange(0, 42)); httpHeaders.setRange(range); when(mockResponse.getHeaders()).thenReturn(httpHeaders); ClientResponse.Headers headers = defaultClientResponse.headers(); assertEquals(OptionalLong.of(contentLength), headers.contentLength()); assertEquals(Optional.of(contentType), headers.contentType()); assertEquals(httpHeaders, headers.asHttpHeaders()); }
public void testStream_optionalLong() { assertThat(stream(OptionalLong.empty())).isEmpty(); assertThat(stream(OptionalLong.of(5L))).containsExactly(5L); }