Java Code Examples for org.apache.calcite.jdbc.CalciteSchema#path()

The following examples show how to use org.apache.calcite.jdbc.CalciteSchema#path() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalcitePrepareImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Executes a prepare action. */
public <R> R perform(CalciteServerStatement statement,
    FrameworkConfig config, Frameworks.BasePrepareAction<R> action) {
  final CalcitePrepare.Context prepareContext =
      statement.createPrepareContext();
  final JavaTypeFactory typeFactory = prepareContext.getTypeFactory();
  final CalciteSchema schema =
      config.getDefaultSchema() != null
          ? CalciteSchema.from(config.getDefaultSchema())
          : prepareContext.getRootSchema();
  CalciteCatalogReader catalogReader =
      new CalciteCatalogReader(schema.root(),
          schema.path(null),
          typeFactory,
          prepareContext.config());
  final RexBuilder rexBuilder = new RexBuilder(typeFactory);
  final RelOptPlanner planner =
      createPlanner(prepareContext,
          config.getContext(),
          config.getCostFactory());
  final RelOptCluster cluster = createCluster(planner, rexBuilder);
  return action.apply(cluster, catalogReader,
      prepareContext.getRootSchema().plus(), statement);
}
 
Example 2
Source File: ModelHandler.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void visit(JsonMaterialization jsonMaterialization) {
  try {
    checkRequiredAttributes(jsonMaterialization, "sql");
    final SchemaPlus schema = currentSchema();
    if (!schema.isMutable()) {
      throw new RuntimeException(
          "Cannot define materialization; parent schema '"
              + currentSchemaName()
              + "' is not a SemiMutableSchema");
    }
    CalciteSchema calciteSchema = CalciteSchema.from(schema);

    final String viewName;
    final boolean existing;
    if (jsonMaterialization.view == null) {
      // If the user did not supply a view name, that means the materialized
      // view is pre-populated. Generate a synthetic view name.
      viewName = "$" + schema.getTableNames().size();
      existing = true;
    } else {
      viewName = jsonMaterialization.view;
      existing = false;
    }
    List<String> viewPath = calciteSchema.path(viewName);
    schema.add(viewName,
        MaterializedViewTable.create(calciteSchema,
            jsonMaterialization.getSql(), jsonMaterialization.viewSchemaPath, viewPath,
            jsonMaterialization.table, existing));
  } catch (Exception e) {
    throw new RuntimeException("Error instantiating " + jsonMaterialization,
        e);
  }
}
 
Example 3
Source File: CalciteCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
private SqlMonikerImpl moniker(CalciteSchema schema, String name,
    SqlMonikerType type) {
  final List<String> path = schema.path(name);
  if (path.size() == 1
      && !schema.root().name.equals("")
      && type == SqlMonikerType.SCHEMA) {
    type = SqlMonikerType.CATALOG;
  }
  return new SqlMonikerImpl(path, type);
}
 
Example 4
Source File: MaterializedViewTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
private MaterializedViewTableMacro(CalciteSchema schema, String viewSql,
    List<String> viewSchemaPath, List<String> viewPath, String suggestedTableName,
    boolean existing) {
  super(schema, viewSql,
      viewSchemaPath != null ? viewSchemaPath : schema.path(null), viewPath,
      Boolean.TRUE);
  this.key = Objects.requireNonNull(
      MaterializationService.instance().defineMaterialization(
          schema, null, viewSql, schemaPath, suggestedTableName, true,
          existing));
}
 
Example 5
Source File: Schemas.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static CalcitePrepare.Context makeContext(
    final CalciteConnectionConfig connectionConfig,
    final JavaTypeFactory typeFactory,
    final DataContext dataContext,
    final CalciteSchema schema,
    final List<String> schemaPath, final List<String> objectPath_) {
  final ImmutableList<String> objectPath =
      objectPath_ == null ? null : ImmutableList.copyOf(objectPath_);
  return new CalcitePrepare.Context() {
    public JavaTypeFactory getTypeFactory() {
      return typeFactory;
    }

    public CalciteSchema getRootSchema() {
      return schema.root();
    }

    public CalciteSchema getMutableRootSchema() {
      return getRootSchema();
    }

    public List<String> getDefaultSchemaPath() {
      // schemaPath is usually null. If specified, it overrides schema
      // as the context within which the SQL is validated.
      if (schemaPath == null) {
        return schema.path(null);
      }
      return schemaPath;
    }

    public List<String> getObjectPath() {
      return objectPath;
    }

    public CalciteConnectionConfig config() {
      return connectionConfig;
    }

    public DataContext getDataContext() {
      return dataContext;
    }

    public RelRunner getRelRunner() {
      throw new UnsupportedOperationException();
    }

    public CalcitePrepare.SparkHandler spark() {
      final boolean enable = config().spark();
      return CalcitePrepare.Dummy.getSparkHandler(enable);
    }
  };
}