Skip to content
Permalink
Browse files
[NO ISSUE] use isExternal() in lieu of instanceof
- user model changes: no
- storage format changes: no
- interface changes: yes

Details:

Add a default method for determining whether an IFunctionInfo
represents an external function or not, which is overriden by
ExternalFunctionInfo. This is much cleaner than abusing
instanceof to determine this.

Change-Id: I50539b9a8a3419a389590ea89230c7e5642c277b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/15543
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Ian Maxon <imaxon@uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@uci.edu>
Reviewed-by: Hussain Towaileb <hussainht@gmail.com>
  • Loading branch information
parshimers committed Mar 4, 2022
1 parent 2cfde81 commit cb9051993b66a75ec2ba852da6203e2f1f3d0692
Showing 5 changed files with 13 additions and 5 deletions.
@@ -26,7 +26,6 @@
import org.apache.asterix.external.library.ExternalFunctionDescriptorProvider;
import org.apache.asterix.metadata.declared.MetadataProvider;
import org.apache.asterix.om.functions.BuiltinFunctions;
import org.apache.asterix.om.functions.IExternalFunctionInfo;
import org.apache.asterix.om.functions.IFunctionDescriptor;
import org.apache.asterix.om.functions.IFunctionManager;
import org.apache.asterix.om.functions.IFunctionTypeInferer;
@@ -138,7 +137,7 @@ private IScalarEvaluatorFactory createScalarFunctionEvaluatorFactory(AbstractFun
throws AlgebricksException {
IScalarEvaluatorFactory[] args = codegenArguments(expr, env, inputSchemas, context);
IFunctionDescriptor fd;
if (expr.getFunctionInfo() instanceof IExternalFunctionInfo) {
if (expr.getFunctionInfo().isExternal()) {
// Expr is an external function
fd = ExternalFunctionDescriptorProvider.resolveExternalFunction(expr, env, context);
} else {
@@ -48,7 +48,6 @@
import org.apache.asterix.om.base.IAObject;
import org.apache.asterix.om.constants.AsterixConstantValue;
import org.apache.asterix.om.functions.BuiltinFunctions;
import org.apache.asterix.om.functions.IExternalFunctionInfo;
import org.apache.asterix.om.typecomputer.impl.TypeComputeUtils;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.ATypeTag;
@@ -389,7 +388,7 @@ private int countConstantArgs(List<Mutable<ILogicalExpression>> argList) {
private boolean canConstantFold(ScalarFunctionCallExpression function) throws AlgebricksException {
// skip external functions because they're not available at compile time (on CC)
IFunctionInfo fi = function.getFunctionInfo();
if (fi instanceof IExternalFunctionInfo) {
if (fi.isExternal()) {
return false;
}
// skip all functions that would produce records/arrays/multisets (derived types) in their open format
@@ -174,7 +174,7 @@ public static boolean supportsBatchInvocation(FunctionKind fnKind, IFunctionInfo
if (fnKind != FunctionKind.SCALAR) {
return false;
}
if (!(fnInfo instanceof IExternalFunctionInfo)) {
if (!fnInfo.isExternal()) {
return false;
}
ExternalFunctionLanguage language = ((IExternalFunctionInfo) fnInfo).getLanguage();
@@ -101,4 +101,9 @@ public Map<String, String> getResources() {
public boolean getNullCall() {
return nullCall;
}

@Override
public boolean isExternal() {
return true;
}
}
@@ -38,6 +38,11 @@ default boolean isFunctional() {
return true;
}

default boolean isExternal() {
// A function is not external by default.
return false;
}

/**
* @param args,
* the arguments.

0 comments on commit cb90519

Please sign in to comment.