本文整理汇总了Java中org.apache.calcite.schema.SchemaPlus类的典型用法代码示例。如果您正苦于以下问题:Java SchemaPlus类的具体用法?Java SchemaPlus怎么用?Java SchemaPlus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SchemaPlus类属于org.apache.calcite.schema包,在下文中一共展示了SchemaPlus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trans
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
private String trans(String sql) throws Exception {
Properties info = new Properties();
info.setProperty("lex", "JAVA");
String jsonFile = SolrSqlTest.class.getClassLoader().getResource("solr.json").toString().replaceAll("file:/", "");
try {
Class.forName("org.apache.calcite.jdbc.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
CalciteConnection connection = (CalciteConnection) DriverManager.getConnection("jdbc:calcite:model="+jsonFile, info);
final SchemaPlus schema = connection.getRootSchema().getSubSchema("solr");
connection.close();
ConfigBuilder builder = Frameworks.newConfigBuilder().defaultSchema(schema).parserConfig(SqlParser.configBuilder().setCaseSensitive(false).build());
FrameworkConfig config = builder.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode sqlNode = planner.parse(sql);
SqlNode node = planner.validate(sqlNode);
RelRoot relRoot = planner.rel(node);
RelNode project = relRoot.project();
RexNode condition = ((Filter) ((Project) project).getInput()).getCondition();
return _trans.translate(condition).toSolrQueryString();
}
示例2: create
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
public static JournalledJdbcSchema create(
SchemaPlus parentSchema,
String name,
Map<String, Object> operand
) {
DataSource dataSource;
try {
dataSource = parseDataSource(operand);
} catch (Exception e) {
throw new IllegalArgumentException("Error while reading dataSource", e);
}
String catalog = (String) operand.get("jdbcCatalog");
String schema = (String) operand.get("jdbcSchema");
Expression expression = null;
if (parentSchema != null) {
expression = Schemas.subSchemaExpression(parentSchema, name, JdbcSchema.class);
}
final SqlDialect dialect = createDialect(dataSource);
final JdbcConvention convention = JdbcConvention.of(dialect, expression, name);
return new JournalledJdbcSchema(dataSource, dialect, convention, catalog, schema, operand);
}
示例3: setDefaultSchemaPath
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
/**
* Update the schema path for the session.
* @param newDefaultSchemaPath New default schema path to set. It could be relative to the current default schema or
* absolute schema.
* @param currentDefaultSchema Current default schema.
* @throws ValidationException If the given default schema path is invalid in current schema tree.
*/
public void setDefaultSchemaPath(String newDefaultSchemaPath, SchemaPlus currentDefaultSchema)
throws ValidationException {
final List<String> newDefaultPathAsList = Lists.newArrayList(newDefaultSchemaPath.split("\\."));
SchemaPlus newDefault;
// First try to find the given schema relative to the current default schema.
newDefault = SchemaUtilites.findSchema(currentDefaultSchema, newDefaultPathAsList);
if (newDefault == null) {
// If we fail to find the schema relative to current default schema, consider the given new default schema path as
// absolute schema path.
newDefault = SchemaUtilites.findSchema(currentDefaultSchema, newDefaultPathAsList);
}
if (newDefault == null) {
SchemaUtilites.throwSchemaNotFoundException(currentDefaultSchema, newDefaultSchemaPath);
}
setProp(SCHEMA, SchemaUtilites.getSchemaPath(newDefault));
}
示例4: getDefaultSchema
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
/**
* Get default schema from current default schema path and given schema tree.
* @param rootSchema
* @return A {@link org.apache.calcite.schema.SchemaPlus} object.
*/
public SchemaPlus getDefaultSchema(SchemaPlus rootSchema) {
final String defaultSchemaPath = getProp(SCHEMA);
if (Strings.isNullOrEmpty(defaultSchemaPath)) {
return null;
}
final SchemaPlus defaultSchema = SchemaUtilites.findSchema(rootSchema, defaultSchemaPath);
if (defaultSchema == null) {
// If the current schema resolves to null, return root schema as the current default schema.
return defaultSchema;
}
return defaultSchema;
}
示例5: findSchema
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
/**
* Search and return schema with given schemaPath. First search in schema tree starting from defaultSchema,
* if not found search starting from rootSchema. Root schema tree is derived from the defaultSchema reference.
*
* @param defaultSchema Reference to the default schema in complete schema tree.
* @param schemaPath Schema path to search.
* @return SchemaPlus object.
*/
public static SchemaPlus findSchema(final SchemaPlus defaultSchema, final List<String> schemaPath) {
if (schemaPath.size() == 0) {
return defaultSchema;
}
SchemaPlus schema;
if ((schema = searchSchemaTree(defaultSchema, schemaPath)) != null) {
return schema;
}
SchemaPlus rootSchema = defaultSchema;
while(rootSchema.getParentSchema() != null) {
rootSchema = rootSchema.getParentSchema();
}
if (rootSchema != defaultSchema &&
(schema = searchSchemaTree(rootSchema, schemaPath)) != null) {
return schema;
}
return null;
}
示例6: getSchemaPathAsList
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
/** Utility method to get the schema path as list for given schema instance. */
public static List<String> getSchemaPathAsList(SchemaPlus schema) {
if (isRootSchema(schema)) {
return Collections.EMPTY_LIST;
}
List<String> path = Lists.newArrayListWithCapacity(5);
while(schema != null) {
final String name = schema.getName();
if (!Strings.isNullOrEmpty(name)) {
path.add(schema.getName());
}
schema = schema.getParentSchema();
}
return Lists.reverse(path);
}
示例7: resolveToMutableDrillSchema
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
/**
* Given reference to default schema in schema tree, search for schema with given <i>schemaPath</i>. Once a schema is
* found resolve it into a mutable <i>AbstractDrillSchema</i> instance. A {@link UserException} is throws when:
* 1. No schema for given <i>schemaPath</i> is found,
* 2. Schema found for given <i>schemaPath</i> is a root schema
* 3. Resolved schema is not a mutable schema.
* @param defaultSchema
* @param schemaPath
* @return
*/
public static AbstractSchema resolveToMutableDrillSchema(final SchemaPlus defaultSchema, List<String> schemaPath) {
final SchemaPlus schema = findSchema(defaultSchema, schemaPath);
if (schema == null) {
throwSchemaNotFoundException(defaultSchema, SCHEMA_PATH_JOINER.join(schemaPath));
}
if (isRootSchema(schema)) {
throw UserException.parseError()
.message("Root schema is immutable. Creating or dropping tables/views is not allowed in root schema." +
"Select a schema using 'USE schema' command.")
.build(logger);
}
final AbstractSchema drillSchema = unwrapAsDrillSchemaInstance(schema);
if (!drillSchema.isMutable()) {
throw UserException.parseError()
.message("Unable to create or drop tables/views. Schema [%s] is immutable.", getSchemaPath(schema))
.build(logger);
}
return drillSchema;
}
示例8: getPlan
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
/**
* Function resolves the schema and invokes the drop method. Raises an exception if the schema is
* immutable.
* @param sqlNode - Table name identifier
* @return - Single row indicating drop succeeded, raise exception otherwise
* @throws ValidationException
* @throws RelConversionException
* @throws IOException
*/
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException {
SqlDropTable dropTableNode = ((SqlDropTable) sqlNode);
SqlIdentifier tableIdentifier = dropTableNode.getTableIdentifier();
SchemaPlus defaultSchema = context.getNewDefaultSchema();
AbstractSchema drillSchema = null;
if (tableIdentifier != null) {
drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, dropTableNode.getSchema());
}
String tableName = ((SqlDropTable) sqlNode).getName();
if (drillSchema == null) {
throw UserException.validationError()
.message("Invalid table_name [%s]", tableName)
.build(logger);
}
drillSchema.dropTable(tableName);
return DirectPlan.createDirectPlan(context, true,
String.format("Table [%s] %s", tableName, "dropped"));
}
示例9: getRootSchema
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
public SchemaPlus getRootSchema() {
if (queryContext == null) {
fail(new UnsupportedOperationException("Schema tree can only be created in root fragment. " +
"This is a non-root fragment."));
return null;
}
final boolean isImpersonationEnabled = isImpersonationEnabled();
// If impersonation is enabled, we want to view the schema as query user and suppress authorization errors. As for
// InfoSchema purpose we want to show tables the user has permissions to list or query. If impersonation is
// disabled view the schema as Drillbit process user and throw authorization errors to client.
SchemaConfig schemaConfig = SchemaConfig
.newBuilder(
isImpersonationEnabled ? queryContext.getQueryUserName() : ImpersonationUtil.getProcessUserName(),
queryContext)
.setIgnoreAuthErrors(isImpersonationEnabled)
.build();
return queryContext.getRootSchema(schemaConfig);
}
示例10: close
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
@Override
public void close() throws Exception {
try {
if (!closed) {
List<AutoCloseable> toClose = Lists.newArrayList();
// TODO(DRILL-1942) the new allocator has this capability built-in, so we can remove bufferManager and
// allocator from the toClose list.
toClose.add(bufferManager);
toClose.add(allocator);
for(SchemaPlus tree : schemaTreesToClose) {
addSchemasToCloseList(tree, toClose);
}
AutoCloseables.close(toClose.toArray(new AutoCloseable[0]));
}
} finally {
closed = true;
}
}
示例11: getColumnList
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
public List<String> getColumnList(final String username, DatasetPath path) {
final SchemaConfig schemaConfig = SchemaConfig.newBuilder(username)
.setProvider(new SchemaInfoProvider() {
private final ViewExpansionContext viewExpansionContext = new ViewExpansionContext(this, schemaProvider, username);
@Override
public ViewExpansionContext getViewExpansionContext() {
return viewExpansionContext;
}
@Override
public OptionValue getOption(String optionKey) {
throw new UnsupportedOperationException();
}
})
.build();
final SchemaPlus schema = schemaProvider.getRootSchema(schemaConfig);
final Table table = path.getTable(schema);
return table.getRowType(new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT)).getFieldNames();
}
示例12: shouldVisitSchema
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
protected boolean shouldVisitSchema(String schemaName, SchemaPlus schema) {
try {
// if the schema path is null or empty (try for root schema)
if (schemaName == null || schemaName.isEmpty()) {
return false;
}
AbstractSchema drillSchema = schema.unwrap(AbstractSchema.class);
if (!drillSchema.showInInformationSchema()) {
return false;
}
Map<String, String> recordValues =
ImmutableMap.of(SHRD_COL_TABLE_SCHEMA, schemaName,
SCHS_COL_SCHEMA_NAME, schemaName);
if (filter != null && filter.evaluate(recordValues) == Result.FALSE) {
// If the filter evaluates to false then we don't need to visit the schema.
// For other two results (TRUE, INCONCLUSIVE) continue to visit the schema.
return false;
}
} catch(ClassCastException e) {
// ignore and return true as this is not a Drill schema
}
return true;
}
示例13: getTable
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
public Table getTable(SchemaPlus rootSchema){
List<FolderName> components = this.getFolderPath();
SchemaPlus schema = rootSchema.getSubSchema(this.getRoot().getName());
if(schema == null){
throw new IllegalStateException(String.format("Failure finding schema path %s in position 0 of path %s", getRoot().getName(), toPathString()));
}
int i = 1;
for(FolderName folder : components){
schema = schema.getSubSchema(folder.getName());
if(schema == null){
throw new IllegalStateException(String.format("Failure finding schema path %s in position %d of path %s", folder.getName(), i, toPathString()));
}
i++;
}
Table table = schema.getTable(getLeaf().getName());
if(table == null){
throw new IllegalStateException(String.format("Failure finding table in path %s. The schema exists but no table in that schema matches %s", toPathString(), getLeaf().getName()));
}
return table;
}
示例14: resolveToMutableSchemaInstance
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
/**
* Given reference to default schema in schema tree, search for schema with given <i>schemaPath</i>. Once a schema is
* found resolve it into a mutable <i>AbstractSchema</i> instance. A {@link UserException} is throws when:
* 1. No schema for given <i>schemaPath</i> is found,
* 2. Schema found for given <i>schemaPath</i> is a root schema
* 3. Resolved schema is not a mutable schema.
* @param defaultSchema
* @param schemaPath
* @return
*/
public static AbstractSchema resolveToMutableSchemaInstance(final SchemaPlus defaultSchema, List<String> schemaPath, boolean isSystemUser, MutationType type) {
final SchemaPlus schema = findSchema(defaultSchema, schemaPath);
if (schema == null) {
throwSchemaNotFoundException(defaultSchema, SCHEMA_PATH_JOINER.join(schemaPath));
}
if (isRootSchema(schema)) {
throw UserException.parseError()
.message("Root schema is immutable. Creating or dropping tables/views is not allowed in root schema " + schema.getName() + ". " +
"Select a schema using 'USE schema' command.")
.build(logger);
}
final AbstractSchema schemaInstance = unwrapAsSchemaInstance(schema);
if(schemaInstance.getMutability().hasMutationCapability(type, isSystemUser)){
return schemaInstance;
}
throw UserException.parseError()
.message("Unable to create or drop tables/views. Schema [%s] is immutable for this user.", getSchemaPath(schema))
.build(logger);
}
示例15: getWriter
import org.apache.calcite.schema.SchemaPlus; //导入依赖的package包/类
private Writer getWriter(OptionManager options, SchemaConfig.SchemaInfoProvider infoProvider) throws IOException{
final String storeTablePath = options.getOption(QUERY_RESULTS_STORE_TABLE.getOptionName()).string_val;
final List<String> storeTable = new StrTokenizer(storeTablePath, '.', ParserConfig.QUOTING.string.charAt(0))
.setIgnoreEmptyTokens(true).getTokenList();
// store query results as the system user
final SchemaPlus systemUserSchema = context.getRootSchema(
SchemaConfig
.newBuilder(SystemUser.SYSTEM_USERNAME)
.setProvider(infoProvider)
.build());
final AbstractSchema schema = SchemaUtilities.resolveToMutableSchemaInstance(systemUserSchema,
Util.skipLast(storeTable), true, MutationType.TABLE);
// Query results are stored in arrow format. If need arises, we can change
// this to a configuration option.
final Map<String, Object> storageOptions = ImmutableMap.<String, Object> of("type",
ArrowFormatPlugin.ARROW_DEFAULT_NAME);
final CreateTableEntry createTableEntry = schema.createNewTable(Util.last(storeTable), WriterOptions.DEFAULT, storageOptions);
return createTableEntry.getWriter(null);
}