Search in sources :

Example 11 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.

the class ModelHandler method visit.

public void visit(JsonCustomTable jsonTable) {
    try {
        checkRequiredAttributes(jsonTable, "name", "factory");
        final SchemaPlus schema = currentMutableSchema("table");
        final TableFactory tableFactory = AvaticaUtils.instantiatePlugin(TableFactory.class, jsonTable.factory);
        final Table table = tableFactory.create(schema, jsonTable.name, operandMap(null, jsonTable.operand), null);
        for (JsonColumn column : jsonTable.columns) {
            column.accept(this);
        }
        schema.add(jsonTable.name, table);
    } catch (Exception e) {
        throw new RuntimeException("Error instantiating " + jsonTable, e);
    }
}
Also used : ViewTable(org.apache.calcite.schema.impl.ViewTable) MaterializedViewTable(org.apache.calcite.schema.impl.MaterializedViewTable) Table(org.apache.calcite.schema.Table) TableFactory(org.apache.calcite.schema.TableFactory) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 12 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.

the class SimpleCalciteSchema method addImplicitTablesBasedOnNullaryFunctionsToBuilder.

protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder(ImmutableSortedMap.Builder<String, Table> builder) {
    ImmutableSortedMap<String, Table> explicitTables = builder.build();
    for (String s : schema.getFunctionNames()) {
        // explicit table wins.
        if (explicitTables.containsKey(s)) {
            continue;
        }
        for (Function function : schema.getFunctions(s)) {
            if (function instanceof TableMacro && function.getParameters().isEmpty()) {
                final Table table = ((TableMacro) function).apply(ImmutableList.of());
                builder.put(s, table);
            }
        }
    }
}
Also used : Function(org.apache.calcite.schema.Function) TableMacro(org.apache.calcite.schema.TableMacro) Table(org.apache.calcite.schema.Table)

Example 13 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.

the class LogicalTableScan method create.

/**
 * Creates a LogicalTableScan.
 *
 * @param cluster Cluster
 * @param relOptTable Table
 */
public static LogicalTableScan create(RelOptCluster cluster, final RelOptTable relOptTable) {
    final Table table = relOptTable.unwrap(Table.class);
    final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {

        public List<RelCollation> get() {
            if (table != null) {
                return table.getStatistic().getCollations();
            }
            return ImmutableList.of();
        }
    });
    return new LogicalTableScan(cluster, traitSet, relOptTable);
}
Also used : Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 14 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.

the class ModifiableViewTable method extend.

/**
 * Extends the underlying table and returns a new view with updated row-type
 * and column-mapping.
 *
 * <p>The type factory is used to perform some scratch calculations, viz the
 * type mapping, but the "real" row-type will be assigned later, when the
 * table has been bound to the statement's type factory. The is important,
 * because adding types to type factories that do not belong to a statement
 * could potentially leak memory.
 *
 * @param extendedColumns Extended fields
 * @param typeFactory Type factory
 */
public final ModifiableViewTable extend(List<RelDataTypeField> extendedColumns, RelDataTypeFactory typeFactory) {
    final ExtensibleTable underlying = unwrap(ExtensibleTable.class);
    assert underlying != null;
    final RelDataTypeFactory.Builder builder = typeFactory.builder();
    final RelDataType rowType = getRowType(typeFactory);
    for (RelDataTypeField column : rowType.getFieldList()) {
        builder.add(column);
    }
    for (RelDataTypeField column : extendedColumns) {
        builder.add(column);
    }
    // The characteristics of the new view.
    final RelDataType newRowType = builder.build();
    final ImmutableIntList newColumnMapping = getNewColumnMapping(underlying, getColumnMapping(), extendedColumns, typeFactory);
    // Extend the underlying table with only the fields that
    // duplicate column names in neither the view nor the base table.
    final List<RelDataTypeField> underlyingColumns = underlying.getRowType(typeFactory).getFieldList();
    final List<RelDataTypeField> columnsOfExtendedBaseTable = RelOptUtil.deduplicateColumns(underlyingColumns, extendedColumns);
    final List<RelDataTypeField> extendColumnsOfBaseTable = columnsOfExtendedBaseTable.subList(underlyingColumns.size(), columnsOfExtendedBaseTable.size());
    final Table extendedTable = underlying.extend(extendColumnsOfBaseTable);
    return extend(extendedTable, RelDataTypeImpl.proto(newRowType), newColumnMapping);
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelOptTable(org.apache.calcite.plan.RelOptTable) Table(org.apache.calcite.schema.Table) ExtensibleTable(org.apache.calcite.schema.ExtensibleTable) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) ExtensibleTable(org.apache.calcite.schema.ExtensibleTable)

Example 15 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project calcite by apache.

the class GeodeSimpleSchema method getTableMap.

@Override
protected Map<String, Table> getTableMap() {
    if (tableMap == null) {
        final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
        for (String regionName : regionNames) {
            Region region = GeodeUtils.createRegionProxy(clientCache, regionName);
            // TODO: What if the region is empty
            Object regionEntry = region.get(region.keySetOnServer().iterator().next());
            Table table = new GeodeSimpleScannableTable(regionName, createRelDataType(regionEntry), clientCache);
            builder.put(regionName, table);
        }
        tableMap = builder.build();
    }
    return tableMap;
}
Also used : Table(org.apache.calcite.schema.Table) Region(org.apache.geode.cache.Region) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Table (org.apache.calcite.schema.Table)104 Test (org.junit.Test)43 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)38 RelOptTable (org.apache.calcite.plan.RelOptTable)33 RelDataType (org.apache.calcite.rel.type.RelDataType)22 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)22 SchemaPlus (org.apache.calcite.schema.SchemaPlus)20 ArrayList (java.util.ArrayList)19 List (java.util.List)19 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)17 ScannableTable (org.apache.calcite.schema.ScannableTable)17 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)16 FilterableTable (org.apache.calcite.schema.FilterableTable)15 AbstractTable (org.apache.calcite.schema.impl.AbstractTable)15 ResultSet (java.sql.ResultSet)14 Schema (org.apache.beam.sdk.schemas.Schema)14 Row (org.apache.beam.sdk.values.Row)14 StreamableTable (org.apache.calcite.schema.StreamableTable)14 CalciteConnection (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection)13 Map (java.util.Map)12