use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class FieldAccessNestedResultType method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
IAType firstArgType = strippedInputTypes[0];
if (firstArgType.getTypeTag() != ATypeTag.OBJECT) {
return BuiltinType.ANY;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
ILogicalExpression arg1 = funcExpr.getArguments().get(1).getValue();
if (arg1.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
return BuiltinType.ANY;
}
ConstantExpression ce = (ConstantExpression) arg1;
IAObject v = ((AsterixConstantValue) ce.getValue()).getObject();
List<String> fieldPath = new ArrayList<>();
if (v.getType().getTypeTag() == ATypeTag.ARRAY) {
for (int i = 0; i < ((AOrderedList) v).size(); i++) {
fieldPath.add(((AString) ((AOrderedList) v).getItem(i)).getStringValue());
}
} else {
fieldPath.add(((AString) v).getStringValue());
}
ARecordType recType = (ARecordType) firstArgType;
IAType fieldType = recType.getSubFieldType(fieldPath);
return fieldType == null ? BuiltinType.ANY : fieldType;
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class RecordRemoveFieldsTypeComputer method getListFromExpression.
private List<String> getListFromExpression(String funcName, ILogicalExpression expression) throws AlgebricksException {
AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) expression;
List<Mutable<ILogicalExpression>> args = funcExp.getArguments();
List<String> list = new ArrayList<>();
for (Mutable<ILogicalExpression> arg : args) {
// At this point all elements has to be a constant
// Input list has only one level of nesting (list of list or list of strings)
ConstantExpression ce = (ConstantExpression) arg.getValue();
if (!(ce.getValue() instanceof AsterixConstantValue)) {
throw new InvalidExpressionException(funcName, 1, ce, LogicalExpressionTag.CONSTANT);
}
IAObject item = ((AsterixConstantValue) ce.getValue()).getObject();
ATypeTag type = item.getType().getTypeTag();
if (type == ATypeTag.STRING) {
list.add(((AString) item).getStringValue());
} else {
throw new UnsupportedTypeException(funcName, type);
}
}
return list;
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class ATypeHierarchy method getAsterixConstantValueFromNumericTypeObject.
// Get an AsterixConstantValue from a source Object
public static AsterixConstantValue getAsterixConstantValueFromNumericTypeObject(IAObject sourceObject, ATypeTag targetTypeTag, boolean strictDemote) throws HyracksDataException {
ATypeTag sourceTypeTag = sourceObject.getType().getTypeTag();
if (sourceTypeTag == targetTypeTag) {
return new AsterixConstantValue(sourceObject);
}
// if the constant type and target type does not match, we do a type conversion
ITypeConvertComputer convertComputer = null;
if (canPromote(sourceTypeTag, targetTypeTag)) {
convertComputer = ATypeHierarchy.getTypePromoteComputer(sourceTypeTag, targetTypeTag);
} else if (canDemote(sourceTypeTag, targetTypeTag)) {
convertComputer = ATypeHierarchy.getTypeDemoteComputer(sourceTypeTag, targetTypeTag, strictDemote);
}
if (convertComputer == null) {
return null;
}
IAObject targetObject = convertComputer.convertType(sourceObject);
return new AsterixConstantValue(targetObject);
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class DisjunctivePredicateToJoinRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider();
if (metadataProvider.isBlockingOperatorDisabled()) {
return false;
}
SelectOperator select;
if ((select = asSelectOperator(opRef)) == null) {
return false;
}
AbstractFunctionCallExpression condEx;
if ((condEx = asFunctionCallExpression(select.getCondition(), AlgebricksBuiltinFunctions.OR)) == null) {
return false;
}
List<Mutable<ILogicalExpression>> args = condEx.getArguments();
VariableReferenceExpression varEx = null;
IAType valType = null;
HashSet<AsterixConstantValue> values = new HashSet<AsterixConstantValue>();
for (Mutable<ILogicalExpression> arg : args) {
AbstractFunctionCallExpression fctCall;
if ((fctCall = asFunctionCallExpression(arg, AlgebricksBuiltinFunctions.EQ)) == null) {
return false;
}
boolean haveConst = false;
boolean haveVar = false;
List<Mutable<ILogicalExpression>> fctArgs = fctCall.getArguments();
for (Mutable<ILogicalExpression> fctArg : fctArgs) {
final ILogicalExpression argExpr = fctArg.getValue();
switch(argExpr.getExpressionTag()) {
case CONSTANT:
haveConst = true;
AsterixConstantValue value = (AsterixConstantValue) ((ConstantExpression) argExpr).getValue();
if (valType == null) {
valType = value.getObject().getType();
} else if (!isCompatible(valType, value.getObject().getType())) {
return false;
}
values.add(value);
break;
case VARIABLE:
haveVar = true;
final VariableReferenceExpression varArg = (VariableReferenceExpression) argExpr;
if (varEx == null) {
varEx = varArg;
} else if (!varEx.getVariableReference().equals(varArg.getVariableReference())) {
return false;
}
break;
default:
return false;
}
}
if (!(haveVar && haveConst)) {
return false;
}
}
AOrderedList list = new AOrderedList(new AOrderedListType(valType, "orderedlist"));
for (AsterixConstantValue value : values) {
list.add(value.getObject());
}
EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator();
context.computeAndSetTypeEnvironmentForOperator(ets);
ILogicalExpression cExp = new ConstantExpression(new AsterixConstantValue(list));
Mutable<ILogicalExpression> mutCExp = new MutableObject<>(cExp);
IFunctionInfo scanFctInfo = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.SCAN_COLLECTION);
UnnestingFunctionCallExpression scanExp = new UnnestingFunctionCallExpression(scanFctInfo, mutCExp);
LogicalVariable scanVar = context.newVar();
UnnestOperator unn = new UnnestOperator(scanVar, new MutableObject<>(scanExp));
unn.getInputs().add(new MutableObject<>(ets));
context.computeAndSetTypeEnvironmentForOperator(unn);
IFunctionInfo eqFctInfo = BuiltinFunctions.getAsterixFunctionInfo(AlgebricksBuiltinFunctions.EQ);
AbstractFunctionCallExpression eqExp = new ScalarFunctionCallExpression(eqFctInfo);
eqExp.getArguments().add(new MutableObject<>(new VariableReferenceExpression(scanVar)));
eqExp.getArguments().add(new MutableObject<>(varEx.cloneExpression()));
eqExp.getAnnotations().put(IndexedNLJoinExpressionAnnotation.INSTANCE, IndexedNLJoinExpressionAnnotation.INSTANCE);
BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
// Broadcast the OR predicates branch.
bcast.setObject(BroadcastExpressionAnnotation.BroadcastSide.LEFT);
eqExp.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
InnerJoinOperator jOp = new InnerJoinOperator(new MutableObject<>(eqExp));
jOp.getInputs().add(new MutableObject<>(unn));
jOp.getInputs().add(select.getInputs().get(0));
opRef.setValue(jOp);
context.computeAndSetTypeEnvironmentForOperator(jOp);
return true;
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class FullTextContainsParameterCheckRule method setDefaultValueForThirdParameter.
/**
* Sets the default option value(s) when a user doesn't provide any option.
*/
void setDefaultValueForThirdParameter(List<Mutable<ILogicalExpression>> newArgs) throws AlgebricksException {
// Sets the search mode option: the default option is conjunctive search.
ILogicalExpression searchModeOptionExpr = new ConstantExpression(new AsterixConstantValue(new AString(FullTextContainsDescriptor.SEARCH_MODE_OPTION)));
ILogicalExpression searchModeValExpr = new ConstantExpression(new AsterixConstantValue(new AString(FullTextContainsDescriptor.CONJUNCTIVE_SEARCH_MODE_OPTION)));
// Add this option as arguments to the ftcontains().
newArgs.add(new MutableObject<ILogicalExpression>(searchModeOptionExpr));
newArgs.add(new MutableObject<ILogicalExpression>(searchModeValExpr));
}
Aggregations