I feel like the solution might be to do something like
final RelOptTable.ViewExpander viewExpander =
(RelOptTable.ViewExpander)
Frameworks.getPlanner(configBuilder.build());
configBuilder.context(Contexts.of(viewExpander));
final RelBuilder builder = RelBuilder.create(configBuilder.build());
Found at:
testExpandViewShouldKeepAlias()
https://github.com/apache/calcite/blob/calcite-1.37.0/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java#L4359
But I have not had much success with this.
On 2024/07/06 18:45:21 Hugh Pearse wrote:
> Hi team, silly question. I'm looking at calcite model files which contain
> entities like tables, lattices, views etc. Assume these entities represent
> a logical data model (not materialised into a physical table).
>
> Example:
> I have a virtual database.
> User sends an SQL query like
> select books.title, authors.first_name from myschema.mymodel
>
> Where my model view is:
> SELECT books.id, books.title, authors.first_name, authors.last_name
> FROM books
> INNER JOIN authors ON books.author_id = authors.id
> ORDER BY books.id;
>
> Observations:
> When I convert the input relnode to SQL and build it, calcite has a
> preference to output "myschema.mymodel".
>
> My question:
> How to correctly get the SQL for the physical backend? (Output SQL should
> include table names like "authors" and "books").
>
> Notes:
> I am currently using a visitor class to replace, but not sure it's the
> correct way to implement.
>