It's a bug. Please file it. We didn't prioritize lattices on views because the main purpose of lattices is to optimize storage, i.e. recognize join-aggregate queries on base tables and create aggregate tables with the same contents. At runtime the system never sees queries on views, because the views will have been expanded to their base tables.
I haven't thought about it much, but it may make sense to define lattices on simple views (e.g. with a WHERE and/or inner JOIN) but less sense to define lattices on more complex views (e.g. with MINUS, or GROUP BY, or outer JOIN). Julian On Fri, Jan 15, 2021 at 10:22 AM maneesh varshney <mvarsh...@gmail.com> wrote: > > Wanted to learn if this is by design. > > Consider two tables: 'Fact' and 'Dim'. If we create two views FactView and > DimView (say, simple SELECT *), we cannot use these views in lattice > definition. > > The Lattrice#populate (link below) only allows TableScan leaf nodes. > This method throws exception "Invalid node type LogicalProject in lattice > query" > > https://github.com/apache/calcite/blob/67ece68208af8385c9e06b6b5cc812d6ad36293c/core/src/main/java/org/apache/calcite/materialize/Lattice.java#L181 > > I am still struggling to figure out why views (LogicalProject) should not > be allowed here. Any pointer will help. > > Thanks!