Java Code Examples for org.apache.calcite.util.Util#filter()
The following examples show how to use
org.apache.calcite.util.Util#filter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RexUtil.java From Bats with Apache License 2.0 | 6 votes |
/** * Creates the expression {@code e1 AND NOT notTerm1 AND NOT notTerm2 ...}. * * <p>Examples: * <ul> * <li>andNot(p) returns "p" * <li>andNot(p, n1, n2) returns "p AND NOT n1 AND NOT n2" * <li>andNot(x = 10, x = 20, y = 30, x = 30) * returns "x = 10 AND NOT (y = 30)" * </ul> */ public static RexNode andNot(final RexBuilder rexBuilder, RexNode e, Iterable<? extends RexNode> notTerms) { // If "e" is of the form "x = literal", remove all "x = otherLiteral" // terms from notTerms. switch (e.getKind()) { case EQUALS: final RexCall call = (RexCall) e; if (call.getOperands().get(1) instanceof RexLiteral) { notTerms = Util.filter(notTerms, e2 -> { switch (e2.getKind()) { case EQUALS: RexCall call2 = (RexCall) e2; if (call2.getOperands().get(0).equals(call.getOperands().get(0)) && call2.getOperands().get(1) instanceof RexLiteral && !call.getOperands().get(1).equals(call2.getOperands().get(1))) { return false; } } return true; }); } } return composeConjunction(rexBuilder, Iterables.concat(ImmutableList.of(e), Iterables.transform(notTerms, e2 -> not(rexBuilder, e2)))); }
Example 2
Source File: AbstractRelOptPlanner.java From calcite with Apache License 2.0 | 5 votes |
/** Returns sub-classes of relational expression. */ public Iterable<Class<? extends RelNode>> subClasses( final Class<? extends RelNode> clazz) { return Util.filter(classes, c -> { // RelSubset must be exact type, not subclass if (c == RelSubset.class) { return c == clazz; } return clazz.isAssignableFrom(c); }); }
Example 3
Source File: RexUtil.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates the expression {@code e1 AND NOT notTerm1 AND NOT notTerm2 ...}. * * <p>Examples: * <ul> * <li>andNot(p) returns "p" * <li>andNot(p, n1, n2) returns "p AND NOT n1 AND NOT n2" * <li>andNot(x = 10, x = 20, y = 30, x = 30) * returns "x = 10 AND NOT (y = 30)" * </ul> */ public static @Nonnull RexNode andNot(final RexBuilder rexBuilder, RexNode e, Iterable<? extends RexNode> notTerms) { // If "e" is of the form "x = literal", remove all "x = otherLiteral" // terms from notTerms. switch (e.getKind()) { case EQUALS: final RexCall call = (RexCall) e; if (call.getOperands().get(1) instanceof RexLiteral) { notTerms = Util.filter(notTerms, e2 -> { switch (e2.getKind()) { case EQUALS: RexCall call2 = (RexCall) e2; if (call2.getOperands().get(0) .equals(call.getOperands().get(0)) && call2.getOperands().get(1) instanceof RexLiteral && !call.getOperands().get(1) .equals(call2.getOperands().get(1))) { return false; } } return true; }); } } return composeConjunction(rexBuilder, Iterables.concat(ImmutableList.of(e), Iterables.transform(notTerms, e2 -> not(rexBuilder, e2)))); }
Example 4
Source File: FilteratorTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testBox() { final Number[] numbers = {1, 2, 3.14, 4, null, 6E23}; List<Integer> result = new ArrayList<Integer>(); for (int i : Util.filter(Arrays.asList(numbers), Integer.class)) { result.add(i); } assertEquals("[1, 2, 4]", result.toString()); }
Example 5
Source File: AttributedDirectedGraph.java From Bats with Apache License 2.0 | 4 votes |
/** Returns all edges between one vertex to another. */ public Iterable<E> getEdges(V source, final V target) { final VertexInfo<V, E> info = vertexMap.get(source); return Util.filter(info.outEdges, outEdge -> outEdge.target.equals(target)); }
Example 6
Source File: AbstractRelOptPlanner.java From Bats with Apache License 2.0 | 4 votes |
/** Returns sub-classes of relational expression. */ public Iterable<Class<? extends RelNode>> subClasses( final Class<? extends RelNode> clazz) { return Util.filter(classes, clazz::isAssignableFrom); }
Example 7
Source File: AttributedDirectedGraph.java From calcite with Apache License 2.0 | 4 votes |
/** Returns all edges between one vertex to another. */ public Iterable<E> getEdges(V source, final V target) { final VertexInfo<V, E> info = vertexMap.get(source); return Util.filter(info.outEdges, outEdge -> outEdge.target.equals(target)); }