use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class ConstantExpressionUtil method getConstantIaObject.
public static IAObject getConstantIaObject(ILogicalExpression expr, ATypeTag typeTag) {
if (expr.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
return null;
}
final IAlgebricksConstantValue acv = ((ConstantExpression) expr).getValue();
if (!(acv instanceof AsterixConstantValue)) {
return null;
}
final IAObject iaObject = ((AsterixConstantValue) acv).getObject();
if (typeTag != null) {
return iaObject.getType().getTypeTag() == typeTag ? iaObject : null;
} else {
return iaObject;
}
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class RecordRemoveFieldsTypeComputer method getPathFromConstantExpression.
private void getPathFromConstantExpression(String funcName, ILogicalExpression expression, Set<String> fieldNameSet, List<List<String>> pathList) throws AlgebricksException {
ConstantExpression ce = (ConstantExpression) expression;
if (!(ce.getValue() instanceof AsterixConstantValue)) {
throw new InvalidExpressionException(funcName, 1, ce, LogicalExpressionTag.CONSTANT);
}
IAObject item = ((AsterixConstantValue) ce.getValue()).getObject();
ATypeTag type = item.getType().getTypeTag();
switch(type) {
case STRING:
String fn = ((AString) item).getStringValue();
fieldNameSet.add(fn);
break;
case ARRAY:
AOrderedList pathOrdereList = (AOrderedList) item;
String fieldName = ((AString) pathOrdereList.getItem(0)).getStringValue();
fieldNameSet.add(fieldName);
List<String> path = new ArrayList<>();
for (int i = 0; i < pathOrdereList.size(); i++) {
path.add(((AString) pathOrdereList.getItem(i)).getStringValue());
}
pathList.add(path);
break;
default:
throw new UnsupportedTypeException(funcName, type);
}
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class FuzzyEqRule method expandFuzzyEq.
private boolean expandFuzzyEq(Mutable<ILogicalExpression> expRef, IOptimizationContext context, IVariableTypeEnvironment env, MetadataProvider metadataProvider) throws AlgebricksException {
ILogicalExpression exp = expRef.getValue();
if (exp.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
boolean expanded = false;
AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) exp;
FunctionIdentifier fi = funcExp.getFunctionIdentifier();
if (fi.equals(BuiltinFunctions.FUZZY_EQ)) {
List<Mutable<ILogicalExpression>> inputExps = funcExp.getArguments();
String simFuncName = FuzzyUtils.getSimFunction(metadataProvider);
ArrayList<Mutable<ILogicalExpression>> similarityArgs = new ArrayList<Mutable<ILogicalExpression>>();
for (int i = 0; i < inputExps.size(); ++i) {
Mutable<ILogicalExpression> inputExpRef = inputExps.get(i);
similarityArgs.add(inputExpRef);
}
FunctionIdentifier simFunctionIdentifier = FuzzyUtils.getFunctionIdentifier(simFuncName);
ScalarFunctionCallExpression similarityExp = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(simFunctionIdentifier), similarityArgs);
// Add annotations from the original fuzzy-eq function.
similarityExp.getAnnotations().putAll(funcExp.getAnnotations());
ArrayList<Mutable<ILogicalExpression>> cmpArgs = new ArrayList<Mutable<ILogicalExpression>>();
cmpArgs.add(new MutableObject<ILogicalExpression>(similarityExp));
IAObject simThreshold = FuzzyUtils.getSimThreshold(metadataProvider, simFuncName);
cmpArgs.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(simThreshold))));
ScalarFunctionCallExpression cmpExpr = FuzzyUtils.getComparisonExpr(simFuncName, cmpArgs);
expRef.setValue(cmpExpr);
return true;
} else if (fi.equals(AlgebricksBuiltinFunctions.AND) || fi.equals(AlgebricksBuiltinFunctions.OR)) {
for (int i = 0; i < 2; i++) {
if (expandFuzzyEq(funcExp.getArguments().get(i), context, env, metadataProvider)) {
expanded = true;
}
}
}
return expanded;
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class IntroduceSecondaryIndexInsertDeleteRule method getOpenOrNestedFieldAccessFunction.
private static AbstractFunctionCallExpression getOpenOrNestedFieldAccessFunction(Mutable<ILogicalExpression> varRef, List<String> fields) {
ScalarFunctionCallExpression func;
if (fields.size() > 1) {
IAObject fieldList = stringListToAOrderedList(fields);
Mutable<ILogicalExpression> fieldRef = constantToMutableLogicalExpression(fieldList);
// Create an expression for the nested case
func = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_NESTED), varRef, fieldRef);
} else {
IAObject fieldList = new AString(fields.get(0));
Mutable<ILogicalExpression> fieldRef = constantToMutableLogicalExpression(fieldList);
// Create an expression for the open field case (By name)
func = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), varRef, fieldRef);
}
return func;
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class AccessMethodUtils method checkFTSearchConstantExpression.
// Checks whether a proper constant expression is in place for the full-text search.
// A proper constant expression in the full-text search should be among string, string type (Un)ordered list.
public static void checkFTSearchConstantExpression(ILogicalExpression constExpression) throws AlgebricksException {
IAObject objectFromExpr = ConstantExpressionUtil.getConstantIaObject(constExpression, null);
String arg2Value;
IACursor oListCursor;
switch(objectFromExpr.getType().getTypeTag()) {
case STRING:
arg2Value = ConstantExpressionUtil.getStringConstant(objectFromExpr);
checkAndGenerateFTSearchExceptionForStringPhrase(arg2Value);
break;
case ARRAY:
oListCursor = ConstantExpressionUtil.getOrderedListConstant(objectFromExpr).getCursor();
checkEachElementInFTSearchListPredicate(oListCursor);
break;
case MULTISET:
oListCursor = ConstantExpressionUtil.getUnorderedListConstant(objectFromExpr).getCursor();
checkEachElementInFTSearchListPredicate(oListCursor);
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_TYPE_UNSUPPORTED, BuiltinFunctions.FULLTEXT_CONTAINS.getName(), objectFromExpr.getType().getTypeTag());
}
}
Aggregations