RexNode compose(RexBuilder rexBuilder, Iterable<RexNode> exprs) { exprs = Linq4j.asEnumerable(exprs).where(new Predicate1<RexNode>() { public boolean apply(RexNode expr) { return expr != null; } }); return RexUtil.composeConjunction(rexBuilder, exprs, false); }
final List<Object[]> rows = serversTable.scan(dataContext).toList(); Assert.assertEquals(2, rows.size()); Object[] row1 = rows.get(0);
final Supplier<Sequence<Object[]>> resultsSupplier = () -> { final Enumerable enumerable = theRel.bind(dataContext); final Enumerator enumerator = enumerable.enumerator(); return Sequences.withBaggage(new BaseSequence<>( new BaseSequence.IteratorMaker<Object[], EnumeratorIterator<Object[]>>()
return Linq4j.asEnumerable( CalciteSchema.from(getConnection().getRootSchema()).getSubSchemaMap().values()) .select( new Function1<CalciteSchema, MetaSchema>() { public MetaSchema apply(CalciteSchema calciteSchema) { .where(catalogMatcher) .selectMany( new Function1<MetaSchema, Enumerable<MetaSchema>>() { @Override .orderBy( new Function1<MetaSchema, Comparable>() { public Comparable apply(MetaSchema metaSchema) {
namedMatcher(columnNamePattern); return createResultSet(schemas(catalog) .where(schemaMatcher) .selectMany(schema -> tables(schema, tableNameMatcher)) .selectMany(this::columns) .where(columnMatcher), MetaColumn.class, "TABLE_CAT",
CatalogScope(SqlValidatorScope parent, List<String> names) { super(parent); this.names = ImmutableList.copyOf(names); this.schemaNames = Linq4j.asEnumerable( validator.getCatalogReader() .getAllSchemaObjectNames(ImmutableList.of())) .where(input -> input.getType() == SqlMonikerType.SCHEMA) .select(SqlMoniker::getFullyQualifiedNames) .into(new HashSet<>()); }
/** Converts an {@link Enumerable} over object arrays into an * {@link Enumerable} over {@link Row} objects. */ public static Enumerable<Row> toRow(final Enumerable<Object[]> enumerable) { return enumerable.select((Function1<Object[], Row>) Row::asCopy); }
/** * Produces the set intersection of two sequences by * using the specified {@code EqualityComparer<TSource>} to compare * values. */ public static <TSource> Enumerable<TSource> intersect( Enumerable<TSource> source0, Enumerable<TSource> source1, EqualityComparer<TSource> comparer) { if (comparer == Functions.identityComparer()) { return intersect(source0, source1); } Set<Wrapped<TSource>> set0 = new HashSet<>(); Function1<TSource, Wrapped<TSource>> wrapper = wrapperFor(comparer); source0.select(wrapper).into(set0); Set<Wrapped<TSource>> set1 = new HashSet<>(); try (Enumerator<Wrapped<TSource>> os = source1.select(wrapper).enumerator()) { while (os.moveNext()) { Wrapped<TSource> o = os.current(); if (set0.contains(o)) { set1.add(o); } } } Function1<Wrapped<TSource>, TSource> unwrapper = unwrapper(); return Linq4j.asEnumerable(set1).select(unwrapper); }
public <E> Queryable<E> asQueryable( QueryProvider queryProvider, SchemaPlus schema, String tableName) { //noinspection unchecked return (Queryable<E>) enumerable.asQueryable(); }
Enumerable<MetaTable> tables(final MetaSchema schema_) { final QuarkMetaSchema schema = (QuarkMetaSchema) schema_; return Linq4j.asEnumerable(schema.calciteSchema.getTableNames()) .select( new Function1<String, MetaTable>() { public MetaTable apply(String name) { final Table table = schema.calciteSchema.getTable(name, true).getTable(); return new QuarkMetaTable(table, schema.tableCatalog, schema.tableSchem, name); } }) .concat( Linq4j.asEnumerable( schema.calciteSchema.getTablesBasedOnNullaryFunctions() .entrySet()) .select( new Function1<Map.Entry<String, Table>, MetaTable>() { public MetaTable apply(Map.Entry<String, Table> pair) { final Table table = pair.getValue(); return new QuarkMetaTable(table, schema.tableCatalog, schema.tableSchem, pair.getKey()); } })); }
Enumerable<MetaSchema> schemas(final String catalog) { return Linq4j.asEnumerable( getConnection().rootSchema.getSubSchemaMap().values()) .select((Function1<CalciteSchema, MetaSchema>) calciteSchema -> new CalciteMetaSchema(calciteSchema, catalog, calciteSchema.getName())) .orderBy((Function1<MetaSchema, Comparable>) metaSchema -> (Comparable) FlatLists.of(Util.first(metaSchema.tableCatalog, ""), metaSchema.tableSchem)); }
/** * Returns the rel nodes in this rel subset. All rels must have the same * traits and are logically equivalent. * * @return all the rels in the subset */ public Iterable<RelNode> getRels() { return () -> Linq4j.asEnumerable(set.rels) .where(v1 -> v1.getTraitSet().satisfies(traitSet)) .iterator(); }
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName) { final Enumerable<Integer> enumerable = a.select(a0 -> offset + ((Integer) a0[0])); //noinspection unchecked return (Queryable) enumerable.asQueryable(); } };
public void sortAndAccumulate(Iterable<TSource> sourceIterable, TAccumulate accumulator) { List<TSource> sorted = Linq4j.asEnumerable(sourceIterable) .orderBy(keySelector, comparator) .toList(); TAccumulate accumulator1 = accumulator; for (TSource source : sorted) { accumulator1 = accumulatorAdder.apply(accumulator1, source); } } }
/** * Produces the set union of two sequences by using a * specified EqualityComparer<TSource>. */ public static <TSource> Enumerable<TSource> union(Enumerable<TSource> source0, Enumerable<TSource> source1, final EqualityComparer<TSource> comparer) { if (comparer == Functions.identityComparer()) { return union(source0, source1); } Set<Wrapped<TSource>> set = new HashSet<>(); Function1<TSource, Wrapped<TSource>> wrapper = wrapperFor(comparer); Function1<Wrapped<TSource>, TSource> unwrapper = unwrapper(); source0.select(wrapper).into(set); source1.select(wrapper).into(set); return Linq4j.asEnumerable(set).select(unwrapper); }
/** * Produces the set difference of two sequences by * using the default equality comparer to compare values. (Defined * by Enumerable.) */ public static <TSource> Enumerable<TSource> except( Enumerable<TSource> source0, Enumerable<TSource> source1) { Set<TSource> set = new HashSet<>(); source0.into(set); try (Enumerator<TSource> os = source1.enumerator()) { while (os.moveNext()) { TSource o = os.current(); set.remove(o); } return Linq4j.asEnumerable(set); } }
public Iterator<T> iterator() { return enumerable.iterator(); }
/** Default implementation of {@link ExtendedEnumerable#removeAll(Collection)}. */ public static <T, C extends Collection<? super T>> C remove( Enumerable<T> source, C sink) { List<T> tempList = new ArrayList<>(); source.into(tempList); sink.removeAll(tempList); return sink; }