Dmitry Lychagin has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/3187
Change subject: [ASTERIXDB-2519][COMP] Fix compiler error with range predicate
......................................................................
[ASTERIXDB-2519][COMP] Fix compiler error with range predicate
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Fix compiler error (Could not infer type for variable ...)
when non-constant expressions are used in the range predicate
Change-Id: I8896e6c0743dcd5b608ebd5a5f25d3077047c789
---
M
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/range-search-open/range-search-open.5.query.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/range-search/range-search.5.query.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/range-search-open/range-search-open.2.adm
A
asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/range-search/range-search.2.adm
5 files changed, 87 insertions(+), 11 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/87/3187/1
diff --git
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
index 099f769..b45e1c6 100644
---
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
+++
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
@@ -329,8 +329,10 @@
LimitType[] highKeyLimits = new LimitType[numSecondaryKeys];
boolean[] lowKeyInclusive = new boolean[numSecondaryKeys];
boolean[] highKeyInclusive = new boolean[numSecondaryKeys];
- ILogicalExpression[] constantAtRuntimeExpressions = new
ILogicalExpression[numSecondaryKeys];
- LogicalVariable[] constAtRuntimeExprVars = new
LogicalVariable[numSecondaryKeys];
+ ILogicalExpression[] lowKeyConstAtRuntimeExpressions = new
ILogicalExpression[numSecondaryKeys];
+ ILogicalExpression[] highKeyConstantAtRuntimeExpressions = new
ILogicalExpression[numSecondaryKeys];
+ LogicalVariable[] lowKeyConstAtRuntimeExprVars = new
LogicalVariable[numSecondaryKeys];
+ LogicalVariable[] highKeyConstAtRuntimeExprVars = new
LogicalVariable[numSecondaryKeys];
/* TODO: For now we don't do any sophisticated analysis of the func
exprs to come up with "the best" range
* predicate. If we can't figure out how to integrate a certain
funcExpr into the current predicate,
@@ -367,13 +369,6 @@
ILogicalExpression searchKeyExpr = returnedSearchKeyExpr.first;
ILogicalExpression searchKeyEQExpr = null;
boolean realTypeConvertedToIntegerType =
returnedSearchKeyExpr.third;
- if (searchKeyExpr.getExpressionTag() ==
LogicalExpressionTag.FUNCTION_CALL) {
- constantAtRuntimeExpressions[keyPos] = searchKeyExpr;
- constAtRuntimeExprVars[keyPos] = context.newVar();
- VariableReferenceExpression varRef = new
VariableReferenceExpression(constAtRuntimeExprVars[keyPos]);
- varRef.setSourceLocation(searchKeyExpr.getSourceLocation());
- searchKeyExpr = varRef;
- }
LimitType limit = getLimitType(optFuncExpr, probeSubTree);
if (limit == null) {
@@ -393,6 +388,24 @@
} else if (limit == LimitType.LOW_EXCLUSIVE) {
limit = LimitType.LOW_INCLUSIVE;
}
+ }
+
+ if (searchKeyExpr.getExpressionTag() ==
LogicalExpressionTag.FUNCTION_CALL) {
+ LogicalVariable constAtRuntimeExprVar = context.newVar();
+ VariableReferenceExpression constAtRuntimeExprVarRef =
+ new VariableReferenceExpression(constAtRuntimeExprVar);
+
constAtRuntimeExprVarRef.setSourceLocation(searchKeyExpr.getSourceLocation());
+
+ if (limit == LimitType.LOW_INCLUSIVE || limit ==
LimitType.LOW_EXCLUSIVE || limit == LimitType.EQUAL) {
+ lowKeyConstAtRuntimeExpressions[keyPos] = searchKeyExpr;
+ lowKeyConstAtRuntimeExprVars[keyPos] =
constAtRuntimeExprVar;
+ }
+ if (limit == LimitType.HIGH_INCLUSIVE || limit ==
LimitType.HIGH_EXCLUSIVE
+ || limit == LimitType.EQUAL) {
+ highKeyConstantAtRuntimeExpressions[keyPos] =
searchKeyExpr;
+ highKeyConstAtRuntimeExprVars[keyPos] =
constAtRuntimeExprVar;
+ }
+ searchKeyExpr = constAtRuntimeExprVarRef;
}
switch (limit) {
@@ -562,9 +575,10 @@
ArrayList<LogicalVariable> assignKeyVarList = new ArrayList<>();
ArrayList<Mutable<ILogicalExpression>> assignKeyExprList = new
ArrayList<>();
int numLowKeys = createKeyVarsAndExprs(numSecondaryKeys, lowKeyLimits,
lowKeyExprs, assignKeyVarList,
- assignKeyExprList, keyVarList, context,
constantAtRuntimeExpressions, constAtRuntimeExprVars);
+ assignKeyExprList, keyVarList, context,
lowKeyConstAtRuntimeExpressions, lowKeyConstAtRuntimeExprVars);
int numHighKeys = createKeyVarsAndExprs(numSecondaryKeys,
highKeyLimits, highKeyExprs, assignKeyVarList,
- assignKeyExprList, keyVarList, context,
constantAtRuntimeExpressions, constAtRuntimeExprVars);
+ assignKeyExprList, keyVarList, context,
highKeyConstantAtRuntimeExpressions,
+ highKeyConstAtRuntimeExprVars);
BTreeJobGenParams jobGenParams = new
BTreeJobGenParams(chosenIndex.getIndexName(), IndexType.BTREE,
dataset.getDataverseName(), dataset.getDatasetName(),
retainInput, requiresBroadcast);
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/range-search-open/range-search-open.5.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/range-search-open/range-search-open.5.query.sqlpp
new file mode 100644
index 0000000..c37d241
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/range-search-open/range-search-open.5.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description: test range search with non-constant search expressions
+ */
+
+use test;
+
+select value count(*)
+from LineItem as c
+where
+ ((c.l_suppkey < 100 + tobigint(random()/2) /* = 0 */) and
+ (c.l_suppkey > 5 + tobigint(random()/2) /* = 0 */));
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/range-search/range-search.5.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/range-search/range-search.5.query.sqlpp
new file mode 100644
index 0000000..c37d241
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/range-search/range-search.5.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description: test range search with non-constant search expressions
+ */
+
+use test;
+
+select value count(*)
+from LineItem as c
+where
+ ((c.l_suppkey < 100 + tobigint(random()/2) /* = 0 */) and
+ (c.l_suppkey > 5 + tobigint(random()/2) /* = 0 */));
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/range-search-open/range-search-open.2.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/range-search-open/range-search-open.2.adm
new file mode 100644
index 0000000..2aba3a1
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/range-search-open/range-search-open.2.adm
@@ -0,0 +1 @@
+2978
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/range-search/range-search.2.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/range-search/range-search.2.adm
new file mode 100644
index 0000000..2aba3a1
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/range-search/range-search.2.adm
@@ -0,0 +1 @@
+2978
\ No newline at end of file
--
To view, visit https://asterix-gerrit.ics.uci.edu/3187
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8896e6c0743dcd5b608ebd5a5f25d3077047c789
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: stabilization-f69489
Gerrit-Owner: Dmitry Lychagin <[email protected]>