@Test(expected = IllegalArgumentException.class) public void testMultiSqlInsert() throws IOException, ParseException { String sql = Joiner.on(";\n").join( "INSERT INTO foo (SELECT * FROM bar)", "INSERT INTO foo (SELECT * FROM bar)" ); SqlNodeList nodes = Planner.parse(sql); Validator validator = new Validator(); validator.validateExactlyOnceSelect(nodes); }
@VisibleForTesting void validateExactlyOnceSelect(SqlNodeList query) { Preconditions.checkArgument(query.size() > 0); SqlNode last = query.get(query.size() - 1); long n = StreamSupport.stream(query.spliterator(), false) .filter(x -> x instanceof SqlSelect) .count(); Preconditions.checkArgument(n == 1 && last instanceof SqlSelect, "Only one top-level SELECT statement is allowed"); statement = (SqlSelect) last; }
Validator { @VisibleForTesting void validateExactlyOnceSelect(SqlNodeList query) { Preconditions.checkArgument(query.size() > 0); SqlNode last = query.get(query.size() - 1); long n = StreamSupport.stream(query.spliterator(), false) .filter(x -> x instanceof SqlSelect) .count(); Preconditions.checkArgument(n == 1 && last instanceof SqlSelect, "Only one top-level SELECT statement is allowed"); statement = (SqlSelect) last; } }
Validator { @VisibleForTesting void validateExactlyOnceSelect(SqlNodeList query) { Preconditions.checkArgument(query.size() > 0); SqlNode last = query.get(query.size() - 1); long n = StreamSupport.stream(query.spliterator(), false) .filter(x -> x instanceof SqlSelect) .count(); Preconditions.checkArgument(n == 1 && last instanceof SqlSelect, "Only one top-level SELECT statement is allowed"); statement = (SqlSelect) last; }  }
Validator { @VisibleForTesting void validateExactlyOnceSelect(SqlNodeList query) { Preconditions.checkArgument(query.size() > 0); SqlNode last = query.get(query.size() - 1); long n = StreamSupport.stream(query.spliterator(), false) .filter(x -> x instanceof SqlSelect) .count(); Preconditions.checkArgument(n == 1 && last instanceof SqlSelect, "Only one top-level SELECT statement is allowed"); statement = (SqlSelect) last; }   }
Validator { @VisibleForTesting void validateExactlyOnceSelect(SqlNodeList query) { Preconditions.checkArgument(query.size() > 0); SqlNode last = query.get(query.size() - 1); long n = StreamSupport.stream(query.spliterator(), false) .filter(x -> x instanceof SqlSelect) .count(); Preconditions.checkArgument(n == 1 && last instanceof SqlSelect, "Only one top-level SELECT statement is allowed"); statement = (SqlSelect) last; }    }