org.apache.calcite.schema.Table - java examples

Here are the examples of the java api org.apache.calcite.schema.Table taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

123 Examples 7

19 View Complete Implementation : SimpleCalciteSchema.java
Copyright Apache License 2.0
Author : bitnine-oss
protected TableEntry getImplicitTable(String tableName, boolean caseSensitive) {
    // Check implicit tables.
    Table table = getSchema().getTable(tableName);
    if (table != null) {
        return tableEntry(tableName, table);
    }
    return null;
}

19 View Complete Implementation : JdbcTableUtils.java
Copyright Apache License 2.0
Author : tzolov
public static List<String> getQualifiedName(RelOptTable sibling, Table table) {
    if (!(table instanceof JdbcTable)) {
        throw new UnsupportedOperationException();
    }
    List<String> name = new ArrayList<>();
    if (sibling != null) {
        name.addAll(sibling.getQualifiedName());
        name.remove(name.size() - 1);
    }
    name.add(getTableName((JdbcTable) table));
    return name;
}

19 View Complete Implementation : DirPrunedEnumerableTableScan.java
Copyright Apache License 2.0
Author : lealone
@Override
public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
    final Table tbl = this.table.unwrap(Table.clreplaced);
    Clreplaced elementType = EnumerableTableScan.deduceElementType(tbl);
    return new DirPrunedEnumerableTableScan(getCluster(), traitSet, table, elementType, digestFromSelection);
}

19 View Complete Implementation : InfoSchemaRecordGenerator.java
Copyright Apache License 2.0
Author : lealone
/**
 * Visit the given table.
 *
 * @param schemaName Name of the schema where the table is present
 * @param tableName Name of the table
 * @param table Table object
 * @return Whether to continue exploring the contents of the table or not. Contents are fields within the table.
 */
public boolean visitTable(String schemaName, String tableName, Table table) {
    return true;
}

19 View Complete Implementation : CapitalizingJdbcSchema.java
Copyright Apache License 2.0
Author : apache
@Override
public Table getTable(String name) {
    if (isCatalogSchema()) {
        logger.warn("Failed attempt to find table '{}' in catalog schema '{}'", name, getName());
        return null;
    }
    Table table = inner.getTable(name);
    if (table == null && !areTableNamesCaseSensitive()) {
        // Oracle and H2 changes unquoted identifiers to uppercase.
        table = inner.getTable(name.toUpperCase());
        if (table == null) {
            // Postgres changes unquoted identifiers to lowercase.
            table = inner.getTable(name.toLowerCase());
        }
    }
    return table;
}

19 View Complete Implementation : CachingCalciteSchema.java
Copyright Apache License 2.0
Author : bitnine-oss
protected TableEntry getImplicitTable(String tableName, boolean caseSensitive) {
    if (caseSensitive) {
        // Check implicit tables, case-sensitive.
        final long now = System.currentTimeMillis();
        if (implicitTableCache.get(now).contains(tableName)) {
            final Table table = getSchema().getTable(tableName);
            if (table != null) {
                return tableEntry(tableName, table);
            }
        }
    } else {
        // Check implicit tables, case-insensitive.
        final long now = System.currentTimeMillis();
        final NavigableSet<String> implicitTableNames = implicitTableCache.get(now);
        final String tableName2 = implicitTableNames.floor(tableName);
        if (tableName2 != null) {
            final Table table = getSchema().getTable(tableName2);
            if (table != null) {
                return tableEntry(tableName2, table);
            }
        }
    }
    return null;
}

19 View Complete Implementation : CalciteCatalogReader.java
Copyright Apache License 2.0
Author : apache
public Prepare.PreparingTable getTable(final List<String> names) {
    // First look in the default schema, if any.
    // If not found, look in the root schema.
    CalciteSchema.TableEntry entry = SqlValidatorUtil.getTableEntry(this, names);
    if (entry != null) {
        final Table table = entry.getTable();
        if (table instanceof Wrapper) {
            final Prepare.PreparingTable relOptTable = ((Wrapper) table).unwrap(Prepare.PreparingTable.clreplaced);
            if (relOptTable != null) {
                return relOptTable;
            }
        }
        return RelOptTableImpl.create(this, table.getRowType(typeFactory), entry, null);
    }
    return null;
}

