diff --git a/reasoner/common/src/main/java/com/antgroup/openspg/reasoner/common/constants/Constants.java b/reasoner/common/src/main/java/com/antgroup/openspg/reasoner/common/constants/Constants.java index c17372b7..14f68e0b 100644 --- a/reasoner/common/src/main/java/com/antgroup/openspg/reasoner/common/constants/Constants.java +++ b/reasoner/common/src/main/java/com/antgroup/openspg/reasoner/common/constants/Constants.java @@ -85,4 +85,7 @@ public class Constants { Sets.newHashSet("isA", "locateAt"); public static final String CONCEPT_EDGE_EXPAND_FUNC_NAME = "concept_edge_expand"; + + /** allow throw exception in udf */ + public static final String ALLOW_UDF_EXCEPTION = "allowUDFThrowException"; } diff --git a/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/builtin/udf/ContainsAny.java b/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/builtin/udf/ContainsAny.java index f65cf22e..2be746aa 100644 --- a/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/builtin/udf/ContainsAny.java +++ b/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/builtin/udf/ContainsAny.java @@ -13,11 +13,16 @@ package com.antgroup.openspg.reasoner.udf.builtin.udf; +import com.antgroup.openspg.reasoner.common.constants.Constants; +import com.antgroup.openspg.reasoner.udf.impl.UdfMngImpl; import com.antgroup.openspg.reasoner.udf.model.UdfDefine; +import java.util.Map; import org.apache.commons.lang3.StringUtils; public class ContainsAny { + public ContainsAny() {} + /** * Contains any function. Return true if the first element of the input array (a string) contains * one or more of the remaining elements, otherwise return false. Such as: 1."adfvg", ["as, "gv"] @@ -53,6 +58,12 @@ public class ContainsAny { */ @UdfDefine(name = "contains_any", compatibleName = "contains") public boolean contains(String toCheckedStr, String keyword) { + Map configMap = UdfMngImpl.sceneConfigMap.get(); + Boolean allowUDFThrowException = + (Boolean) configMap.getOrDefault(Constants.ALLOW_UDF_EXCEPTION, false); + if ((toCheckedStr == null || keyword == null) && allowUDFThrowException) { + throw new RuntimeException("contains_any arguments is null"); + } if (StringUtils.isEmpty(toCheckedStr) || null == keyword) { return false; } diff --git a/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/impl/UdfMngImpl.java b/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/impl/UdfMngImpl.java index 4b9d889f..5e7a427b 100644 --- a/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/impl/UdfMngImpl.java +++ b/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/impl/UdfMngImpl.java @@ -54,6 +54,9 @@ public class UdfMngImpl implements UdfMng { private static volatile UdfMngImpl instance = null; + public static ThreadLocal> sceneConfigMap = + ThreadLocal.withInitial(HashMap::new); + /** 单例 */ public static UdfMngImpl getInstance() { if (null == instance) {