cleanup type casting code
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceStaticTypeCastRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceStaticTypeCastRule.java
index 3aae2dd..f42782b 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceStaticTypeCastRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceStaticTypeCastRule.java
@@ -42,7 +42,7 @@
/**
* Statically cast a constant from its type to a specified required type, in a
* recursive way. It enables: 1. bag-based fields in a record, 2. bidirectional
- * cast of a open field and a matched closed field, and 3. put in null fields
+ * cast of an open field and a matched closed field, and 3. put in null fields
* when necessary. It should be fired before the constant folding rule.
* This rule is not responsible for type casting between primitive types.
* Here is an example: A record { "hobby": {{"music", "coding"}}, "id": "001",
@@ -90,9 +90,6 @@
InsertDeleteOperator insertDeleteOp = (InsertDeleteOperator) op2;
if (insertDeleteOp.getOperation() == InsertDeleteOperator.Kind.DELETE)
return false;
- AbstractLogicalOperator assignOp = (AbstractLogicalOperator) op2.getInputs().get(0).getValue();
- if (assignOp.getOperatorTag() != LogicalOperatorTag.ASSIGN)
- return false;
/**
* get required record type
*/
@@ -101,21 +98,21 @@
IAType[] schemaTypes = (IAType[]) dataSource.getSchemaTypes();
IAType requiredRecordType = schemaTypes[schemaTypes.length - 1];
- AssignOperator topAssignOperator = (AssignOperator) assignOp;
List<LogicalVariable> usedVariables = new ArrayList<LogicalVariable>();
- VariableUtilities.getUsedVariables(topAssignOperator, usedVariables);
+ insertDeleteOperator.getPayloadExpression().getValue().getUsedVariables(usedVariables);
// the used variable should contain the record that will be inserted
// but it will not fail in many cases even if the used variable set is
// empty
if (usedVariables.size() == 0)
return false;
+
oldRecordVariable = usedVariables.get(0);
LogicalVariable inputRecordVar = usedVariables.get(0);
- IVariableTypeEnvironment env = topAssignOperator.computeOutputTypeEnvironment(context);
+ IVariableTypeEnvironment env = insertDeleteOperator.computeOutputTypeEnvironment(context);
IAType inputRecordType = (IAType) env.getVarType(inputRecordVar);
- AbstractLogicalOperator currentOperator = assignOp;
+ AbstractLogicalOperator currentOperator = (AbstractLogicalOperator) op2.getInputs().get(0).getValue();
/**
* find the assign operator for the "input record" to the insert_delete
* operator
@@ -123,6 +120,7 @@
do {
context.addToDontApplySet(this, currentOperator);
if (currentOperator.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
+ AssignOperator assignOp = (AssignOperator) currentOperator;
producedVariables.clear();
VariableUtilities.getProducedVariables(currentOperator, producedVariables);
int position = producedVariables.indexOf(oldRecordVariable);
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/typecast/StaticTypeCastUtil.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/typecast/StaticTypeCastUtil.java
index f608212..59c9ed0 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/typecast/StaticTypeCastUtil.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/typecast/StaticTypeCastUtil.java
@@ -132,9 +132,6 @@
* because they are not "statically cast-able".
* instead, the record will be dynamically casted at the runtime
*/
- //if (haveListOrRecordVariableExpr(funcExpr, env, true)) {
- // return false;
- //}
if (funcExpr.getFunctionIdentifier() == AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR) {
if (reqType.equals(BuiltinType.ANY)) {
reqType = DefaultOpenFieldType.NESTED_OPEN_AUNORDERED_LIST_TYPE;
@@ -407,7 +404,6 @@
}
// add the open part
-
for (int i = 0; i < openFields.length; i++) {
if (openFields[i]) {
arguments.add(originalArguments.get(2 * i));