Search in sources :

Example 1 with Lattice

use of org.apache.calcite.materialize.Lattice in project calcite by apache.

the class ModelHandler method visit.

public void visit(JsonLattice jsonLattice) {
    try {
        checkRequiredAttributes(jsonLattice, "name", "sql");
        final SchemaPlus schema = currentSchema();
        if (!schema.isMutable()) {
            throw new RuntimeException("Cannot define lattice; parent schema '" + currentSchemaName() + "' is not a SemiMutableSchema");
        }
        CalciteSchema calciteSchema = CalciteSchema.from(schema);
        Lattice.Builder latticeBuilder = Lattice.builder(calciteSchema, jsonLattice.getSql()).auto(jsonLattice.auto).algorithm(jsonLattice.algorithm);
        if (jsonLattice.rowCountEstimate != null) {
            latticeBuilder.rowCountEstimate(jsonLattice.rowCountEstimate);
        }
        if (jsonLattice.statisticProvider != null) {
            latticeBuilder.statisticProvider(jsonLattice.statisticProvider);
        }
        populateLattice(jsonLattice, latticeBuilder);
        schema.add(jsonLattice.name, latticeBuilder.build());
    } catch (Exception e) {
        throw new RuntimeException("Error instantiating " + jsonLattice, e);
    }
}
Also used : CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Lattice(org.apache.calcite.materialize.Lattice) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)1 Lattice (org.apache.calcite.materialize.Lattice)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1