This is an automated email from the ASF dual-hosted git repository.
rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new dfbcc9bbc1 [CALCITE-6903] CalciteSchema#getSubSchemaMap must consider
implicit sub-schemas
dfbcc9bbc1 is described below
commit dfbcc9bbc168a05c8ca309993b380e6def11b9d9
Author: Ruben Quesada Lopez <[email protected]>
AuthorDate: Wed Mar 19 11:44:03 2025 +0000
[CALCITE-6903] CalciteSchema#getSubSchemaMap must consider implicit
sub-schemas
---
.../org/apache/calcite/jdbc/CalciteSchema.java | 11 +++---
.../java/org/apache/calcite/test/JdbcTest.java | 41 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
index 60978fc5d2..53cffca371 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
@@ -313,15 +313,14 @@ public List<? extends List<String>> getPath() {
}
/** Returns a collection of sub-schemas, both explicit (defined using
- * {@link #add(String, org.apache.calcite.schema.Schema)}) and implicit
- * (defined using {@link
org.apache.calcite.schema.Schema#getSubSchemaNames()}
- * and {@link Schema#getSubSchema(String)}). */
+ * {@link #add(String, org.apache.calcite.schema.Schema)}) and implicit. */
public final NavigableMap<String, CalciteSchema> getSubSchemaMap() {
- // Build a map of implicit sub-schemas first, then explicit sub-schemas.
- // If there are implicit and explicit with the same name, explicit wins.
final ImmutableSortedMap.Builder<String, CalciteSchema> builder =
new ImmutableSortedMap.Builder<>(NameSet.COMPARATOR);
- builder.putAll(subSchemaMap.map());
+ final Lookup<CalciteSchema> schemas = subSchemas();
+ for (String name : schemas.getNames(LikePattern.any())) {
+ builder.put(name, requireNonNull(schemas.get(name)));
+ }
return builder.build();
}
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
index b53c71599d..21369dac3a 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -7568,6 +7568,47 @@ private void
testConvertOracleInternal(CalciteAssert.AssertThat with) {
assertThat(aSchema.subSchemas().getNames(LikePattern.any()), hasSize(2));
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6903">[CALCITE-6903]
+ * CalciteSchema#getSubSchemaMap must consider implicit sub-schemas</a>. */
+ @Test void testCalciteSchemaGetSubSchemaMapCache() {
+ checkCalciteSchemaGetSubSchemaMap(true);
+ }
+
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6903">[CALCITE-6903]
+ * CalciteSchema#getSubSchemaMap must consider implicit sub-schemas</a>. */
+ @Test void testCalciteSchemaGetSubSchemaMapNoCache() {
+ checkCalciteSchemaGetSubSchemaMap(false);
+ }
+
+ void checkCalciteSchemaGetSubSchemaMap(boolean cache) {
+ final CalciteSchema calciteSchema = CalciteSchema.createRootSchema(false,
cache);
+
+ // create schema "/a"
+ final Map<String, Schema> aSubSchemaMap = new HashMap<>();
+ final CalciteSchema aSchema =
+ calciteSchema.add("a", new AbstractSchema() {
+ @Override protected Map<String, Schema> getSubSchemaMap() {
+ return aSubSchemaMap;
+ }
+ });
+
+ // add explicit schema "/a/b".
+ aSchema.add("b", new AbstractSchema());
+
+ // add implicit schema "/a/c"
+ aSubSchemaMap.put("c", new AbstractSchema());
+
+ assertThat(aSchema.subSchemas().get("c"), notNullValue());
+ assertThat(aSchema.subSchemas().get("b"), notNullValue());
+
+ final Map<String, CalciteSchema> subSchemaMap = aSchema.getSubSchemaMap();
+ assertThat(subSchemaMap.values(), hasSize(2));
+ assertThat(subSchemaMap.get("c"), notNullValue());
+ assertThat(subSchemaMap.get("b"), notNullValue());
+ }
+
@Test void testCaseSensitiveConfigurableSimpleCalciteSchema() {
final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false,
false).plus();
// create schema "/a"