use of org.apache.asterix.om.constants.AsterixConstantValue 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.constants.AsterixConstantValue in project asterixdb by apache.
the class AddEquivalenceClassForRecordConstructorRule method propagateEquivalenceClassesForRecordConstructor.
@SuppressWarnings("unchecked")
private boolean propagateEquivalenceClassesForRecordConstructor(LogicalVariable recordVar, AbstractFunctionCallExpression funcExpr, AssignOperator assignOp, IOptimizationContext context) {
List<Mutable<ILogicalExpression>> argRefs = funcExpr.getArguments();
boolean changed = false;
// Only odd position arguments are field value expressions.
for (int parameterIndex = 1; parameterIndex < argRefs.size(); parameterIndex += 2) {
ILogicalExpression fieldExpr = argRefs.get(parameterIndex).getValue();
// Adds equivalent classes if a field is from a variable reference.
if (fieldExpr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
VariableReferenceExpression varExpr = (VariableReferenceExpression) fieldExpr;
LogicalVariable fieldVar = varExpr.getVariableReference();
Map<LogicalVariable, EquivalenceClass> ecs = context.getEquivalenceClassMap(assignOp);
if (ecs == null) {
ecs = new HashMap<LogicalVariable, EquivalenceClass>();
context.putEquivalenceClassMap(assignOp, ecs);
}
ILogicalExpression expr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), new MutableObject<ILogicalExpression>(new VariableReferenceExpression(recordVar)), new MutableObject<ILogicalExpression>(// Every two parameters corresponds to a field.
new ConstantExpression(new AsterixConstantValue(new AInt32(parameterIndex / 2)))));
EquivalenceClass equivClass = new EquivalenceClass(Collections.singletonList(fieldVar), fieldVar, Collections.singletonList(expr));
ecs.put(fieldVar, equivClass);
changed = true;
}
}
return changed;
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class ByNameToByIndexFieldAccessRule method createFieldAccessByIndex.
@SuppressWarnings("unchecked")
private static ILogicalExpression createFieldAccessByIndex(ARecordType recType, AbstractFunctionCallExpression fce) {
String s = ConstantExpressionUtil.getStringArgument(fce, 1);
if (s == null) {
return null;
}
int k = recType.getFieldIndex(s);
if (k < 0) {
return null;
}
return new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), fce.getArguments().get(0), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt32(k)))));
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class NonTaggedDataFormat method getExpressionEvalSizeComputer.
@Override
public IExpressionEvalSizeComputer getExpressionEvalSizeComputer() {
return new IExpressionEvalSizeComputer() {
@Override
public int getEvalSize(ILogicalExpression expr, IVariableEvalSizeEnvironment env) throws AlgebricksException {
switch(expr.getExpressionTag()) {
case CONSTANT:
{
ConstantExpression c = (ConstantExpression) expr;
if (c == ConstantExpression.MISSING) {
return 1;
} else if (c == ConstantExpression.FALSE || c == ConstantExpression.TRUE) {
return 2;
} else {
AsterixConstantValue acv = (AsterixConstantValue) c.getValue();
IAObject o = acv.getObject();
switch(o.getType().getTypeTag()) {
case DOUBLE:
return 9;
case FLOAT:
return 5;
case BOOLEAN:
return 2;
case MISSING:
return 1;
case NULL:
return 1;
case TINYINT:
return 2;
case SMALLINT:
return 3;
case INTEGER:
return 5;
case BIGINT:
return 9;
default:
return -1;
}
}
}
case FUNCTION_CALL:
{
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
if (f.getFunctionIdentifier().equals(BuiltinFunctions.TID)) {
return 5;
} else {
// TODO
return -1;
}
}
default:
{
// TODO
return -1;
}
}
}
};
}
Aggregations