BigQueryFilter implements BeamSqlTableFilter { private Pair<Boolean, Integer> isSupported(RexNode node) { int numberOfInputRefs = 0; boolean isSupported = true; if (node instanceof RexCall) { RexCall compositeNode = (RexCall) node; if (!node.getKind().belongsTo(SUPPORTED_OPS)) { isSupported = false; } else { for (RexNode operand : compositeNode.getOperands()) { Pair<Boolean, Integer> childSupported = isSupported(operand); if (!node.getKind().belongsTo(ImmutableSet.of(AND, OR))) { numberOfInputRefs += childSupported.getRight(); } isSupported = numberOfInputRefs < 2 && childSupported.getLeft(); } } } else if (node instanceof RexInputRef) { numberOfInputRefs = 1; } else if (node instanceof RexLiteral) { } else { throw new UnsupportedOperationException( "Encountered an unexpected node type: " + node.getClass().getSimpleName()); } return Pair.of(isSupported, numberOfInputRefs); } BigQueryFilter(List<RexNode> predicateCNF); @Override List<RexNode> getNotSupported(); @Override int numSupported(); List<RexNode> getSupported(); @Override String toString();  }
@Test public void testIsSupported() { ImmutableList<Pair<String, Boolean>> sqlQueries = ImmutableList.of( Pair.of("select * from TEST where unused1=100", true), Pair.of("select * from TEST where unused1 in (100, 200)", true), Pair.of("select * from TEST where unused1+10=110", true), Pair.of("select * from TEST where b", true), Pair.of( "select * from TEST where unused1>100 and unused1<=200 and id<>1 and (name='two' or id=2)", true), Pair.of("select * from TEST where unused2=200", true), Pair.of("select * from TEST where name like 'o%e'", true), Pair.of("select * from TEST where unused1=unused2 and id=2", false), Pair.of("select * from TEST where unused1+unused2=10", false)); for (Pair<String, Boolean> query : sqlQueries) { String sql = query.getLeft(); Boolean isSupported = query.getRight(); BeamRelNode beamRelNode = sqlEnv.parseQuery(sql); assertThat(beamRelNode, instanceOf(BeamCalcRel.class)); BigQueryFilter filter = new BigQueryFilter(((BeamCalcRel) beamRelNode).getProgram().split().right); assertThat( "Query: '" + sql + "' is expected to be " + (isSupported ? "supported." : "unsupported."), filter.getNotSupported().isEmpty() == isSupported); } }