Search in sources :

Example 96 with Table

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

the class EnumerableTableScanRule method convert.

@Override
public RelNode convert(RelNode rel) {
    LogicalTableScan scan = (LogicalTableScan) rel;
    final RelOptTable relOptTable = scan.getTable();
    final Table table = relOptTable.unwrap(Table.class);
    if (!EnumerableTableScan.canHandle(table)) {
        return null;
    }
    final Expression expression = relOptTable.getExpression(Object.class);
    if (expression == null) {
        return null;
    }
    return EnumerableTableScan.create(scan.getCluster(), relOptTable);
}
Also used : Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) Expression(org.apache.calcite.linq4j.tree.Expression) RelOptTable(org.apache.calcite.plan.RelOptTable) LogicalTableScan(org.apache.calcite.rel.logical.LogicalTableScan)

Example 97 with Table

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

the class CalciteSchema method getTablesBasedOnNullaryFunctions.

/**
 * Returns tables derived from explicit and implicit functions
 * that take zero parameters.
 */
public final NavigableMap<String, Table> getTablesBasedOnNullaryFunctions() {
    ImmutableSortedMap.Builder<String, Table> builder = new ImmutableSortedMap.Builder<>(NameSet.COMPARATOR);
    for (Map.Entry<String, FunctionEntry> entry : nullaryFunctionMap.map().entrySet()) {
        final Function function = entry.getValue().getFunction();
        if (function instanceof TableMacro) {
            assert function.getParameters().isEmpty();
            final Table table = ((TableMacro) function).apply(ImmutableList.of());
            builder.put(entry.getKey(), table);
        }
    }
    // add tables derived from implicit functions
    addImplicitTablesBasedOnNullaryFunctionsToBuilder(builder);
    return Compatible.INSTANCE.navigableMap(builder.build());
}
Also used : Function(org.apache.calcite.schema.Function) TableMacro(org.apache.calcite.schema.TableMacro) MaterializedViewTable(org.apache.calcite.schema.impl.MaterializedViewTable) Table(org.apache.calcite.schema.Table) StarTable(org.apache.calcite.schema.impl.StarTable) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) NameMap(org.apache.calcite.util.NameMap) NavigableMap(java.util.NavigableMap)

Example 98 with Table

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

the class CachingCalciteSchema method getImplicitTable.

protected TableEntry getImplicitTable(String tableName, boolean caseSensitive) {
    final long now = System.currentTimeMillis();
    final NameSet implicitTableNames = implicitTableCache.get(now);
    for (String tableName2 : implicitTableNames.range(tableName, caseSensitive)) {
        final Table table = schema.getTable(tableName2);
        if (table != null) {
            return tableEntry(tableName2, table);
        }
    }
    return null;
}
Also used : Table(org.apache.calcite.schema.Table) NameSet(org.apache.calcite.util.NameSet)

Example 99 with Table

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

the class CachingCalciteSchema method addImplicitTablesBasedOnNullaryFunctionsToBuilder.

protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder(ImmutableSortedMap.Builder<String, Table> builder) {
    ImmutableSortedMap<String, Table> explicitTables = builder.build();
    final long now = System.currentTimeMillis();
    final NameSet set = implicitFunctionCache.get(now);
    for (String s : set.iterable()) {
        // 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) NameSet(org.apache.calcite.util.NameSet)

Example 100 with Table

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

the class CachingCalciteSchema method getImplicitTableBasedOnNullaryFunction.

protected TableEntry getImplicitTableBasedOnNullaryFunction(String tableName, boolean caseSensitive) {
    final long now = System.currentTimeMillis();
    final NameSet set = implicitFunctionCache.get(now);
    for (String s : set.range(tableName, caseSensitive)) {
        for (Function function : schema.getFunctions(s)) {
            if (function instanceof TableMacro && function.getParameters().isEmpty()) {
                final Table table = ((TableMacro) function).apply(ImmutableList.of());
                return tableEntry(tableName, table);
            }
        }
    }
    return null;
}
Also used : Function(org.apache.calcite.schema.Function) TableMacro(org.apache.calcite.schema.TableMacro) Table(org.apache.calcite.schema.Table) NameSet(org.apache.calcite.util.NameSet)

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