You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2015/06/17 20:57:04 UTC
[2/3] incubator-calcite git commit: Test case and workaround for
[CALCITE-760] Aggregate recommender blows up if row count estimate is too
high
Test case and workaround for [CALCITE-760] Aggregate recommender blows up if row count estimate is too high
Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/e7d15add
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/e7d15add
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/e7d15add
Branch: refs/heads/master
Commit: e7d15adde55029953166ec0b35e81133df4c1e68
Parents: bc8c4a9
Author: Julian Hyde <jh...@apache.org>
Authored: Tue Jun 16 14:14:55 2015 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Wed Jun 17 11:39:02 2015 -0700
----------------------------------------------------------------------
.../org/apache/calcite/test/LatticeTest.java | 134 +++++++++++--------
1 file changed, 75 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/e7d15add/core/src/test/java/org/apache/calcite/test/LatticeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/LatticeTest.java b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
index 0b649cc..92d121b 100644
--- a/core/src/test/java/org/apache/calcite/test/LatticeTest.java
+++ b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
@@ -43,12 +43,72 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
/**
* Unit test for lattices.
*/
public class LatticeTest {
+ private static final String SALES_LATTICE = "{\n"
+ + " name: 'star',\n"
+ + " sql: [\n"
+ + " 'select 1 from \"foodmart\".\"sales_fact_1997\" as \"s\"',\n"
+ + " 'join \"foodmart\".\"product\" as \"p\" using (\"product_id\")',\n"
+ + " 'join \"foodmart\".\"time_by_day\" as \"t\" using (\"time_id\")',\n"
+ + " 'join \"foodmart\".\"product_class\" as \"pc\" on \"p\".\"product_class_id\" = \"pc\".\"product_class_id\"'\n"
+ + " ],\n"
+ + " auto: false,\n"
+ + " algorithm: true,\n"
+ + " algorithmMaxMillis: 10000,\n"
+ + " rowCountEstimate: 86837,\n"
+ + " defaultMeasures: [ {\n"
+ + " agg: 'count'\n"
+ + " } ],\n"
+ + " tiles: [ {\n"
+ + " dimensions: [ 'the_year', ['t', 'quarter'] ],\n"
+ + " measures: [ {\n"
+ + " agg: 'sum',\n"
+ + " args: 'unit_sales'\n"
+ + " }, {\n"
+ + " agg: 'sum',\n"
+ + " args: 'store_sales'\n"
+ + " }, {\n"
+ + " agg: 'count'\n"
+ + " } ]\n"
+ + " } ]\n"
+ + "}\n";
+
+ private static final String INVENTORY_LATTICE = "{\n"
+ + " name: 'warehouse',\n"
+ + " sql: [\n"
+ + " 'select 1 from \"foodmart\".\"inventory_fact_1997\" as \"s\"',\n"
+ + " 'join \"foodmart\".\"product\" as \"p\" using (\"product_id\")',\n"
+ + " 'join \"foodmart\".\"time_by_day\" as \"t\" using (\"time_id\")',\n"
+ + " 'join \"foodmart\".\"warehouse\" as \"w\" using (\"warehouse_id\")'\n"
+ + " ],\n"
+ + " auto: false,\n"
+ + " algorithm: true,\n"
+ + " algorithmMaxMillis: 10000,\n"
+ + " rowCountEstimate: 4070,\n"
+ + " defaultMeasures: [ {\n"
+ + " agg: 'count'\n"
+ + " } ],\n"
+ + " tiles: [ {\n"
+ + " dimensions: [ 'the_year', 'warehouse_name'],\n"
+ + " measures: [ {\n"
+ + " agg: 'sum',\n"
+ + " args: 'store_invoice'\n"
+ + " }, {\n"
+ + " agg: 'sum',\n"
+ + " args: 'supply_time'\n"
+ + " }, {\n"
+ + " agg: 'sum',\n"
+ + " args: 'warehouse_cost'\n"
+ + " } ]\n"
+ + " } ]\n"
+ + "}\n";
+
private CalciteAssert.AssertThat modelWithLattice(String name, String sql,
String... extras) {
final StringBuilder buf = new StringBuilder("{ name: '")
@@ -548,66 +608,8 @@ public class LatticeTest {
}
@Test public void testTwoLattices() {
- final String sales_lattice = "{\n"
- + " name: 'star',\n"
- + " sql: [\n"
- + " 'select 1 from \"foodmart\".\"sales_fact_1997\" as \"s\"',\n"
- + " 'join \"foodmart\".\"product\" as \"p\" using (\"product_id\")',\n"
- + " 'join \"foodmart\".\"time_by_day\" as \"t\" using (\"time_id\")',\n"
- + " 'join \"foodmart\".\"product_class\" as \"pc\" on \"p\".\"product_class_id\" = \"pc\".\"product_class_id\"'\n"
- + " ],\n"
- + " auto: false,\n"
- + " algorithm: true,\n"
- + " algorithmMaxMillis: 10000,\n"
- + " rowCountEstimate: 86837,\n"
- + " defaultMeasures: [ {\n"
- + " agg: 'count'\n"
- + " } ],\n"
- + " tiles: [ {\n"
- + " dimensions: [ 'the_year', ['t', 'quarter'] ],\n"
- + " measures: [ {\n"
- + " agg: 'sum',\n"
- + " args: 'unit_sales'\n"
- + " }, {\n"
- + " agg: 'sum',\n"
- + " args: 'store_sales'\n"
- + " }, {\n"
- + " agg: 'count'\n"
- + " } ]\n"
- + " } ]\n"
- + "}\n";
-
- final String inventory_lattice = "{\n"
- + " name: 'warehouse',\n"
- + " sql: [\n"
- + " 'select 1 from \"foodmart\".\"inventory_fact_1997\" as \"s\"',\n"
- + " 'join \"foodmart\".\"product\" as \"p\" using (\"product_id\")',\n"
- + " 'join \"foodmart\".\"time_by_day\" as \"t\" using (\"time_id\")',\n"
- + " 'join \"foodmart\".\"warehouse\" as \"w\" using (\"warehouse_id\")'\n"
- + " ],\n"
- + " auto: false,\n"
- + " algorithm: true,\n"
- + " algorithmMaxMillis: 10000,\n"
- + " rowCountEstimate: 86837,\n"
- + " defaultMeasures: [ {\n"
- + " agg: 'count'\n"
- + " } ],\n"
- + " tiles: [ {\n"
- + " dimensions: [ 'the_year', 'warehouse_name'],\n"
- + " measures: [ {\n"
- + " agg: 'sum',\n"
- + " args: 'store_invoice'\n"
- + " }, {\n"
- + " agg: 'sum',\n"
- + " args: 'supply_time'\n"
- + " }, {\n"
- + " agg: 'sum',\n"
- + " args: 'warehouse_cost'\n"
- + " } ]\n"
- + " } ]\n"
- + "}\n";
final AtomicInteger counter = new AtomicInteger();
- modelWithLattices(sales_lattice, inventory_lattice)
+ modelWithLattices(SALES_LATTICE, INVENTORY_LATTICE)
.query("select s.\"unit_sales\", p.\"brand_name\"\n"
+ "from \"foodmart\".\"sales_fact_1997\" as s\n"
+ "join \"foodmart\".\"product\" as p using (\"product_id\")\n")
@@ -621,6 +623,20 @@ public class LatticeTest {
assertThat(counter.intValue(), equalTo(1));
}
+ /** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-760">[CALCITE-760]
+ * Aggregate recommender blows up if row count estimate is too high</a>. */
+ @Ignore
+ @Test public void testLatticeWithBadRowCountEstimate() {
+ final String lattice =
+ INVENTORY_LATTICE.replace("rowCountEstimate: 4070,",
+ "rowCountEstimate: 4074070,");
+ assertFalse(lattice.equals(INVENTORY_LATTICE));
+ modelWithLattices(lattice)
+ .query("values 1\n")
+ .returns("EXPR$0=1\n");
+ }
+
private CalciteAssert.AssertThat foodmartModel(String... extras) {
return modelWithLattice("star",
"select 1 from \"foodmart\".\"sales_fact_1997\" as \"s\"\n"