I'll log a bug. To me it makes more sense to add it to RelBuilderTest since view can be created programatically using ViewTable.viewMacro().
Do you think implementation can be similar to (inspired from) PlannerImpl.ViewExpanderImpl <https://github.com/apache/calcite/blob/HEAD/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java#L248> ? On Thu, Aug 2, 2018 at 6:40 PM Julian Hyde <[email protected]> wrote: > There’s no reason why it shouldn’t work, except that it hasn’t been > tested. It looks as if the implementation is trying to do the right thing — > parse the view, expand it to relational algebra, and push that algebra onto > RelBuilder’s stack — but it fails because the context is a dumb > implementation that doesn’t know how to expand views. > > Can you log a bug, please? I’m not sure whether the test case would be in > RelBuilderTest (using a schema that contains a view) or ServerTest (where > you could execute CREATE VIEW and then start a RelBuilder on the > connection). > > Julian > > > > > > On Aug 2, 2018, at 2:57 PM, Andrei Sereda <[email protected]> wrote: > > > > Hello, > > > > I was wondering if one can use relational algebra > > <https://calcite.apache.org/docs/algebra.html> API on the top of > existing > > view (or only tables are supported) ? Below is an example which fails for > > me : > > > > // suppose one creates a view as follows > > CREATE VIEW view AS select * from elastic.docs; > > > > @Test > > public void sql() { > > // works when using SQL > > CalciteAssert.that() > > .with(newConnectionFactory()) > > .query("select * from view") > > .returnsCount(1); > > } > > > > > > /** > > * Example when querying calcite view using {@link RelBuilder} api fails. > > * It is working fine when using SQL or when using RelBuilder on a > > table (not view). > > */ > > @Test > > public void relBuilder() throws Exception { > > Connection connection = newConnectionFactory().createConnection(); > > SchemaPlus root = > connection.unwrap(CalciteConnection.class).getRootSchema(); > > FrameworkConfig config = > > Frameworks.newConfigBuilder().defaultSchema(root).build(); > > // querying a view using RelBuilder fails > > RelBuilder builder = RelBuilder.create(config).scan("VIEW"); > > // querying directly a table works > > // RelBuilder builder = RelBuilder.create(config).scan("elastic", > "docs"); > > > > int count = 0; > > try (PreparedStatement stm = > > connection.unwrap(RelRunner.class).prepare(builder.build()); > > ResultSet rset = stm.executeQuery() ) { > > while (rset.next()) { > > count++; > > } > > } > > > > assertEquals(1, count); > > } > > > > Exception > > > > Caused by: java.lang.UnsupportedOperationException > > at > org.apache.calcite.plan.RelOptUtil$4.expandView(RelOptUtil.java:2805) > > at > org.apache.calcite.schema.impl.ViewTable.expandView(ViewTable.java:124) > > ... 39 more > > > > > > Anything I'm doing wrong ? > > > > Many thanks, > > Andrei. > >
