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.

Reply via email to