fix the non-expand open type record issue
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_opentype@279 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/TopDownTypeInferenceRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/TopDownTypeInferenceRule.java
index 4ff2e65..4097d3a 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/TopDownTypeInferenceRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/TopDownTypeInferenceRule.java
@@ -39,6 +39,9 @@
* pattern match: sink/insert/assign record type is propagated from
* insert data source to the record-constructor expression
*/
+ if (context.checkIfInDontApplySet(this, opRef.getValue()))
+ return false;
+ context.addToDontApplySet(this, opRef.getValue());
AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.SINK)
return false;
@@ -73,28 +76,30 @@
AbstractLogicalOperator currentOperator = oldAssignOperator;
List<LogicalVariable> producedVariables = new ArrayList<LogicalVariable>();
boolean changed = false;
- if (!requiredRecordType.equals(inputRecordType)) {
- /**
- * find the assign operator for the "input record" to the
- * insert_delete operator
- */
- do {
- if (currentOperator.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
- producedVariables.clear();
- VariableUtilities.getProducedVariables(currentOperator, producedVariables);
- int position = producedVariables.indexOf(oldRecordVariable);
- /**
- * set the top-down propagated type
- */
- if (position >= 0) {
- AssignOperator originalAssign = (AssignOperator) currentOperator;
- List<Mutable<ILogicalExpression>> expressionPointers = originalAssign.getExpressions();
- ILogicalExpression expr = expressionPointers.get(position).getValue();
- if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
- ScalarFunctionCallExpression funcExpr = (ScalarFunctionCallExpression) expr;
- changed = TypeComputerUtilities.setRequiredAndInputTypes(funcExpr, requiredRecordType,
- inputRecordType);
+ /**
+ * find the assign operator for the "input record" to the insert_delete
+ * operator
+ */
+ do {
+ if (currentOperator.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
+ producedVariables.clear();
+ VariableUtilities.getProducedVariables(currentOperator, producedVariables);
+ int position = producedVariables.indexOf(oldRecordVariable);
+
+ /**
+ * set the top-down propagated type
+ */
+ if (position >= 0) {
+ AssignOperator originalAssign = (AssignOperator) currentOperator;
+ List<Mutable<ILogicalExpression>> expressionPointers = originalAssign.getExpressions();
+ ILogicalExpression expr = expressionPointers.get(position).getValue();
+ if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
+ ScalarFunctionCallExpression funcExpr = (ScalarFunctionCallExpression) expr;
+ changed = TypeComputerUtilities.setRequiredAndInputTypes(funcExpr, requiredRecordType,
+ inputRecordType);
+ changed &= !requiredRecordType.equals(inputRecordType);
+ if (changed) {
List<Mutable<ILogicalExpression>> args = funcExpr.getArguments();
int openPartStart = requiredRecordType.getFieldTypes().length * 2;
for (int j = openPartStart; j < args.size(); j++) {
@@ -105,15 +110,15 @@
}
}
}
- context.computeAndSetTypeEnvironmentForOperator(originalAssign);
}
+ context.computeAndSetTypeEnvironmentForOperator(originalAssign);
}
- if (currentOperator.getInputs().size() > 0)
- currentOperator = (AbstractLogicalOperator) currentOperator.getInputs().get(0).getValue();
- else
- break;
- } while (currentOperator != null);
- }
+ }
+ if (currentOperator.getInputs().size() > 0)
+ currentOperator = (AbstractLogicalOperator) currentOperator.getInputs().get(0).getValue();
+ else
+ break;
+ } while (currentOperator != null);
return changed;
}
}
diff --git a/asterix-app/src/test/resources/runtimets/queries/dml/opentype-noexpand.aql b/asterix-app/src/test/resources/runtimets/queries/dml/opentype-noexpand.aql
new file mode 100644
index 0000000..43aa5af
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/dml/opentype-noexpand.aql
@@ -0,0 +1,20 @@
+drop dataverse testdv2 if exists;
+create dataverse testdv2;
+use dataverse testdv2;
+
+create type testtype as open {
+ name: string,
+ id: string
+}
+
+create dataset testds(testtype) partitioned by key id;
+
+insert into dataset testds (
+{ "name": "Person One", "id": "001"}
+);
+
+write output to nc1:"rttest/dml_opentype-noexpand.adm";
+
+for $d in dataset("testds")
+order by $d.id
+return $d
diff --git a/asterix-app/src/test/resources/runtimets/results/dml/opentype-noexpand.adm b/asterix-app/src/test/resources/runtimets/results/dml/opentype-noexpand.adm
new file mode 100644
index 0000000..e6dc584
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/dml/opentype-noexpand.adm
@@ -0,0 +1 @@
+{ "name": "Person One", "id": "001" }