Skip to content
This repository was archived by the owner on Apr 4, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions core/src/test/java/org/apache/calcite/test/LatticeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,62 @@ private void check(int n) throws IOException {
// TODO
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-787">[CALCITE-787]
* Wrong assignment of star table to Materialized views</a> */
@Test public void testOneLatticeOneMV() {
final AtomicInteger counter = new AtomicInteger();
final Class<JdbcTest.EmpDeptTableFactory> clazz =
JdbcTest.EmpDeptTableFactory.class;

final String mv = " materializations: [\n"
+ " {\n"
+ " table: \"m0\",\n"
+ " view: \"m0v\",\n"
+ " sql: \"select * from \\\"foodmart\\\".\\\"sales_fact_1997\\\" where \\\"product_id\\\" = 10\" "
+ " }\n"
+ " ]\n";

final String model =
""
+ "{\n"
+ " version: '1.0',\n"
+ " schemas: [\n"
+ JdbcTest.FOODMART_SCHEMA
+ ",\n"
+ " {\n"
+ " name: 'adhoc',\n"
+ " tables: [\n"
+ " {\n"
+ " name: 'EMPLOYEES',\n"
+ " type: 'custom',\n"
+ " factory: '"
+ clazz.getName()
+ "',\n"
+ " operand: {'foo': true, 'bar': 345}\n"
+ " }\n"
+ " ],\n"
+ " lattices: " + "[" + INVENTORY_LATTICE
+ " ]\n"
+ " },\n"
+ " {\n"
+ " name: 'mat',\n"
+ mv
+ " }\n"
+ " ]\n"
+ "}";

CalciteAssert.model(model)
.withDefaultSchema("foodmart")
.query("select * from \"foodmart\".\"sales_fact_1997\" where \"product_id\" = 10")
.enableMaterializations(true)
.substitutionMatches(
CalciteAssert.checkRel(
"EnumerableTableScan(table=[[mat, m0]])\n",
counter));
assertThat(counter.intValue(), equalTo(1));
}

private CalciteAssert.AssertThat foodmartModel(String... extras) {
return modelWithLattice("star",
"select 1 from \"foodmart\".\"sales_fact_1997\" as \"s\"\n"
Expand Down