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); }
private static OptionalLong getMaxFileDescriptorCount() { try { MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); Object maxFileDescriptorCount = mbeanServer.getAttribute(ObjectName.getInstance(OPERATING_SYSTEM_MXBEAN_NAME), "MaxFileDescriptorCount"); return OptionalLong.of(((Number) maxFileDescriptorCount).longValue()); } catch (Exception e) { return OptionalLong.empty(); } }
/** * 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(); }
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()); }
/** * 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(); }
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 OptionalLong toOptionalLong(long value) { return value != -1 ? OptionalLong.of(value) : 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 getIntegerValue(ConnectorSession session, Type type, Block block) { // works for BIGINT as well as for other integer types TINYINT/SMALLINT/INTEGER that store values as byte/short/int return block.isNull(0) ? OptionalLong.empty() : OptionalLong.of(((Number) type.getObjectValue(session, block, 0)).longValue()); }
protected void assertUpdate(Session session, @Language("SQL") String sql) { QueryAssertions.assertUpdate(queryRunner, session, sql, OptionalLong.empty(), Optional.empty()); }
/** * Hive calculates NDV considering null as a distinct value */ private static OptionalLong fromMetastoreDistinctValuesCount(OptionalLong distinctValuesCount, OptionalLong nullsCount, OptionalLong rowCount) { if (distinctValuesCount.isPresent() && nullsCount.isPresent() && rowCount.isPresent()) { return OptionalLong.of(fromMetastoreDistinctValuesCount(distinctValuesCount.getAsLong(), nullsCount.getAsLong(), rowCount.getAsLong())); } return OptionalLong.empty(); }
private static OptionalLong getTimestampValue(DateTimeZone timeZone, Block block) { // TODO #7122 return block.isNull(0) ? OptionalLong.empty() : OptionalLong.of(MILLISECONDS.toSeconds(timeZone.convertUTCToLocal(block.getLong(0, 0)))); }
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 testBasicStatisticsRoundTrip() { testBasicStatisticsRoundTrip(new HiveBasicStatistics(OptionalLong.empty(), OptionalLong.empty(), OptionalLong.empty(), OptionalLong.empty())); testBasicStatisticsRoundTrip(new HiveBasicStatistics(OptionalLong.of(1), OptionalLong.empty(), OptionalLong.of(2), OptionalLong.empty())); testBasicStatisticsRoundTrip(new HiveBasicStatistics(OptionalLong.of(1), OptionalLong.of(2), OptionalLong.of(3), OptionalLong.of(4))); }
public void testStream_optionalLong() { assertThat(stream(OptionalLong.empty())).isEmpty(); assertThat(stream(OptionalLong.of(5L))).containsExactly(5L); }