Skip to content

How to instantiate a Morel context from an existing Calcite rootSchema? #145

@GavinRay97

Description

@GavinRay97

Heya Julian,

I'm working on a web playground for Calcite, that I plan on hosting for free so that people can experiment with it. It'll essentially be a web REPL with some pre-loaded data, and the ability to render visualizations of query plans + schema diagrams.

I figured that while I'm at it, it could be nice to add a second input form, which takes Morel expressions, and is bound to the same Calcite context/rootSchema.

Having a bit of difficulty figuring out how to do this though.

I have a singleton object that holds the master schema like below -- I think I need to pass this as a foreignValue to Morel or similar?

// Holds the master schema that contains all datasource schemas and their sub-schemas
object CalciteSchemaService {

    val connection: CalciteConnection = initCalciteConnection()
    val rootSchema: SchemaPlus = connection.rootSchema

    val frameworkConfig: FrameworkConfig = Frameworks.newConfigBuilder()
        .defaultSchema(connection.rootSchema)
        .parserConfig(SqlParser.config().withCaseSensitive(false))
        .build()

    val relBuilder: RelBuilder = RelBuilder.create(frameworkConfig)

    // <SNIPPED>
}

I see this but it's protected:

protected Calcite() {
rootSchema = CalciteSchema.createRootSchema(false).plus();
relBuilder = RelBuilder.create(Frameworks.newConfigBuilder()
.defaultSchema(rootSchema)
.build());
typeFactory = (JavaTypeFactory) relBuilder.getTypeFactory();
dataContext = new EmptyDataContext(typeFactory, rootSchema);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions