/** Checks that a given query CAN NOT use a materialized view with a given definition. */ private void checkNoMaterialize(String materialize, String query, String model) { try { Prepare.THREAD_TRIM.set(true); MaterializationService.setThreadLocal(); CalciteAssert.that() .withMaterializations(model, "m0", materialize) .query(query) .enableMaterializations(true) .explainContains("EnumerableTableScan(table=[[hr, emps]])"); } finally { Prepare.THREAD_TRIM.set(false); } }
/** Checks that a given query can use a materialized view with a given definition. */ private void checkMaterialize( String materialize, String query, String model, Function<ResultSet, Void> explainChecker) { try { Prepare.THREAD_TRIM.set(true); MaterializationService.setThreadLocal(); CalciteAssert.that() .withMaterializations(model, "m0", materialize) .query(query) .enableMaterializations(true) .explainMatches("", explainChecker) .sameResultWithMaterializationsDisabled(); } finally { Prepare.THREAD_TRIM.set(false); } }
@Test public void testFilterQueryOnProjectView() { try { Prepare.THREAD_TRIM.set(true); MaterializationService.setThreadLocal(); CalciteAssert.that() .withMaterializations( JdbcTest.HR_MODEL, "m0", "select \"deptno\", \"empid\" from \"emps\"") .query("select \"empid\" + 1 as x from \"emps\" where \"deptno\" = 10") .enableMaterializations(true) .explainContains("EnumerableTableScan(table=[[hr, m0]])") .sameResultWithMaterializationsDisabled(); } finally { Prepare.THREAD_TRIM.set(false); } }