* Get the constant value for the collection. Return null for not a collection.
*/
protected String getCollectionName(Mutable<ILogicalOperator> opRef) throws AlgebricksException {
VXQueryConstantValue constantValue;
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.UNNEST) {
return null;
}
UnnestOperator unnest = (UnnestOperator) op;
// Check if assign is for fn:Collection.
AbstractLogicalOperator op2 = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue();
if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
return null;
}
AssignOperator assign = (AssignOperator) op2;
// Check to see if the expression is a function and fn:Collection.
ILogicalExpression logicalExpression = (ILogicalExpression) assign.getExpressions().get(0).getValue();
if (logicalExpression.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return null;
}
AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) logicalExpression;
if (!functionCall.getFunctionIdentifier().equals(BuiltinFunctions.FN_COLLECTION_1.getFunctionIdentifier())) {
return null;
}
// Get the string assigned to the collection function.
AbstractLogicalOperator op3 = (AbstractLogicalOperator) assign.getInputs().get(0).getValue();
if (op3.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
AssignOperator assign2 = (AssignOperator) op3;
// Check to see if the expression is a constant expression and type string.
ILogicalExpression logicalExpression2 = (ILogicalExpression) assign2.getExpressions().get(0).getValue();
if (logicalExpression2.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
return null;
}
ConstantExpression constantExpression = (ConstantExpression) logicalExpression2;
constantValue = (VXQueryConstantValue) constantExpression.getValue();
if (constantValue.getType() != SequenceType.create(BuiltinTypeRegistry.XS_STRING, Quantifier.QUANT_ONE)) {
return null;
}
} else if (op3.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
ILogicalExpression logicalExpression2 = (ILogicalExpression) functionCall.getArguments().get(0).getValue();
if (logicalExpression2.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return null;
}
AbstractFunctionCallExpression functionCall2 = (AbstractFunctionCallExpression) logicalExpression2;