public static boolean includesIdField(Collection<FieldPath> projected) { return Iterables.tryFind(projected, path -> Preconditions.checkNotNull(path).equals(ID_FIELD)).isPresent(); }
private static <T> void pushIfPresent(Deque<T> stack, Optional<T> node) { if (node.isPresent()) { stack.addLast(node.get()); } }
private static <T> void acceptIfPresent(Consumer<? super T> action, Optional<T> node) { if (node.isPresent()) { action.accept(node.get()); } } }
public static boolean includesIdField(Collection<FieldPath> projected) { return Iterables.tryFind(projected, new Predicate<FieldPath>() { @Override public boolean apply(FieldPath path) { return Preconditions.checkNotNull(path).equals(ID_FIELD); } }).isPresent(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. */ public static <T> Stream<T> stream(org.apache.drill.shaded.guava.com.google.common.base.Optional<T> optional) { return optional.isPresent() ? Stream.of(optional.get()) : Stream.of(); }
/** * Return true if list of schema path has star column. * @param projected * @return True if the list of {@link org.apache.drill.common.expression.SchemaPath}s has star column. */ public static boolean isStarQuery(Collection<SchemaPath> projected) { return Iterables.tryFind(Preconditions.checkNotNull(projected, COL_NULL_ERROR), new Predicate<SchemaPath>() { @Override public boolean apply(SchemaPath path) { return Preconditions.checkNotNull(path).equals(SchemaPath.STAR_COLUMN); } }).isPresent(); }
@Override public Optional<Long> sizeIfKnown() { Optional<Long> optionalUnslicedSize = ByteSource.this.sizeIfKnown(); if (optionalUnslicedSize.isPresent()) { long unslicedSize = optionalUnslicedSize.get(); long off = Math.min(offset, unslicedSize); return Optional.of(Math.min(length, unslicedSize - off)); } return Optional.absent(); }
@Override public boolean isStarQuery() { return super.isStarQuery() || Iterables.tryFind(getColumns(), new Predicate<SchemaPath>() { private final SchemaPath COLUMNS = SchemaPath.getSimplePath("columns"); @Override public boolean apply(@Nullable SchemaPath path) { return path.equals(COLUMNS); } }).isPresent(); }
@Override public Optional<Long> lengthIfKnown() { long result = 0L; for (CharSource source : sources) { Optional<Long> lengthIfKnown = source.lengthIfKnown(); if (!lengthIfKnown.isPresent()) { return Optional.absent(); } result += lengthIfKnown.get(); } return Optional.of(result); }
@Override public Optional<Long> sizeIfKnown() { long result = 0L; for (ByteSource source : sources) { Optional<Long> sizeIfKnown = source.sizeIfKnown(); if (!sizeIfKnown.isPresent()) { return Optional.absent(); } result += sizeIfKnown.get(); } return Optional.of(result); }
@Override public boolean isStarQuery() { if(settings.isUseRepeatedVarChar()) { return super.isStarQuery() || Iterables.tryFind(getColumns(), new Predicate<SchemaPath>() { @Override public boolean apply(@Nullable SchemaPath path) { return path.equals(RepeatedVarCharOutput.COLUMNS); } }).isPresent(); } return super.isStarQuery(); }
/** * Returns whether the source has zero chars. The default implementation first checks * {@link #lengthIfKnown}, returning true if it's known to be zero and false if it's known to be * non-zero. If the length is not known, it falls back to opening a stream and checking for EOF. * * <p>Note that, in cases where {@code lengthIfKnown} returns zero, it is <i>possible</i> that * chars are actually available for reading. This means that a source may return {@code true} from * {@code isEmpty()} despite having readable content. * * @throws IOException if an I/O error occurs * @since 15.0 */ public boolean isEmpty() throws IOException { Optional<Long> lengthIfKnown = lengthIfKnown(); if (lengthIfKnown.isPresent()) { return lengthIfKnown.get() == 0L; } Closer closer = Closer.create(); try { Reader reader = closer.register(openStream()); return reader.read() == -1; } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
/** * Returns whether the source has zero bytes. The default implementation first checks * {@link #sizeIfKnown}, returning true if it's known to be zero and false if it's known to be * non-zero. If the size is not known, it falls back to opening a stream and checking for EOF. * * <p>Note that, in cases where {@code sizeIfKnown} returns zero, it is <i>possible</i> that bytes * are actually available for reading. (For example, some special files may return a size of 0 * despite actually having content when read.) This means that a source may return {@code true} * from {@code isEmpty()} despite having readable content. * * @throws IOException if an I/O error occurs * @since 15.0 */ public boolean isEmpty() throws IOException { Optional<Long> sizeIfKnown = sizeIfKnown(); if (sizeIfKnown.isPresent()) { return sizeIfKnown.get() == 0L; } Closer closer = Closer.create(); try { InputStream in = closer.register(openStream()); return in.read() == -1; } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
public long length() throws IOException { Optional<Long> lengthIfKnown = lengthIfKnown(); if (lengthIfKnown.isPresent()) { return lengthIfKnown.get();
if (sizeIfKnown.isPresent()) { return sizeIfKnown.get();
if(nonNullExpr.isPresent()) { MajorType type = nonNullExpr.get().getMajorType(); conditions = new IfExpression.IfCondition(conditions.condition, rewriteNullExpression(conditions.expression, type));