19 View Complete Implementation : CalciteSchema.java
Copyright Apache License 2.0
Author : bitnine-oss
/**
 * Creates a TableEntryImpl with no SQLs.
 */
public final TableEntryImpl tableEntry(String tableName, Table table) {
    return new TableEntryImpl(this, tableName, table, ImmutableList.<String>of());
}

19 View Complete Implementation : PackageSchema.java
Copyright Apache License 2.0
Author : vlsi
private void addClreplaced(String name, Table table) {
    if (!clreplacedes.containsKey(name)) {
        clreplacedes.put(name, table);
    }
}

19 View Complete Implementation : RelOptTableImpl.java
Copyright Apache License 2.0
Author : apache
@Override
protected RelOptTable extend(Table extendedTable) {
    final RelDataType extendedRowType = extendedTable.getRowType(getRelOptSchema().getTypeFactory());
    return new RelOptTableImpl(getRelOptSchema(), extendedRowType, getQualifiedName(), extendedTable, expressionFunction, getRowCount());
}

19 View Complete Implementation : RelOptTableImpl.java
Copyright Apache License 2.0
Author : apache
private static Function<Clreplaced, Expression> getClreplacedExpressionFunction(CalciteSchema.TableEntry tableEntry, Table table) {
    return getClreplacedExpressionFunction(tableEntry.schema.plus(), tableEntry.name, table);
}

19 View Complete Implementation : UserSession.java
Copyright Apache License 2.0
Author : apache
/**
 * Checks if preplaceded table is temporary, table name is case-insensitive.
 * Before looking for table checks if preplaceded schema is temporary and returns false if not
 * since temporary tables are allowed to be created in temporary workspace only.
 * If preplaceded workspace is temporary, looks for temporary table.
 * First checks if table name is among temporary tables, if not returns false.
 * If temporary table named was resolved, checks that temporary table exists on disk,
 * to ensure that temporary table actually exists and resolved table name is not orphan
 * (for example, in result of unsuccessful temporary table creation).
 *
 * @param drillSchema table schema
 * @param config drill config
 * @param tableName original table name
 * @return true if temporary table exists in schema, false otherwise
 */
public boolean isTemporaryTable(AbstractSchema drillSchema, DrillConfig config, String tableName) {
    if (drillSchema == null || !SchemaUtilites.isTemporaryWorkspace(drillSchema.getFullSchemaName(), config)) {
        return false;
    }
    String temporaryTableName = resolveTemporaryTableName(tableName);
    if (temporaryTableName != null) {
        Table temporaryTable = SqlHandlerUtil.getTableFromSchema(drillSchema, temporaryTableName);
        if (temporaryTable != null && temporaryTable.getJdbcTableType() == Schema.TableType.TABLE) {
            return true;
        }
    }
    return false;
}

19 View Complete Implementation : TableNamespace.java
Copyright Apache License 2.0
Author : apache
/**
 * Gets the data-type of all columns in a table (for a view table: including
 * columns of the underlying table)
 */
private RelDataType getBaseRowType() {
    final Table schemaTable = table.unwrap(Table.clreplaced);
    if (schemaTable instanceof ModifiableViewTable) {
        final Table underlying = ((ModifiableViewTable) schemaTable).unwrap(Table.clreplaced);
        replacedert underlying != null;
        return underlying.getRowType(validator.typeFactory);
    }
    return schemaTable.getRowType(validator.typeFactory);
}

19 View Complete Implementation : RelOptTableImpl.java
Copyright Apache License 2.0
Author : apache
public static RelOptTableImpl create(RelOptSchema schema, RelDataType rowType, Table table, Path path) {
    final SchemaPlus schemaPlus = MySchemaPlus.create(path);
    return new RelOptTableImpl(schema, rowType, Pair.left(path), table, getClreplacedExpressionFunction(schemaPlus, Util.last(path).left, table), table.getStatistic().getRowCount());
}

