forked from apache/calcite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CALCITE-6268] Support implementing custom JdbcSchema
- Loading branch information
Showing
3 changed files
with
29 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import org.apache.calcite.schema.Schema; | ||
import org.apache.calcite.schema.SchemaPlus; | ||
import org.apache.calcite.schema.Schemas; | ||
import org.apache.calcite.schema.Wrapper; | ||
import org.apache.calcite.schema.impl.AbstractSchema; | ||
import org.apache.calcite.sql.SqlDialect; | ||
import org.apache.calcite.sql.SqlDialectFactory; | ||
|
@@ -54,7 +55,7 @@ | |
* {@link JdbcSchema} for each schema name. Each JdbcSchema will populate its | ||
* tables on demand. | ||
*/ | ||
public class JdbcCatalogSchema extends AbstractSchema { | ||
public class JdbcCatalogSchema extends AbstractSchema implements Wrapper { | ||
final DataSource dataSource; | ||
public final SqlDialect dialect; | ||
final JdbcConvention convention; | ||
|
@@ -137,6 +138,17 @@ public DataSource getDataSource() { | |
return dataSource; | ||
} | ||
|
||
|
||
@Override public <T extends Object> T unwrap(Class<T> clazz) { | ||
if (clazz.isInstance(this)) { | ||
return clazz.cast(this); | ||
} | ||
if (clazz == DataSource.class) { | ||
return clazz.cast(getDataSource()); | ||
} | ||
return null; | ||
Check failure on line 149 in core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java GitHub Actions / CheckerFramework (JDK 11)
Check failure on line 149 in core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java GitHub Actions / CheckerFramework (JDK 11), oldest Guava
|
||
} | ||
|
||
/** Contains sub-schemas by name, and the name of the default schema. */ | ||
private static class SubSchemaMap { | ||
final String defaultSchemaName; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import org.apache.calcite.schema.SchemaVersion; | ||
import org.apache.calcite.schema.Schemas; | ||
import org.apache.calcite.schema.Table; | ||
import org.apache.calcite.schema.Wrapper; | ||
import org.apache.calcite.sql.SqlDialect; | ||
import org.apache.calcite.sql.SqlDialectFactory; | ||
import org.apache.calcite.sql.SqlDialectFactoryImpl; | ||
|
@@ -75,7 +76,7 @@ | |
* queries against this schema are executed against those tables, pushing down | ||
* as much as possible of the query logic to SQL. | ||
*/ | ||
public class JdbcSchema implements Schema { | ||
public class JdbcSchema implements Schema, Wrapper { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcSchema.class); | ||
|
||
final DataSource dataSource; | ||
|
@@ -512,6 +513,17 @@ protected Map<String, RelProtoDataType> getTypes() { | |
return ImmutableSet.of(); | ||
} | ||
|
||
@Override public <T extends Object> T unwrap(Class<T> clazz) { | ||
if (clazz.isInstance(this)) { | ||
return clazz.cast(this); | ||
} | ||
if (clazz == DataSource.class) { | ||
return clazz.cast(getDataSource()); | ||
} | ||
return null; | ||
Check failure on line 523 in core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java GitHub Actions / CheckerFramework (JDK 11)
Check failure on line 523 in core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java GitHub Actions / CheckerFramework (JDK 11), oldest Guava
|
||
} | ||
|
||
|
||
private static void close( | ||
@Nullable Connection connection, | ||
@Nullable Statement statement, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters