Skip to content

Commit

Permalink
Change Prepare.trim to a thread-local, to fix non-determinism in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
julianhyde committed Jun 28, 2014
1 parent 1de5cf8 commit 86a6f8c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/net/hydromatic/optiq/prepare/Prepare.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ public abstract class Prepare {
protected List<List<String>> fieldOrigins;
protected RelDataType parameterRowType;

public static boolean trim = false; // temporary. for testing.
// temporary. for testing.
public static final ThreadLocal<Boolean> THREAD_TRIM =
new ThreadLocal<Boolean>() {
@Override protected Boolean initialValue() {
return false;
}
};

public Prepare(OptiqPrepare.Context context, CatalogReader catalogReader,
Convention resultConvention) {
Expand Down Expand Up @@ -353,7 +359,7 @@ private boolean shouldTrim(RelNode rootRel) {
// For now, don't trim if there are more than 3 joins. The projects
// near the leaves created by trim migrate past joins and seem to
// prevent join-reordering.
return trim || RelOptUtil.countJoins(rootRel) < 2;
return THREAD_TRIM.get() || RelOptUtil.countJoins(rootRel) < 2;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3659,7 +3659,7 @@ private void startOfGroupStep3(String startOfGroup) {
/** Tests that field-trimming creates a project near the table scan. */
@Test public void testTrimFields() throws Exception {
try {
Prepare.trim = true;
Prepare.THREAD_TRIM.set(true);
OptiqAssert.that()
.with(OptiqAssert.Config.REGULAR)
.query(
Expand All @@ -3672,15 +3672,15 @@ private void startOfGroupStep3(String startOfGroup) {
+ " ProjectRel(deptno=[$1], name=[$2], commission=[$4])\n"
+ " EnumerableTableAccessRel(table=[[hr, emps]])\n");
} finally {
Prepare.trim = false;
Prepare.THREAD_TRIM.set(false);
}
}

/** Tests that field-trimming creates a project near the table scan, in a
* query with windowed-aggregation. */
@Test public void testTrimFieldsOver() throws Exception {
try {
Prepare.trim = true;
Prepare.THREAD_TRIM.set(true);
OptiqAssert.that()
.with(OptiqAssert.Config.REGULAR)
.query(
Expand All @@ -3693,7 +3693,7 @@ private void startOfGroupStep3(String startOfGroup) {
+ " ProjectRel(empid=[$0], deptno=[$1], name=[$2], commission=[$4])\n"
+ " EnumerableTableAccessRel(table=[[hr, emps]])\n");
} finally {
Prepare.trim = false;
Prepare.THREAD_TRIM.set(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class MaterializationTest {

@Test public void testFilterQueryOnProjectView() {
try {
Prepare.trim = true;
Prepare.THREAD_TRIM.set(true);
MaterializationService.setThreadLocal();
OptiqAssert.that()
.with(OptiqAssert.Config.REGULAR)
Expand All @@ -82,7 +82,7 @@ public class MaterializationTest {
"EnumerableTableAccessRel(table=[[hr, m0]])")
.sameResultWithMaterializationsDisabled();
} finally {
Prepare.trim = false;
Prepare.THREAD_TRIM.set(false);
}
}

Expand All @@ -97,7 +97,7 @@ private void checkMaterialize(String materialize, String query) {
private void checkMaterialize(String materialize, String query, String model,
Function1<ResultSet, Void> checker) {
try {
Prepare.trim = true;
Prepare.THREAD_TRIM.set(true);
MaterializationService.setThreadLocal();
OptiqAssert.that()
.with(OptiqAssert.Config.REGULAR)
Expand All @@ -107,7 +107,7 @@ private void checkMaterialize(String materialize, String query, String model,
.explainMatches(checker)
.sameResultWithMaterializationsDisabled();
} finally {
Prepare.trim = false;
Prepare.THREAD_TRIM.set(false);
}
}

Expand All @@ -116,7 +116,7 @@ private void checkMaterialize(String materialize, String query, String model,
private void checkNoMaterialize(String materialize, String query,
String model) {
try {
Prepare.trim = true;
Prepare.THREAD_TRIM.set(true);
MaterializationService.setThreadLocal();
OptiqAssert.that()
.with(OptiqAssert.Config.REGULAR)
Expand All @@ -126,7 +126,7 @@ private void checkNoMaterialize(String materialize, String query,
.explainContains(
"EnumerableTableAccessRel(table=[[hr, emps]])");
} finally {
Prepare.trim = false;
Prepare.THREAD_TRIM.set(false);
}
}

Expand Down

0 comments on commit 86a6f8c

Please sign in to comment.