19 View Complete Implementation : CalciteMetaImpl.java
Copyright Apache License 2.0
Author : apache
Enumerable<MetaTable> tables(final MetaSchema schema_) {
    final CalciteMetaSchema schema = (CalciteMetaSchema) schema_;
    return Linq4j.asEnumerable(schema.calciteSchema.getTableNames()).select((Function1<String, MetaTable>) name -> {
        final Table table = schema.calciteSchema.getTable(name, true).getTable();
        return new CalciteMetaTable(table, schema.tableCatalog, schema.tableSchem, name);
    }).concat(Linq4j.asEnumerable(schema.calciteSchema.getTablesBasedOnNullaryFunctions().entrySet()).select(pair -> {
        final Table table = pair.getValue();
        return new CalciteMetaTable(table, schema.tableCatalog, schema.tableSchem, pair.getKey());
    }));
}

19 View Complete Implementation : RelOptTableImpl.java
Copyright Apache License 2.0
Author : apache
public static RelOptTableImpl create(RelOptSchema schema, RelDataType rowType, final CalciteSchema.TableEntry tableEntry, Double rowCount) {
    final Table table = tableEntry.getTable();
    return new RelOptTableImpl(schema, rowType, tableEntry.path(), table, getClreplacedExpressionFunction(tableEntry, table), rowCount);
}

19 View Complete Implementation : CalciteSchema.java
Copyright Apache License 2.0
Author : bitnine-oss
/**
 * Defines a table within this schema.
 */
public final TableEntry add(String tableName, Table table, ImmutableList<String> sqls) {
    final TableEntryImpl entry = new TableEntryImpl(this, tableName, table, sqls);
    tableMap.put(tableName, entry);
    return entry;
}

19 View Complete Implementation : StarTable.java
Copyright Apache License 2.0
Author : apache
/**
 * Returns the column offset of the first column of {@code table} in this
 * star table's output row type.
 *
 * @param table Table
 * @return Column offset
 * @throws IllegalArgumentException if table is not in this star
 */
public int columnOffset(Table table) {
    int n = 0;
    for (Pair<Table, Integer> pair : Pair.zip(tables, fieldCounts)) {
        if (pair.left == table) {
            return n;
        }
        n += pair.right;
    }
    throw new IllegalArgumentException("star table " + this + " does not contain table " + table);
}

19 View Complete Implementation : CalciteSchema.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a TableEntryImpl with no SQLs.
 */
protected TableEntryImpl tableEntry(String name, Table table) {
    return new TableEntryImpl(this, name, table, ImmutableList.of());
}

19 View Complete Implementation : StarTable.java
Copyright Apache License 2.0
Author : apache
public StarTable add(Table table) {
    return of(lattice, ImmutableList.<Table>builder().addAll(tables).add(table).build());
}

19 View Complete Implementation : EnumerableTableScan.java
Copyright Apache License 2.0
Author : lealone
/**
 * Returns whether EnumerableTableScan can generate code to handle a
 * particular variant of the Table SPI.
 */
public static boolean canHandle(Table table) {
    // FilterableTable and ProjectableFilterableTable cannot be handled in
    // enumerable convention because they might reject filters and those filters
    // would need to be handled dynamically.
    return table instanceof QueryableTable || table instanceof ScannableTable;
}

19 View Complete Implementation : RelOptTableImpl.java
Copyright Apache License 2.0
Author : apache
public static RelOptTableImpl create(RelOptSchema schema, RelDataType rowType, Table table, ImmutableList<String> names) {
    replacedert table instanceof TranslatableTable || table instanceof ScannableTable || table instanceof ModifiableTable;
    return new RelOptTableImpl(schema, rowType, names, table, null, null);
}

19 View Complete Implementation : JdbcRelBuilder.java
Copyright Apache License 2.0
Author : tzolov
// Table MUST be a JdbcTable (cannot be type-safe since JdbcTable is package-private)
public JdbcRelBuilder scanJdbc(Table table, List<String> qualifiedName) {
    push(JdbcTableUtils.toRel(cluster, relOptSchema, table, qualifiedName));
    return this;
}

19 View Complete Implementation : SimpleCalciteSchema.java
Copyright Apache License 2.0
Author : apache
protected TableEntry getImplicitTable(String tableName, boolean caseSensitive) {
    // Check implicit tables.
    Table table = schema.getTable(tableName);
    if (table != null) {
        return tableEntry(tableName, table);
    }
    return null;
}

19 View Complete Implementation : FlinkPreparingTableBase.java
Copyright Apache License 2.0
Author : apache
@Override
protected RelOptTable extend(Table extendedTable) {
    throw new RuntimeException("Extending column not supported");
}

18 View Complete Implementation : TableFunctionImpl.java
Copyright Apache License 2.0
Author : apache
public Type getElementType(List<Object> arguments) {
    final Table table = apply(arguments);
    if (table instanceof QueryableTable) {
        QueryableTable queryableTable = (QueryableTable) table;
        return queryableTable.getElementType();
    } else if (table instanceof ScannableTable) {
        return Object[].clreplaced;
    }
    throw new replacedertionError("Invalid table clreplaced: " + table + " " + table.getClreplaced());
}

18 View Complete Implementation : ModifiableViewTable.java
Copyright Apache License 2.0
Author : apache
protected ModifiableViewTable extend(Table extendedTable, RelProtoDataType protoRowType, ImmutableIntList newColumnMapping) {
    return new ModifiableViewTable(getElementType(), protoRowType, getViewSql(), getSchemaPath(), getViewPath(), extendedTable, getTablePath(), constraint, newColumnMapping);
}

18 View Complete Implementation : RelToSqlConverterStructsTest.java
Copyright Apache License 2.0
Author : apache
/**
 * Tests for {@link RelToSqlConverter} on a schema that has nested structures of multiple
 * levels.
 */
public clreplaced RelToSqlConverterStructsTest {

    private static final Schema SCHEMA = new Schema() {

        @Override
        public Table getTable(String name) {
            return TABLE;
        }

        @Override
        public Set<String> getTableNames() {
            return ImmutableSet.of("myTable");
        }

        @Override
        public RelProtoDataType getType(String name) {
            return null;
        }

        @Override
        public Set<String> getTypeNames() {
            return ImmutableSet.of();
        }

        @Override
        public Collection<Function> getFunctions(String name) {
            return null;
        }

        @Override
        public Set<String> getFunctionNames() {
            return ImmutableSet.of();
        }

        @Override
        public Schema getSubSchema(String name) {
            return null;
        }

        @Override
        public Set<String> getSubSchemaNames() {
            return ImmutableSet.of();
        }

        @Override
        public Expression getExpression(SchemaPlus parentSchema, String name) {
            return null;
        }

        @Override
        public boolean isMutable() {
            return false;
        }

        @Override
        public Schema snapshot(SchemaVersion version) {
            return null;
        }
    };

    private static final Table TABLE = new Table() {

        /**
         * Table schema is as following:
         *  myTable(
         *          a: BIGINT,
         *          n1: STRUCT<
         *                n11: STRUCT<b: BIGINT>,
         *                n12: STRUCT<c: BIGINT>
         *              >,
         *          n2: STRUCT<d: BIGINT>,
         *          e: BIGINT
         *  )
         */
        @Override
        public RelDataType getRowType(RelDataTypeFactory tf) {
            RelDataType bigint = tf.createSqlType(SqlTypeName.BIGINT);
            RelDataType n1Type = tf.createStructType(ImmutableList.of(tf.createStructType(ImmutableList.of(bigint), ImmutableList.of("b")), tf.createStructType(ImmutableList.of(bigint), ImmutableList.of("c"))), ImmutableList.of("n11", "n12"));
            RelDataType n2Type = tf.createStructType(ImmutableList.of(bigint), ImmutableList.of("d"));
            return tf.createStructType(ImmutableList.of(bigint, n1Type, n2Type, bigint), ImmutableList.of("a", "n1", "n2", "e"));
        }

        @Override
        public Statistic getStatistic() {
            return STATS;
        }

        @Override
        public Schema.TableType getJdbcTableType() {
            return null;
        }

        @Override
        public boolean isRolledUp(String column) {
            return false;
        }

        @Override
        public boolean rolledUpColumnValidInsideAgg(String column, SqlCall call, SqlNode parent, CalciteConnectionConfig config) {
            return false;
        }
    };

    private static final Statistic STATS = new Statistic() {

        @Override
        public Double getRowCount() {
            return 0D;
        }

        @Override
        public boolean isKey(ImmutableBitSet columns) {
            return false;
        }

        @Override
        public List<ImmutableBitSet> getKeys() {
            return ImmutableList.of();
        }

        @Override
        public List<RelReferentialConstraint> getReferentialConstraints() {
            return ImmutableList.of();
        }

        @Override
        public List<RelCollation> getCollations() {
            return ImmutableList.of();
        }

        @Override
        public RelDistribution getDistribution() {
            return null;
        }
    };

    private static final SchemaPlus ROOT_SCHEMA = CalciteSchema.createRootSchema(false).add("myDb", SCHEMA).plus();

    private RelToSqlConverterTest.Sql sql(String sql) {
        return new RelToSqlConverterTest.Sql(ROOT_SCHEMA, sql, CalciteSqlDialect.DEFAULT, SqlParser.Config.DEFAULT, RelToSqlConverterTest.DEFAULT_REL_CONFIG, ImmutableList.of());
    }

    @Test
    public void testNestedSchemaSelectStar() {
        String query = "SELECT * FROM \"myTable\"";
        String expected = "SELECT \"a\", " + "ROW(ROW(\"n1\".\"n11\".\"b\"), ROW(\"n1\".\"n12\".\"c\")) AS \"n1\", " + "ROW(\"n2\".\"d\") AS \"n2\", " + "\"e\"\n" + "FROM \"myDb\".\"myTable\"";
        sql(query).ok(expected);
    }

    @Test
    public void testNestedSchemaRootColumns() {
        String query = "SELECT \"a\", \"e\" FROM \"myTable\"";
        String expected = "SELECT \"a\", " + "\"e\"\n" + "FROM \"myDb\".\"myTable\"";
        sql(query).ok(expected);
    }

    @Test
    public void testNestedSchemaNestedColumns() {
        String query = "SELECT \"a\", \"e\", " + "\"myTable\".\"n1\".\"n11\".\"b\", " + "\"myTable\".\"n2\".\"d\" " + "FROM \"myTable\"";
        String expected = "SELECT \"a\", " + "\"e\", " + "\"n1\".\"n11\".\"b\", " + "\"n2\".\"d\"\n" + "FROM \"myDb\".\"myTable\"";
        sql(query).ok(expected);
    }
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-3405">[CALCITE-3405]
 * Prune columns for ProjectableFilterable when project is not simple mapping</a>.
 */
@Test
public void testPushNonSimpleMappingProject() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, true);
    final String explain = "PLAN=" + "EnumerableCalc(expr#0..1=[{inputs}], expr#2=[+($t1, $t1)], expr#3=[3]," + " proj#0..1=[{exprs}], k0=[$t0], $f3=[$t2], $f4=[$t3])\n" + "  EnumerableInterpreter\n" + "    BindableTableScan(table=[[s, beatles]], projects=[[2, 0]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query("select \"k\", \"i\", \"k\", \"i\"+\"i\" \"ii\", 3 from \"s\".\"beatles\"").explainContains(explain).returnsUnordered("k=1940; i=4; k=1940; ii=8; EXPR$3=3", "k=1940; i=5; k=1940; ii=10; EXPR$3=3", "k=1942; i=4; k=1942; ii=8; EXPR$3=3", "k=1943; i=6; k=1943; ii=12; EXPR$3=3");
    replacedertThat(buf.toString(), is("returnCount=4, projects=[2, 0]"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
@Test
public void testPFPushDownProjectFilterAggregateNested() {
    final StringBuilder buf = new StringBuilder();
    final String sql = "select \"k\", count(*) as c\n" + "from (\n" + "  select \"k\", \"i\" from \"s\".\"beatles\" group by \"k\", \"i\") t\n" + "where \"k\" = 1940\n" + "group by \"k\"";
    final Table table = new BeatlesProjectableFilterableTable(buf, false);
    final String explain = "PLAN=" + "EnumerableAggregate(group=[{1}], C=[COUNT()])\n" + "  EnumerableAggregate(group=[{0, 1}])\n" + "    EnumerableInterpreter\n" + "      BindableTableScan(table=[[s, beatles]], filters=[[=($2, 1940)]], projects=[[0, 2]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query(sql).explainContains(explain).returnsUnordered("k=1940; C=2");
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * A filter and project on a
 * {@link org.apache.calcite.schema.ProjectableFilterableTable}. The table
 * refuses to execute the filter, so Calcite should add a pull up and
 * transform the filter (projecting the column needed by the filter).
 */
@Test
public void testPFTableRefusesFilterCooperative() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, false);
    final String explain = "PLAN=EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles2]], filters=[[=($0, 4)]], projects=[[2]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles2", table))).query("select \"k\" from \"s\".\"beatles2\" where \"i\" = 4").explainContains(explain).returnsUnordered("k=1940", "k=1942");
    replacedertThat(buf.toString(), is("returnCount=4, projects=[2, 0]"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-458">[CALCITE-458]
 * ArrayIndexOutOfBoundsException when using just a single column in
 * interpreter</a>.
 */
@Test
public void testPFTableRefusesFilterSingleColumn() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, false);
    final String explain = "PLAN=" + "EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles2]], filters=[[>($2, 1941)]], projects=[[2]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles2", table))).query("select \"k\" from \"s\".\"beatles2\" where \"k\" > 1941").explainContains(explain).returnsUnordered("k=1942", "k=1943");
    replacedertThat(buf.toString(), is("returnCount=4, projects=[2]"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
@Test
public void testPFPushDownProjectFilterAggregateGroup() {
    final String sql = "select \"i\", count(*) as c\n" + "from \"s\".\"beatles\"\n" + "where \"k\" > 1900\n" + "group by \"i\"";
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, false);
    final String explain = "PLAN=" + "EnumerableAggregate(group=[{0}], C=[COUNT()])\n" + "  EnumerableInterpreter\n" + "    BindableTableScan(table=[[s, beatles]], filters=[[>($2, 1900)]], " + "projects=[[0]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query(sql).explainContains(explain).returnsUnordered("i=4; C=2", "i=5; C=1", "i=6; C=1");
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * A filter on a {@link org.apache.calcite.schema.ProjectableFilterableTable}
 * with two columns, and a project in the query. (Cooperative)
 */
@Test
public void testProjectableFilterableWithProjectAndFilter() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, true);
    final String explain = "PLAN=" + "EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles]], filters=[[=($0, 4)]], projects=[[2, 1]]";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query("select \"k\",\"j\" from \"s\".\"beatles\" where \"i\" = 4").explainContains(explain).returnsUnordered("k=1940; j=John", "k=1942; j=Paul");
    replacedertThat(buf.toString(), is("returnCount=2, filter=4, projects=[2, 1]"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
@Test
public void testProjectableFilterableNonCooperative() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, false);
    final String explain = "PLAN=" + "EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles2]], filters=[[=($0, 4)]], projects=[[1]]";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles2", table))).query("select \"j\" from \"s\".\"beatles2\" where \"i\" = 4").explainContains(explain).returnsUnordered("j=John", "j=Paul");
    replacedertThat(buf.toString(), is("returnCount=4, projects=[1, 0]"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * A filter on a {@link FilterableTable} with two columns (noncooperative).
 */
@Test
public void testFilterableTableNonCooperative() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesFilterableTable(buf, false);
    final String explain = "PLAN=" + "EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles2]], filters=[[=($0, 4)]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles2", table))).query("select * from \"s\".\"beatles2\" where \"i\" = 4").explainContains(explain).returnsUnordered("i=4; j=John; k=1940", "i=4; j=Paul; k=1942");
    replacedertThat(buf.toString(), is("returnCount=4"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * A filter on a {@link org.apache.calcite.schema.ProjectableFilterableTable}
 * with two columns, and a project in the query (NonCooperative).
 */
@Test
public void testProjectableFilterableWithProjectFilterNonCooperative() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, false);
    final String explain = "PLAN=" + "EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles]], filters=[[>($2, 1941)]], " + "projects=[[0, 2]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query("select \"i\",\"k\" from \"s\".\"beatles\" where \"k\" > 1941").explainContains(explain).returnsUnordered("i=4; k=1942", "i=6; k=1943");
    replacedertThat(buf.toString(), is("returnCount=4, projects=[0, 2]"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * A filter on a {@link FilterableTable} with two columns (cooperative).
 */
@Test
public void testFilterableTableCooperative() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesFilterableTable(buf, true);
    final String explain = "PLAN=" + "EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles]], filters=[[=($0, 4)]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query("select * from \"s\".\"beatles\" where \"i\" = 4").explainContains(explain).returnsUnordered("i=4; j=John; k=1940", "i=4; j=Paul; k=1942");
    // Only 2 rows came out of the table. If the value is 4, it means that the
    // planner did not preplaced the filter down.
    replacedertThat(buf.toString(), is("returnCount=2, filter=4"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-3405">[CALCITE-3405]
 * Prune columns for ProjectableFilterable when project is not simple mapping</a>.
 */
@Test
public void testPushSimpleMappingProject() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, true);
    // Note that no redundant Project on EnumerableInterpreter
    final String explain = "PLAN=" + "EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles]], projects=[[2, 0]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query("select \"k\", \"i\" from \"s\".\"beatles\"").explainContains(explain).returnsUnordered("k=1940; i=4", "k=1940; i=5", "k=1942; i=4", "k=1943; i=6");
    replacedertThat(buf.toString(), is("returnCount=4, projects=[2, 0]"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
/**
 * A filter on a {@link org.apache.calcite.schema.ProjectableFilterableTable}
 * with two columns (cooperative).
 */
@Test
public void testProjectableFilterableCooperative() throws Exception {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, true);
    final String explain = "PLAN=" + "EnumerableInterpreter\n" + "  BindableTableScan(table=[[s, beatles]], filters=[[=($0, 4)]], projects=[[1]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query("select \"j\" from \"s\".\"beatles\" where \"i\" = 4").explainContains(explain).returnsUnordered("j=John", "j=Paul");
    // Only 2 rows came out of the table. If the value is 4, it means that the
    // planner did not preplaced the filter down.
    replacedertThat(buf.toString(), is("returnCount=2, filter=4, projects=[1]"));
}

18 View Complete Implementation : ScannableTableTest.java
Copyright Apache License 2.0
Author : apache
@Test
public void testPFPushDownProjectFilterInAggregateNoGroup() {
    final StringBuilder buf = new StringBuilder();
    final Table table = new BeatlesProjectableFilterableTable(buf, false);
    final String explain = "PLAN=EnumerableAggregate(group=[{}], M=[MAX($0)])\n" + "  EnumerableInterpreter\n" + "    BindableTableScan(table=[[s, beatles]], filters=[[>($0, 1)]], projects=[[2]])";
    Calcitereplacedert.that().with(newSchema("s", Pair.of("beatles", table))).query("select max(\"k\") as m from \"s\".\"beatles\" where \"i\" > 1").explainContains(explain).returnsUnordered("M=1943");
}

18 View Complete Implementation : CalciteSchema.java
Copyright Apache License 2.0
Author : bitnine-oss
/**
 * Defines a table within this schema.
 */
public final TableEntry add(String tableName, Table table) {
    return add(tableName, table, ImmutableList.<String>of());
}

18 View Complete Implementation : DatasetPath.java
Copyright Apache License 2.0
Author : dremio
public Table getTable(SchemaPlus rootSchema) {
    List<FolderName> components = this.getFolderPath();
    SchemaPlus schema = rootSchema.getSubSchema(this.getRoot().getName());
    if (schema == null) {
        throw new IllegalStateException(String.format("Failure finding schema path %s in position 0 of path %s", getRoot().getName(), toPathString()));
    }
    int i = 1;
    for (FolderName folder : components) {
        schema = schema.getSubSchema(folder.getName());
        if (schema == null) {
            throw new IllegalStateException(String.format("Failure finding schema path %s in position %d of path %s", folder.getName(), i, toPathString()));
        }
        i++;
    }
    Table table = schema.getTable(getLeaf().getName());
    if (table == null) {
        throw new IllegalStateException(String.format("Failure finding table in path %s. The schema exists but no table in that schema matches %s", toPathString(), getLeaf().getName()));
    }
    return table;
}

18 View Complete Implementation : MetastoreAnalyzeTableHandler.java
Copyright Apache License 2.0
Author : apache
private DrillTable getDrillTable(AbstractSchema drillSchema, String tableName) {
    Table tableFromSchema = SqlHandlerUtil.getTableFromSchema(drillSchema, tableName);
    if (tableFromSchema == null) {
        throw UserException.validationError().message("No table with given name [%s] exists in schema [%s]", tableName, drillSchema.getFullSchemaName()).build(logger);
    }
    switch(tableFromSchema.getJdbcTableType()) {
        case TABLE:
            if (tableFromSchema instanceof DrillTable) {
                return (DrillTable) tableFromSchema;
            } else {
                throw UserException.validationError().message("replacedYZE does not support [%s] table kind", tableFromSchema.getClreplaced().getSimpleName()).build(logger);
            }
        default:
            throw UserException.validationError().message("replacedYZE does not support [%s] object type", tableFromSchema.getJdbcTableType()).build(logger);
    }
}

18 View Complete Implementation : CloneSchema.java
Copyright Apache License 2.0
Author : apache
@Override
protected Map<String, Table> getTableMap() {
    final Map<String, Table> map = new LinkedHashMap<>();
    for (String name : sourceSchema.getTableNames()) {
        final Table table = sourceSchema.getTable(name);
        if (table instanceof QueryableTable) {
            final QueryableTable sourceTable = (QueryableTable) table;
            map.put(name, createCloneTable(MATERIALIZATION_CONNECTION, sourceTable, name));
        }
    }
    return map;
}

18 View Complete Implementation : EnumerableTableScan.java
Copyright Apache License 2.0
Author : apache
/**
 * Returns whether EnumerableTableScan can generate code to handle a
 * particular variant of the Table SPI.
 * @deprecated
 */
@Deprecated
public static boolean canHandle(Table table) {
    if (table instanceof TransientTable) {
        // CALCITE-3673: TransientTable can't be implemented with Enumerable
        return false;
    }
    // See org.apache.calcite.prepare.RelOptTableImpl.getClreplacedExpressionFunction
    return table instanceof QueryableTable || table instanceof FilterableTable || table instanceof ProjectableFilterableTable || table instanceof ScannableTable;
}

18 View Complete Implementation : CalciteSchema.java
Copyright Apache License 2.0
Author : apache
/**
 * Defines a table within this schema.
 */
public TableEntry add(String tableName, Table table, ImmutableList<String> sqls) {
    final TableEntryImpl entry = new TableEntryImpl(this, tableName, table, sqls);
    tableMap.put(tableName, entry);
    return entry;
}

18 View Complete Implementation : CalciteSchema.java
Copyright Apache License 2.0
Author : apache
/**
 * Defines a table within this schema.
 */
public TableEntry add(String tableName, Table table) {
    return add(tableName, table, ImmutableList.of());
}

18 View Complete Implementation : RelOptTableImpl.java
Copyright Apache License 2.0
Author : apache
private static Function<Clreplaced, Expression> getClreplacedExpressionFunction(final SchemaPlus schema, final String tableName, final Table table) {
    if (table instanceof QueryableTable) {
        final QueryableTable queryableTable = (QueryableTable) table;
        return clazz -> queryableTable.getExpression(schema, tableName, clazz);
    } else if (table instanceof ScannableTable || table instanceof FilterableTable || table instanceof ProjectableFilterableTable) {
        return clazz -> Schemas.tableExpression(schema, Object[].clreplaced, tableName, table.getClreplaced());
    } else if (table instanceof StreamableTable) {
        return getClreplacedExpressionFunction(schema, tableName, ((StreamableTable) table).stream());
    } else {
        return input -> {
            throw new UnsupportedOperationException();
        };
    }
}

18 View Complete Implementation : RelOptTableImpl.java
Copyright Apache License 2.0
Author : apache
public static RelOptTableImpl create(RelOptSchema schema, RelDataType rowType, List<String> names, Table table, Expression expression) {
    return new RelOptTableImpl(schema, rowType, names, table, c -> expression, table.getStatistic().getRowCount());
}