本文整理汇总了Java中org.apache.calcite.schema.Schema类的典型用法代码示例。如果您正苦于以下问题:Java Schema类的具体用法?Java Schema怎么用?Java Schema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Schema类属于org.apache.calcite.schema包,在下文中一共展示了Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPlan
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
SqlDropView dropView = unwrap(sqlNode, SqlDropView.class);
final String viewToDrop = dropView.getName();
final AbstractSchema drillSchema =
SchemaUtilites.resolveToMutableDrillSchema(context.getNewDefaultSchema(), dropView.getSchemaPath());
final String schemaPath = drillSchema.getFullSchemaName();
final Table existingTable = SqlHandlerUtil.getTableFromSchema(drillSchema, viewToDrop);
if (existingTable != null && existingTable.getJdbcTableType() != Schema.TableType.VIEW) {
throw UserException.validationError()
.message("[%s] is not a VIEW in schema [%s]", viewToDrop, schemaPath)
.build(logger);
} else if (existingTable == null) {
throw UserException.validationError()
.message("Unknown view [%s] in schema [%s].", viewToDrop, schemaPath)
.build(logger);
}
drillSchema.dropView(viewToDrop);
return DirectPlan.createDirectPlan(context, true,
String.format("View [%s] deleted successfully from schema [%s].", viewToDrop, schemaPath));
}
示例2: getSubSchema
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
@Override
public Schema getSubSchema(String name) {
// This gets called for same schema name multiple times. cache the result.
final SimpleSchema directRootLevelSchema = findRootLevelSubSchema(name);
if (directRootLevelSchema != null) {
return directRootLevelSchema;
}
// If the name refers to schema subschema promoted to root level (possible when exposing schemas to BI tools,
// because BI tools can not work with more than one level of subschema
final List<String> subSchemaPath = SubSchemaWrapper.toSubSchemaPath(name);
if (subSchemaPath.size() <= 1) {
return null; // still a top-level schema as the path components contains just one.
}
final SimpleSchema rootLevelSchema = findRootLevelSubSchema(subSchemaPath.get(0));
Schema schema = rootLevelSchema;
for(int i = 1; i < subSchemaPath.size(); i++) {
if (schema == null) {
return null;
}
schema = schema.getSubSchema(subSchemaPath.get(i));
}
return schema;
}
示例3: getTable
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
@Override
public Table getTable(String name) {
Schema schema = getDefaultSchema();
if (schema != null) {
try {
Table t = schema.getTable(name);
if (t != null) {
return t;
}
return schema.getTable(name.toUpperCase());
} catch (RuntimeException e) {
logger.warn("Failure while attempting to read table '{}' from JDBC source.", name, e);
}
}
// no table was found.
return null;
}
示例4: SubSchemaCache
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
private SubSchemaCache(final CalciteSchema calciteSchema,
NavigableSet<String> names) {
this.names = names;
this.cache = CacheBuilder.newBuilder().build(
new CacheLoader<String, CalciteSchema>() {
@SuppressWarnings(value = "NullableProblems")
@Override
public CalciteSchema load(String schemaName) {
final Schema subSchema =
calciteSchema.getSchema().getSubSchema(schemaName);
if (subSchema == null) {
throw new RuntimeException("sub-schema " + schemaName
+ " not found");
}
return new CachingCalciteSchema(calciteSchema, subSchema, schemaName);
}
});
}
示例5: OctopusMetaModelDataSource
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
public OctopusMetaModelDataSource(MetaDataSource metaDataSource) {
super(metaDataSource);
LOG.debug("create OctopusMetaModelDataSource. dataSourceName: " + metaDataSource.getName());
JSONParser jsonParser = new JSONParser();
try {
connectionInfo = (JSONObject) jsonParser.parse(metaDataSource.getConnectionString());
} catch (ParseException ignore) {
/*
* NOTE: parse() never fail, because ADD DATASOURCE... succeeded.
* This assumption is NOT preferable.
*/
}
ImmutableMap.Builder<String, Schema> builder = ImmutableMap.builder();
for (MetaSchema metaSchema : metaDataSource.getSchemas())
builder.put(metaSchema.getName(), new OctopusMetaModelSchema(metaSchema, this));
setSubSchemaMap(builder.build());
}
示例6: OctopusJdbcDataSource
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
public OctopusJdbcDataSource(SchemaPlus parentSchema, MetaDataSource metaDataSource) {
super(metaDataSource);
LOG.debug("create OctopusJdbcDataSource. dataSourceName: " + metaDataSource.getName());
dataSource = dataSource(metaDataSource.getConnectionString(), metaDataSource.getDriverName());
/* TODO: what is this? */
final Expression expression =
Schemas.subSchemaExpression(parentSchema, getName(), OctopusJdbcSchema.class);
this.dialect = createDialect(dataSource);
this.convention = JdbcConvention.of(dialect, expression, metaDataSource.getName());
ImmutableMap.Builder<String, Schema> builder = ImmutableMap.builder();
for (MetaSchema metaSchema : metaDataSource.getSchemas())
builder.put(metaSchema.getName(), new OctopusJdbcSchema(metaSchema, this));
setSubSchemaMap(builder.build());
}
示例7: OctopusTable
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
public OctopusTable(MetaTable metaTable, OctopusSchema schema) {
super(Object[].class);
name = metaTable.getName();
try {
//tableType = Schema.TableType.valueOf(table.getType().name());
tableType = Schema.TableType.TABLE; // FIXME
} catch (IllegalArgumentException e) {
tableType = Schema.TableType.TABLE;
}
RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
RelDataTypeFactory.FieldInfoBuilder fieldInfo = typeFactory.builder();
for (MetaColumn metaColumn : metaTable.getColumns()) {
String columnName = metaColumn.getName();
//int jdbcType = metaColumn.getType().getJdbcType();
int jdbcType = metaColumn.getType(); //FIXME
SqlTypeName typeName = SqlTypeName.getNameForJdbcType(jdbcType);
RelDataType sqlType = typeFactory.createSqlType(typeName);
fieldInfo.add(columnName, sqlType);
}
protoRowType = RelDataTypeImpl.proto(fieldInfo.build());
this.schema = schema;
}
示例8: addDataSource
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
public void addDataSource(OctopusDataSource octopusDataSource) {
writeLock.lock();
try {
// FIXME: all or nothing
addToListMap(dataSourceMap, octopusDataSource.getName(), octopusDataSource);
for (Schema cSchema : octopusDataSource.getSubSchemaMap().values()) {
OctopusSchema schema = (OctopusSchema) cSchema;
addToListMap(schemaMap, schema.getName(), schema);
for (Table cTable : schema.getTableMap().values()) {
OctopusTable table = (OctopusTable) cTable;
addToListMap(tableMap, table.getName(), table);
}
}
rootSchema.add(octopusDataSource.getName(), octopusDataSource);
} finally {
writeLock.unlock();
}
}
示例9: getSchemaFromResultSet
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
private ImmutableMap<String, Schema> getSchemaFromResultSet(ResultSet rs,
ImmutableMap<String, Integer>
dataTypes)
throws SQLException {
if (rs == null || !rs.next()) {
return ImmutableMap.of();
}
ImmutableMap.Builder<String, Schema> schemaBuilder = new ImmutableMap.Builder<>();
while (!rs.isAfterLast()) {
String currentSchema = rs.getString(1);
String schemaKey = currentSchema;
if (!this.isCaseSensitive()) {
schemaKey = currentSchema.toUpperCase();
}
schemaBuilder.put(schemaKey, new JdbcSchema(currentSchema,
rs, this.isCaseSensitive(), dataTypes));
}
return schemaBuilder.build();
}
示例10: getSchemas
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
@Override
public ImmutableMap<String, Schema> getSchemas() throws QuarkException {
Map<String, List<SchemaOrdinal>> schemas;
try {
schemas = getSchemaListDescribed();
} catch (ExecutionException | InterruptedException e) {
LOG.error("Getting Schema metadata for " + this.endpoint
+ " failed. Error: " + e.getMessage(), e);
throw new QuarkException(e);
}
ImmutableMap.Builder<String, Schema> schemaBuilder = new ImmutableMap.Builder<>();
for (String schemaName: schemas.keySet()) {
String schemaKey = schemaName;
if (!this.isCaseSensitive()) {
schemaKey = schemaName.toUpperCase();
}
schemaBuilder.put(schemaKey, new QuboleSchema(schemaKey,
schemas.get(schemaName), this.isCaseSensitive(), this.getDataTypes()));
}
return schemaBuilder.build();
}
示例11: create
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
public Schema create(SchemaPlus parentSchema, String name,
Map<String, Object> operand) {
final String directory = (String) operand.get("directory");
final File base =
(File) operand.get(ModelHandler.ExtraOperand.BASE_DIRECTORY.camelName);
File directoryFile = new File(directory);
if (base != null && !directoryFile.isAbsolute()) {
directoryFile = new File(base, directory);
}
String flavorName = (String) operand.get("flavor");
CsvTable.Flavor flavor;
if (flavorName == null) {
flavor = CsvTable.Flavor.SCANNABLE;
} else {
flavor = CsvTable.Flavor.valueOf(flavorName.toUpperCase(Locale.ROOT));
}
return new CsvSchema(directoryFile, flavor);
}
示例12: testPrepared
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1031">[CALCITE-1031]
* In prepared statement, CsvScannableTable.scan is called twice</a>. To see
* the bug, place a breakpoint in CsvScannableTable.scan, and note that it is
* called twice. It should only be called once. */
@Test public void testPrepared() throws SQLException {
final Properties properties = new Properties();
properties.setProperty("caseSensitive", "true");
try (final Connection connection =
DriverManager.getConnection("jdbc:calcite:", properties)) {
final CalciteConnection calciteConnection = connection.unwrap(
CalciteConnection.class);
final Schema schema =
CsvSchemaFactory.INSTANCE
.create(calciteConnection.getRootSchema(), null,
ImmutableMap.<String, Object>of("directory",
resourcePath("sales"), "flavor", "scannable"));
calciteConnection.getRootSchema().add("TEST", schema);
final String sql = "select * from \"TEST\".\"DEPTS\" where \"NAME\" = ?";
final PreparedStatement statement2 =
calciteConnection.prepareStatement(sql);
statement2.setString(1, "Sales");
final ResultSet resultSet1 = statement2.executeQuery();
Function<ResultSet, Void> expect = expect("DEPTNO=10; NAME=Sales");
expect.apply(resultSet1);
}
}
示例13: create
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
@Override public Schema create(SchemaPlus parentSchema, String name,
Map<String, Object> operand) {
final Map map = (Map) operand;
final ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
try {
final Map<String, Integer> coordinates =
mapper.readValue((String) map.get("coordinates"),
new TypeReference<Map<String, Integer>>() { });
final Map<String, String> userConfig =
mapper.readValue((String) map.get("userConfig"),
new TypeReference<Map<String, String>>() { });
final String index = (String) map.get("index");
return new Elasticsearch2Schema(coordinates, userConfig, index);
} catch (IOException e) {
throw new RuntimeException("Cannot parse values from json", e);
}
}
示例14: create
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
public Schema create(SchemaPlus parentSchema, String name,
Map<String, Object> operand) {
@SuppressWarnings("unchecked") List<Map<String, Object>> tables =
(List) operand.get("tables");
final File baseDirectory =
(File) operand.get(ModelHandler.ExtraOperand.BASE_DIRECTORY.camelName);
File directoryFile = baseDirectory;
final String directory = (String) operand.get("directory");
if (baseDirectory != null && directory != null) {
directoryFile = new File(directory);
if (!directoryFile.isAbsolute()) {
directoryFile = new File(baseDirectory, directory);
}
}
return new FileSchema(parentSchema, name, directoryFile, tables);
}
示例15: create
import org.apache.calcite.schema.Schema; //导入依赖的package包/类
@Override public Schema create(SchemaPlus parentSchema, String name,
Map<String, Object> operand) {
final Map map = (Map) operand;
final ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
try {
final Map<String, Integer> coordinates =
mapper.readValue((String) map.get("coordinates"),
new TypeReference<Map<String, Integer>>() { });
final Map<String, String> userConfig =
mapper.readValue((String) map.get("userConfig"),
new TypeReference<Map<String, String>>() { });
final String index = (String) map.get("index");
return new Elasticsearch5Schema(coordinates, userConfig, index);
} catch (IOException e) {
throw new RuntimeException("Cannot parse values from json", e);
}
}