Creates a path with a given list of names starting from a given root schema.
(CalciteSchema rootSchema, Iterable<String> names)
| 558 | /** Creates a path with a given list of names starting from a given root |
| 559 | * schema. */ |
| 560 | public static Path path(CalciteSchema rootSchema, Iterable<String> names) { |
| 561 | final ImmutableList.Builder<Pair<String, Schema>> builder = |
| 562 | ImmutableList.builder(); |
| 563 | Schema schema = rootSchema.plus(); |
| 564 | final Iterator<String> iterator = names.iterator(); |
| 565 | if (!iterator.hasNext()) { |
| 566 | return PathImpl.EMPTY; |
| 567 | } |
| 568 | if (!rootSchema.name.isEmpty()) { |
| 569 | // If path starts with the name of the root schema, ignore the first step |
| 570 | // in the path. |
| 571 | checkState(rootSchema.name.equals(iterator.next())); |
| 572 | } |
| 573 | for (;;) { |
| 574 | final String name = iterator.next(); |
| 575 | builder.add(Pair.of(name, schema)); |
| 576 | if (!iterator.hasNext()) { |
| 577 | return path(builder.build()); |
| 578 | } |
| 579 | Schema next = schema.subSchemas().get(name); |
| 580 | if (next == null) { |
| 581 | throw new IllegalArgumentException("schema " + name + " is not found in " + schema); |
| 582 | } |
| 583 | schema = next; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | public static Path path(Iterable<? extends Map.Entry<String, Schema>> list) { |
| 588 | return new PathImpl(ImmutablePairList.copyOf(list)); |