From 46d688143799e24e7730316cd913a12f4a9ce58a Mon Sep 17 00:00:00 2001 From: Zkplo <87751516+Zkplo@users.noreply.github.com> Date: Sat, 12 Oct 2024 11:26:00 +0800 Subject: [PATCH] [INLONG-11049][SDK] Standardize existing functions (#11339) Co-authored-by: ZKpLo <14148880+zkplo@user.noreply.gitee.com> --- .../process/function/FunctionTools.java | 39 +++++++++++++ .../process/function/TransformFunction.java | 7 +++ .../function/arithmetic/AbsFunction.java | 27 ++++----- .../function/arithmetic/AcosFunction.java | 28 +++++----- .../function/arithmetic/AcosdFunction.java | 18 +++++- .../function/arithmetic/AsinFunction.java | 17 ++++-- .../function/arithmetic/AsindFunction.java | 18 +++++- .../function/arithmetic/Atan2Function.java | 19 +++++-- .../function/arithmetic/Atan2dFunction.java | 19 +++++-- .../function/arithmetic/AtanFunction.java | 18 +++++- .../function/arithmetic/AtandFunction.java | 18 +++++- .../function/arithmetic/BinFunction.java | 17 +++++- .../function/arithmetic/CbrtFunction.java | 12 +++- .../function/arithmetic/CeilFunction.java | 27 ++++----- .../function/arithmetic/ChrFunction.java | 16 ++++-- .../function/arithmetic/CosFunction.java | 28 +++++----- .../function/arithmetic/CosdFunction.java | 18 +++++- .../function/arithmetic/CoshFunction.java | 20 ++++++- .../function/arithmetic/CotFunction.java | 21 +++++-- .../function/arithmetic/CotdFunction.java | 21 +++++-- .../function/arithmetic/EFunction.java | 11 +++- .../function/arithmetic/ErfFunction.java | 15 +++-- .../function/arithmetic/ErfcFunction.java | 15 +++-- .../function/arithmetic/ExpFunction.java | 26 ++++----- .../function/arithmetic/FloorFunction.java | 27 ++++----- .../function/arithmetic/GcdFunction.java | 14 +++-- .../function/arithmetic/GreatestFunction.java | 17 ++++-- .../function/arithmetic/HexFunction.java | 15 +++-- .../function/arithmetic/LcmFunction.java | 30 +++++----- .../function/arithmetic/LeastFunction.java | 15 +++-- .../function/arithmetic/LnFunction.java | 26 ++++----- .../function/arithmetic/Log10Function.java | 26 ++++----- .../function/arithmetic/Log2Function.java | 26 ++++----- .../function/arithmetic/LogFunction.java | 25 ++++----- .../function/arithmetic/MinScaleFunction.java | 11 +++- .../function/arithmetic/ModuloFunction.java | 17 +++++- .../arithmetic/NumNonNullsFunction.java | 8 ++- .../function/arithmetic/NumNullsFunction.java | 10 +++- .../function/arithmetic/PiFunction.java | 11 +++- .../function/arithmetic/PowerFunction.java | 26 ++++----- .../function/arithmetic/RadiansFunction.java | 12 +++- .../arithmetic/RadixConvertFunction.java | 23 +++++--- .../function/arithmetic/RandFunction.java | 15 +++-- .../arithmetic/RandIntegerFunction.java | 18 ++++-- .../function/arithmetic/RoundFunction.java | 18 +++++- .../function/arithmetic/ScaleFunction.java | 11 +++- .../function/arithmetic/SignFunction.java | 20 ++++++- .../function/arithmetic/SinFunction.java | 26 ++++----- .../function/arithmetic/SindFunction.java | 16 +++++- .../function/arithmetic/SinhFunction.java | 26 ++++----- .../function/arithmetic/SqrtFunction.java | 26 ++++----- .../function/arithmetic/TanFunction.java | 17 +++++- .../function/arithmetic/TandFunction.java | 16 +++++- .../function/arithmetic/TanhFunction.java | 16 +++++- .../arithmetic/TrimScaleFunction.java | 11 +++- .../function/arithmetic/TruncateFunction.java | 21 +++---- .../collection/ArrayAppendFunction.java | 16 ++++-- .../collection/ArrayConcatFunction.java | 16 ++++-- .../collection/ArrayContainsFunction.java | 20 +++++-- .../collection/ArrayDistinctFunction.java | 16 ++++-- .../collection/ArrayExceptFunction.java | 21 ++++--- .../function/collection/ArrayFunction.java | 17 ++++-- .../collection/ArrayIntersectFunction.java | 22 +++++--- .../collection/ArrayJoinFunction.java | 27 +++++---- .../function/collection/ArrayMaxFunction.java | 15 +++-- .../function/collection/ArrayMinFunction.java | 15 +++-- .../collection/ArrayPositionFunction.java | 21 ++++--- .../collection/ArrayPrependFunction.java | 16 ++++-- .../collection/ArrayRemoveFunction.java | 16 ++++-- .../collection/ArrayReverseFunction.java | 16 ++++-- .../collection/ArraySliceFunction.java | 28 ++++++---- .../collection/ArraySortFunction.java | 36 ++++++++---- .../collection/ArrayUnionFunction.java | 17 ++++-- .../collection/CardinalityFunction.java | 19 +++++-- .../function/collection/ElementFunction.java | 17 ++++-- .../collection/FindInSetFunction.java | 26 ++++++--- .../collection/MapEntriesFunction.java | 17 ++++-- .../collection/MapFromArraysFunction.java | 19 +++++-- .../function/collection/MapFunction.java | 20 ++++--- .../function/collection/MapKeysFunction.java | 16 ++++-- .../function/collection/MapUnionFunction.java | 20 ++++--- .../function/collection/MapValueFunction.java | 16 ++++-- .../compression/CompressFunction.java | 26 +++++++-- .../compression/UnCompressFunction.java | 20 +++++-- .../function/condition/CoalesceFunction.java | 21 ++++--- .../function/condition/IfFunction.java | 13 ++++- .../function/condition/IfNullFunction.java | 16 ++++-- .../function/condition/IsNullFunction.java | 12 +++- .../function/condition/NullIfFunction.java | 17 +++--- .../function/encryption/DecodeFunction.java | 18 ++++-- .../function/encryption/EncodeFunction.java | 18 ++++-- .../encryption/FromBase64Function.java | 13 ++++- .../function/encryption/Md5Function.java | 14 ++++- .../function/encryption/Sha2Function.java | 15 +++-- .../function/encryption/ShaFunction.java | 15 +++-- .../function/encryption/ToBase64Function.java | 16 +++++- .../json/JsonArrayAppendFunction.java | 12 +++- .../json/JsonArrayInsertFunction.java | 10 +++- .../function/json/JsonArraysFunction.java | 17 +++--- .../function/json/JsonExistsFunction.java | 18 ++++-- .../function/json/JsonQueryFunction.java | 19 ++++--- .../function/json/JsonQuoteFunction.java | 28 +++++----- .../function/json/JsonUnQuoteFunction.java | 24 +++++--- .../function/json/JsonValueFunction.java | 16 ++++-- .../function/string/AsciiFunction.java | 25 ++++----- .../function/string/BitLengthFunction.java | 17 ++++-- .../function/string/CharLengthFunction.java | 16 ++++-- .../function/string/ConcatFunction.java | 25 ++++----- .../function/string/ConcatWsFunction.java | 19 +++++-- .../function/string/ContainsFunction.java | 22 ++++++-- .../process/function/string/EltFunction.java | 14 +++-- .../function/string/EndsWithFunction.java | 13 ++++- .../function/string/FormatFunction.java | 8 ++- .../{ => string}/InitCapFunction.java | 19 +++++-- .../function/string/InsertFunction.java | 41 +++++++------- .../function/string/IsAlphaFunction.java | 17 ++++-- .../function/string/IsDecimalFunction.java | 17 ++++-- .../function/string/IsDigitFunction.java | 12 +++- .../process/function/string/LeftFunction.java | 13 ++++- .../function/string/LengthFunction.java | 16 ++++-- .../function/string/LocateFunction.java | 32 +++++------ .../function/string/LowerFunction.java | 16 ++++-- .../process/function/string/LpadFunction.java | 22 +++++--- .../function/string/LtrimFunction.java | 13 +++-- .../function/string/ParseUrlFunction.java | 23 ++++++-- .../function/string/PrintfFunction.java | 12 +++- .../function/string/RegexpCountFunction.java | 18 ++++-- .../string/RegexpExtractAllFunction.java | 30 ++++++---- .../string/RegexpExtractFunction.java | 34 +++++++---- .../function/string/RegexpFunction.java | 18 ++++-- .../function/string/RegexpInstrFunction.java | 17 ++++-- .../string/RegexpMatchesFunction.java | 33 +++++++---- .../string/RegexpReplaceFunction.java | 18 ++++-- .../string/RegexpSplitToArrayFunction.java | 35 ++++++++---- .../function/string/RegexpSubstrFunction.java | 15 +++-- .../function/string/RepeatFunction.java | 14 +++-- .../function/string/ReplaceFunction.java | 16 +++++- .../function/string/ReverseFunction.java | 23 ++++---- .../function/string/RightFunction.java | 18 ++++-- .../process/function/string/RpadFunction.java | 27 ++++++--- .../function/string/RtrimFunction.java | 15 +++-- .../function/string/SoundexFunction.java | 14 +++-- .../function/string/SpaceFunction.java | 17 ++++-- .../function/string/SplitIndexFunction.java | 25 +++++---- .../function/string/StartsWithFunction.java | 13 ++++- .../function/string/StrToMapFunction.java | 26 ++++++--- .../function/string/StrcmpFunction.java | 21 ++++--- .../function/string/SubstringFunction.java | 17 +++++- .../string/SubstringIndexFunction.java | 19 +++++-- .../function/string/TranslateFunction.java | 36 ++++++------ .../process/function/string/TrimFunction.java | 17 ++++-- .../function/string/UnHexFunction.java | 15 +++-- .../function/string/UpperFunction.java | 16 ++++-- .../function/string/UrlDecodeFunction.java | 20 +++++-- .../function/string/UrlEncodeFunction.java | 20 +++++-- .../process/function/string/UuidFunction.java | 13 ++++- .../function/temporal/ConvertTzFunction.java | 27 ++++++--- .../function/temporal/DateAddFunction.java | 31 ++++++---- .../function/temporal/DateDiffFunction.java | 19 +++++-- .../temporal/DateExtractFunction.java | 56 ++++++++++++++++--- .../function/temporal/DateFormatFunction.java | 37 +++++------- .../function/temporal/DateSubFunction.java | 32 +++++++---- .../temporal/FromUnixTimeFunction.java | 21 +++++-- .../function/temporal/LocalDateFunction.java | 16 ++++-- .../function/temporal/LocalTimeFunction.java | 15 +++-- .../function/temporal/NowFunction.java | 21 +++---- .../function/temporal/TimeDiffFunction.java | 17 ++++-- .../temporal/TimestampAddFunction.java | 32 ++++++++--- .../temporal/TimestampDiffFunction.java | 15 +++-- .../temporal/TimestampExtractFunction.java | 21 ++++++- .../function/temporal/TimestampFunction.java | 17 ++++-- .../function/temporal/ToDateFunction.java | 31 ++++------ .../temporal/ToTimestampFunction.java | 15 +++-- .../temporal/UnixTimestampFunction.java | 18 ++++-- .../transform/process/pojo/FunctionInfo.java | 37 ++++++++++++ .../process/function/TestFunctionDoc.java | 31 ++++++++++ ...on.java => TestRegexpExtractFunction.java} | 2 +- 177 files changed, 2378 insertions(+), 1119 deletions(-) rename inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/{ => string}/InitCapFunction.java (76%) create mode 100644 inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/pojo/FunctionInfo.java create mode 100644 inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/TestFunctionDoc.java rename inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/{TestRegexExtractFunction.java => TestRegexpExtractFunction.java} (98%) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/FunctionTools.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/FunctionTools.java index 8da0bf622ec..123b2394037 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/FunctionTools.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/FunctionTools.java @@ -19,7 +19,9 @@ import org.apache.inlong.sdk.transform.process.parser.ColumnParser; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import org.apache.inlong.sdk.transform.process.pojo.FunctionInfo; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Function; @@ -29,6 +31,8 @@ import org.reflections.scanners.Scanners; import java.lang.reflect.Constructor; +import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.Set; @@ -65,10 +69,45 @@ private static void init() { return clazz; }); } + } + } + + private static class FunctionDocHolder { + + final static List functionDocList = Lists.newCopyOnWriteArrayList(); + static { + initFunctionDoc(); + } + + private static void initFunctionDoc() { + Collection> clazzList = functionMap.values(); + for (Class clazz : clazzList) { + TransformFunction annotation = clazz.getAnnotation(TransformFunction.class); + if (annotation == null || ArrayUtils.isEmpty(annotation.names())) { + continue; + } + StringBuilder name = new StringBuilder(); + StringBuilder explanation = new StringBuilder(); + StringBuilder example = new StringBuilder(); + for (String functionName : annotation.names()) { + name.append(functionName.concat(annotation.parameter() + "\r\n")); + } + for (String functionExplanation : annotation.descriptions()) { + explanation.append(functionExplanation.concat("\r\n")); + } + for (String functionExample : annotation.examples()) { + example.append(functionExample.concat("\r\n")); + } + functionDocList.add(new FunctionInfo(name.toString(), explanation.toString(), example.toString())); + } } } + public static List getFunctionDoc() { + return FunctionDocHolder.functionDocList; + } + public static ValueParser getTransformFunction(Function func) { if (func == null) { return null; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TransformFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TransformFunction.java index b78d2b31f9f..4f8d0a19de5 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TransformFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TransformFunction.java @@ -28,4 +28,11 @@ public @interface TransformFunction { String[] names(); + + String parameter() default ""; + + String[] descriptions() default {}; + + String[] examples() default {}; + } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AbsFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AbsFunction.java index a59ed0f50f6..3cc9104b3ed 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AbsFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AbsFunction.java @@ -28,31 +28,32 @@ import java.math.BigDecimal; /** - * AbsFunction - * description: abs(numeric)--returns the absolute value of numeric + * AbsFunction -> abs(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the absolute value of 'numeric'. */ -@TransformFunction(names = {"abs"}) +@TransformFunction(names = {"abs"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the absolute value of 'numeric'." +}, examples = { + "abs(2) = 2", + "abs(-4.25) = 4.25" +}) public class AbsFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public AbsFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return numberValue.abs(); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AcosFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AcosFunction.java index 9d3feb0a551..fefd0790f9f 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AcosFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AcosFunction.java @@ -28,31 +28,33 @@ import java.math.BigDecimal; /** - * AcosFunction - * description: acos(numeric)--returns the arc cosine of numeric + * AcosFunction -> acos(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the arc cosine of 'numeric'. */ -@TransformFunction(names = {"acos"}) +@TransformFunction(names = {"acos"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the arc cosine of 'numeric'." +}, examples = { + "acos(1) = 0.0", + "acos(0) = 1.5707963267948966", + "acos(-1) = 3.141592653589793" +}) public class AcosFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public AcosFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.acos(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AcosdFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AcosdFunction.java index 96a9236a43c..7fc5abbaf0e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AcosdFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AcosdFunction.java @@ -28,10 +28,19 @@ import java.math.BigDecimal; /** - * AcosdFunction - * description: acosd(numeric)--returns the arc cosine of numeric in units of degrees + * AcosdFunction -> acosd(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the arc cosine of 'numeric' in units of degrees. */ -@TransformFunction(names = {"acosd"}) +@TransformFunction(names = {"acosd"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the arc cosine of 'numeric' in units of degrees." +}, examples = { + "acosd(1) = 0.0", + "acosd(0) = 90.0", + "acosd(-1) = 180.0" +}) public class AcosdFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +52,9 @@ public AcosdFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.toDegrees(Math.acos(numberValue.doubleValue())); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AsinFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AsinFunction.java index a42acbf06a5..66cd39ad995 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AsinFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AsinFunction.java @@ -28,10 +28,19 @@ import java.math.BigDecimal; /** - * AsinFunction - * description: asin(numeric)--returns the arc sine of numeric + * AsinFunction -> asin(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the arc sine of 'numeric'. */ -@TransformFunction(names = {"asin"}) +@TransformFunction(names = {"asin"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the arc sine of 'numeric' in units of degrees." +}, examples = { + "asin(0.5) = 0.5235987755982989", + "asin(0) = 0.0", + "asin(-0.5) = -0.5235987755982989" +}) public class AsinFunction implements ValueParser { private ValueParser numberParser; @@ -44,7 +53,7 @@ public AsinFunction(Function expr) { public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); if (numberObj == null) { - throw new NullPointerException("Parsed number object is null"); + return null; } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.asin(numberValue.doubleValue()); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AsindFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AsindFunction.java index 56b8e64bdb8..5ba585b6f92 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AsindFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AsindFunction.java @@ -28,10 +28,19 @@ import java.math.BigDecimal; /** - * AsindFunction - * description: asind(numeric)--returns the arc sine of numeric in units of degrees + * AsindFunction -> asind(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the arc sine of 'numeric' in units of degrees. */ -@TransformFunction(names = {"asind"}) +@TransformFunction(names = {"asind"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the arc sine of 'numeric' in units of degrees." +}, examples = { + "asind(0.5) = 30.000000000000004", + "asind(0) = 0.0", + "asind(-0.5) = -30.000000000000004" +}) public class AsindFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +52,9 @@ public AsindFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.toDegrees(Math.asin(numberValue.doubleValue())); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Atan2Function.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Atan2Function.java index 487cc8c1f14..21a0acaf2c9 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Atan2Function.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Atan2Function.java @@ -28,10 +28,19 @@ import java.math.BigDecimal; /** - * Atan2Function - * description: atan2(numeric)--returns the arc tangent of a coordinate (numeric1, numeric2). + * Atan2Function -> atan2(numericx,numericy) + * description: + * - Return NULL if 'numericx' or 'numericy' is NULL; + * - Return the arc tangent of a coordinate ('numericx', 'numericy'). */ -@TransformFunction(names = {"atan2"}) +@TransformFunction(names = {"atan2"}, parameter = "(Numeric numeric)", descriptions = { + "Return \"\" if 'numericx' or 'numericy' is NULL;", + "Return the arc tangent of a coordinate ('numericx', 'numericy')." +}, examples = { + "atan2(1, 1) = 0.7853981633974483", + "atan2(1, 0) = 1.5707963267948966", + "atan2(0, -1) = 3.141592653589793" +}) public class Atan2Function implements ValueParser { private ValueParser xParser; @@ -47,8 +56,8 @@ public Object parse(SourceData sourceData, int rowIndex, Context context) { Object xObj = xParser.parse(sourceData, rowIndex, context); Object yObj = yParser.parse(sourceData, rowIndex, context); - if (xObj == null) { - throw new NullPointerException("Parsed number object on the x-axis is null"); + if (xObj == null || yObj == null) { + return null; } BigDecimal xValue = OperatorTools.parseBigDecimal(xObj); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Atan2dFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Atan2dFunction.java index d6d67374e43..965db85bc30 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Atan2dFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Atan2dFunction.java @@ -28,10 +28,19 @@ import java.math.BigDecimal; /** - * Atan2dFunction - * description: asind(numeric)--returns the arc sine of numeric in units of degrees + * Atan2dFunction -> atan2d(numericx,numericy) + * description: + * - Return NULL if 'numericx' or 'numericy' is NULL; + * - Return inverse tangent of 'numericy'/'numericx', result in degrees. */ -@TransformFunction(names = {"atan2d"}) +@TransformFunction(names = {"atan2d"}, parameter = "(Numeric numericx, Numeric numericy)", descriptions = { + "- Return \"\" if 'numericx' or 'numericy' is NULL;", + "- Return inverse tangent of 'numericy'/'numericx', result in degrees." +}, examples = { + "atan2d(1, 1) = 45.0", + "atan2d(1, 0) = 90.0", + "atan2d(0, -1) = 180.0" +}) public class Atan2dFunction implements ValueParser { private ValueParser xParser; @@ -47,8 +56,8 @@ public Object parse(SourceData sourceData, int rowIndex, Context context) { Object xObj = xParser.parse(sourceData, rowIndex, context); Object yObj = yParser.parse(sourceData, rowIndex, context); - if (xObj == null) { - throw new NullPointerException("Parsed number object on the x-axis is null"); + if (xObj == null || yObj == null) { + return null; } BigDecimal xValue = OperatorTools.parseBigDecimal(xObj); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AtanFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AtanFunction.java index ada42b73226..d6149fd5742 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AtanFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AtanFunction.java @@ -28,10 +28,19 @@ import java.math.BigDecimal; /** - * AtanFunction - * description: atan(numeric)--returns the arc tangent of numeric + * AtanFunction -> atan(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the arc tangent of 'numeric'. */ -@TransformFunction(names = {"atan"}) +@TransformFunction(names = {"atan"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the arc tangent of 'numeric'." +}, examples = { + "atan(1) = 0.7853981633974483", + "atan(0) = 0.0", + "atan(-1) = -0.7853981633974483" +}) public class AtanFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +52,9 @@ public AtanFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.atan(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AtandFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AtandFunction.java index 22975b1ceda..c385cc85a5c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AtandFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/AtandFunction.java @@ -28,10 +28,19 @@ import java.math.BigDecimal; /** - * AtandFunction - * description: atand(numeric)--returns the arc tangent of numeric in units of degrees + * AtandFunction -> atand(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the arc tangent of 'numeric' in units of degrees. */ -@TransformFunction(names = {"atand"}) +@TransformFunction(names = {"atand"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the arc tangent of 'numeric' in units of degrees." +}, examples = { + "atand(1) = 45.0", + "atand(0) = 0.0", + "atand(-1) = -45.0" +}) public class AtandFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +52,9 @@ public AtandFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.toDegrees(Math.atan(numberValue.doubleValue())); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/BinFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/BinFunction.java index b09b0b6a44c..bceb42922e3 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/BinFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/BinFunction.java @@ -28,11 +28,19 @@ import java.math.BigDecimal; import java.util.List; + /** - * BinFunction - * description: bin(integer)--Returns a string representation of an integer in binary format. If the integer is NULL, NULL is returned. + * BinFunction -> bin(integer) + * description: + * - Return NULL if 'integer' is NULL; + * - Return a string representation of 'integer' in binary format. */ -@TransformFunction(names = {"bin"}) +@TransformFunction(names = {"bin"}, parameter = "(Integer integer)", descriptions = { + "- Return \"\" if 'integer' is NULL;", + "- Return a string representation of 'integer' in binary format." +}, examples = { + "bin(4) = 100" +}) public class BinFunction implements ValueParser { private ValueParser valueParser; @@ -50,6 +58,9 @@ public BinFunction(Function expr) { public Object parse(SourceData sourceData, int rowIndex, Context context) { if (valueParser != null) { Object valueObj = valueParser.parse(sourceData, rowIndex, context); + if (valueObj == null) { + return null; + } BigDecimal value = OperatorTools.parseBigDecimal(valueObj); return Integer.toBinaryString(value.intValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CbrtFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CbrtFunction.java index 46fb010a386..4c401240715 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CbrtFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CbrtFunction.java @@ -28,10 +28,16 @@ /** * CbrtFunction -> cbrt(numeric) * description: - * - return NULL if numeric is NULL - * - return cube root + * - Return NULL if 'numeric' is NULL; + * - Return cube root. */ -@TransformFunction(names = {"cbrt"}) +@TransformFunction(names = {"cbrt"}, parameter = "(Numeric numeric)", descriptions = { + "- Return NULL if 'numeric' is NULL;", + "- Return cube root.", +}, examples = { + "cbrt(5) = 1.7099759466766968", + "cbrt(27) = 3.0" +}) public class CbrtFunction implements ValueParser { private ValueParser numParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CeilFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CeilFunction.java index 3bfe886f1f8..38ac22e38a1 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CeilFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CeilFunction.java @@ -28,31 +28,32 @@ import java.math.BigDecimal; /** - * CeilFunction - * description: ceil(numeric)--rounds numeric up, and returns the smallest number that is greater than or equal to numeric + * CeilFunction -> ceil(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the smallest number that is greater than or equal to 'numeric'. */ -@TransformFunction(names = {"ceil"}) +@TransformFunction(names = {"ceil"}, parameter = "(Numeric numeric)", descriptions = { + "- Return NULL if 'numeric' is NULL;", + "- Return the smallest number that is greater than or equal to 'numeric'.", +}, examples = { + "ceil(-5.67) = -5.0", + "ceil(1.23) = 2.0" +}) public class CeilFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public CeilFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.ceil(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ChrFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ChrFunction.java index a1e4a42d3fc..dda3bee59cc 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ChrFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ChrFunction.java @@ -28,10 +28,18 @@ import java.math.BigDecimal; /** - * ChrFunction - * description: chr(numeric)--returns the ASCII character having the binary equivalent to integer -**/ -@TransformFunction(names = {"chr"}) + * ChrFunction -> chr(integer) + * description: + * - Return NULL if 'integer' is NULL; + * - Return the ASCII character having the binary equivalent to 'integer'. + */ +@TransformFunction(names = {"chr"}, parameter = "(Integer integer)", descriptions = { + "- Return NULL if 'integer' is NULL;", + "- Return the ASCII character having the binary equivalent to 'integer'.", +}, examples = { + "chr(97) = \"a\"", + "chr(353) = \"a\"" +}) public class ChrFunction implements ValueParser { private ValueParser numberParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CosFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CosFunction.java index df49a2df2bc..7f8c886907d 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CosFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CosFunction.java @@ -23,36 +23,38 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Function; import java.math.BigDecimal; /** - * CosFunction - * description: cos(numeric)--returns the cosine of numeric + * CosFunction -> cos(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the cosine of 'numeric'. */ -@TransformFunction(names = {"cos"}) +@Slf4j +@TransformFunction(names = {"cos"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the cosine of 'numeric'." +}, examples = { + "cos(0) = 1.0" +}) public class CosFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public CosFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.cos(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CosdFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CosdFunction.java index f1b3068d571..06e2f954d97 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CosdFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CosdFunction.java @@ -23,15 +23,24 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Function; import java.math.BigDecimal; /** - * CosdFunction - * description: cosd(numeric)--returns the cosine of numeric in units of degrees + * CosdFunction -> cosd(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the cosine of 'numeric' in units of degrees. */ -@TransformFunction(names = {"cosd"}) +@Slf4j +@TransformFunction(names = {"cosd"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the cosine of 'numeric' in units of degrees." +}, examples = { + "cosd(15) = 0.9659258262890683" +}) public class CosdFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +52,9 @@ public CosdFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.cos(Math.toRadians(numberValue.doubleValue())); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CoshFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CoshFunction.java index 8bbfd548e50..c6ef2900be3 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CoshFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CoshFunction.java @@ -23,15 +23,26 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Function; import java.math.BigDecimal; /** - * CoshFunction - * description: cosh(numeric)--returns the hyperbolic cosine of numeric + * CoshFunction -> cosh(numeric) + * description: + * - Return NULL if 'numeric' is NULL'; + * - Return the hyperbolic cosine of 'numeric'. */ -@TransformFunction(names = {"cosh"}) +@Slf4j +@TransformFunction(names = {"cosh"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the hyperbolic cosine of 'numeric'." +}, examples = { + "cosh(1) = 1.543080634815244", + "cosh(0) = 1.0", + "cosh(-1) = 1.543080634815244" +}) public class CoshFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +54,9 @@ public CoshFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.cosh(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CotFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CotFunction.java index a4dbf7bad4e..9c7f16659c6 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CotFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CotFunction.java @@ -23,15 +23,26 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Function; import java.math.BigDecimal; /** - * CotFunction - * description: cot(numeric) -- returns the cotangent of the numeric (in radians) + * CotFunction -> cot(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the cotangent of the 'numeric' (in radians). */ -@TransformFunction(names = {"cot"}) +@Slf4j +@TransformFunction(names = {"cot"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the cotangent of the 'numeric' (in radians)." +}, examples = { + "cot(1) = 0.6420926159343306", + "cot(0.5) = 1.830487721712452", + "cot(-1) = -0.6420926159343306" +}) public class CotFunction implements ValueParser { private final ValueParser valueParser; @@ -43,7 +54,9 @@ public CotFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object valueObj = valueParser.parse(sourceData, rowIndex, context); - + if (valueObj == null) { + return null; + } BigDecimal value = OperatorTools.parseBigDecimal(valueObj); // Calculate tan(x) and take the inverse to find cot(x) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CotdFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CotdFunction.java index f9b5ff85c27..a0083aadd82 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CotdFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/CotdFunction.java @@ -23,15 +23,26 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Function; import java.math.BigDecimal; /** - * CotdFunction - * description: cotd(numeric)--returns the cotangent of numeric in units of degrees + * CotdFunction -> cotd(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the cotangent of 'numeric' in units of degrees. */ -@TransformFunction(names = {"cotd"}) +@Slf4j +@TransformFunction(names = {"cotd"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if numeric is NULL;", + "- Return the cotangent of numeric in units of degrees." +}, examples = { + "cotd(0) = \"\"", + "cotd(45) = 1.0000000000000002", + "cotd(-1) = -57.28996163075943" +}) public class CotdFunction implements ValueParser { private ValueParser numberParser; @@ -43,7 +54,9 @@ public CotdFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object valueObj = numberParser.parse(sourceData, rowIndex, context); - + if (valueObj == null) { + return null; + } BigDecimal value = OperatorTools.parseBigDecimal(valueObj); // Calculate tan(x) and take the inverse to find cot(x) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/EFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/EFunction.java index 0d648e4c2a2..4e226067f0b 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/EFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/EFunction.java @@ -25,10 +25,15 @@ import net.sf.jsqlparser.expression.Function; /** - * EFunction - * returns the mathematical constant E + * EFunction -> E() + * Description: + * - Return the mathematical constant. */ -@TransformFunction(names = {"e"}) +@TransformFunction(names = {"e"}, parameter = "()", descriptions = { + "- Return the mathematical constant." +}, examples = { + "e() = 2.718281828459045" +}) public class EFunction implements ValueParser { public EFunction(Function expr) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ErfFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ErfFunction.java index acbc48cc117..886f9957a96 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ErfFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ErfFunction.java @@ -27,12 +27,17 @@ import org.apache.commons.math3.special.Erf; /** - * ErfFunction -> erf(x) - * description: - * - return NULL if x is NULL. - * - return the error function value of the input value + * ErfFunction -> erf(numeric) + * Description: + * - Return NULL if 'numeric' is NULL; + * - Return the error function value of the input value. */ -@TransformFunction(names = {"erf"}) +@TransformFunction(names = {"erf"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the error function value of the input value." +}, examples = { + "erf(3) = 0.9999779095030014" +}) public class ErfFunction implements ValueParser { private final ValueParser numParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ErfcFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ErfcFunction.java index 1e43d14947b..0249355e85c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ErfcFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ErfcFunction.java @@ -27,12 +27,17 @@ import org.apache.commons.math3.special.Erf; /** - * ErfcFunction -> erfc(x) - * description: - * - return NULL if x is NULL. - * - return complementary error (1 - erf(x), without loss of precision for large inputs) + * ErfcFunction -> erfc(numeric) + * Description: + * - Return NULL if 'numeric' is NULL; + * - Return complementary error (1 - erf('numeric'), without loss of precision for large inputs). */ -@TransformFunction(names = {"erfc"}) +@TransformFunction(names = {"erfc"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return complementary error (1 - erf('numeric'), without loss of precision for large inputs)." +}, examples = { + "erfc(1) = 0.15729920705028488" +}) public class ErfcFunction implements ValueParser { private final ValueParser numParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ExpFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ExpFunction.java index 7a1eb57c983..9909d249be6 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ExpFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ExpFunction.java @@ -28,31 +28,31 @@ import java.math.BigDecimal; /** - * ExpFunction - * description: exp(numeric)--returns e raised to the power of numeric + * ExpFunction -> exp(numeric) + * Description: + * - Return NULL if 'numeric' is NULL; + * - Return e raised to the power of 'numeric'. */ -@TransformFunction(names = {"exp"}) +@TransformFunction(names = {"exp"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return e raised to the power of 'numeric'." +}, examples = { + "exp(2) = 7.38905609893065" +}) public class ExpFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public ExpFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.exp(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/FloorFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/FloorFunction.java index a7472b607a8..d7ea9249d75 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/FloorFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/FloorFunction.java @@ -28,31 +28,32 @@ import java.math.BigDecimal; /** - * FloorFunction - * description: floor(numeric)--rounds numeric down, and returns the largest number that is less than or equal to numeric + * FloorFunction -> floor(numeric) + * Description: + * - Return NULL if 'numeric' is NULL; + * - Return the largest number that is less than or equal to 'numeric'. */ -@TransformFunction(names = {"floor"}) +@TransformFunction(names = {"floor"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the largest number that is less than or equal to 'numeric'." +}, examples = { + "floor(1.23) = 1.0", + "floor(-5.67) = -6.0" +}) public class FloorFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public FloorFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.floor(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/GcdFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/GcdFunction.java index 21e4738f2c4..b7dc919d044 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/GcdFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/GcdFunction.java @@ -33,12 +33,18 @@ /** * GcdFunction -> gcd(numeric_type,numeric_type) * description: - * - return 0 if both inputs are zero; - * - return greatest common divisor (the largest positive number that divides both inputs with no remainder). - * Note: numeric_type includes floating-point number and integer + * - Return NULL if any parameter is null + * - Return 0 if both inputs are zero + * - Return greatest common divisor (the largest positive number that divides both inputs with no remainder). */ @Slf4j -@TransformFunction(names = {"gcd"}) +@TransformFunction(names = {"gcd"}, parameter = "(Numeric numeric1,Numeric numeric2)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return 0 if both inputs are zero;", + "- Return greatest common divisor (the largest positive number that divides both inputs with no remainder).", +}, examples = { + "gcd(3.141,3.846) = 0.003" +}) public class GcdFunction implements ValueParser { private final ValueParser firstNumParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/GreatestFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/GreatestFunction.java index d30e38a67e5..b842d93e49f 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/GreatestFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/GreatestFunction.java @@ -23,18 +23,27 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; + /** - * GreatestFunction - * description: GREATEST(value1[, value2]*)--Returns the greatest value of the list of arguments. - * Returns NULL if any argument is NULL. + * GreatestFunction -> GREATEST(value1[, value2, ...]) + * description: + * - Return NULL if any parameter is null + * - Return the greatest value of the list of arguments. */ -@TransformFunction(names = {"greatest"}) +@Slf4j +@TransformFunction(names = {"greatest"}, parameter = "(Numeric value1 [,Numeric value2,...])", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return the greatest value of the list of arguments." +}, examples = { + "greatest(3.141592653589793, 3, greatest(4, 1)) = 4" +}) public class GreatestFunction implements ValueParser { private List parserList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/HexFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/HexFunction.java index fbd335990e2..8f5925cd283 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/HexFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/HexFunction.java @@ -31,12 +31,19 @@ import java.util.regex.Pattern; /** - * HexFunction + * HexFunction -> hex(dataStr) * description: - * - If the input argument is a numeric value (such as an integer), the HEX function converts the value to the corresponding hexadecimal string. - * - If the input argument is a string, the HEX function converts each character in the string to its corresponding hexadecimal ASCII encoding and returns the hexadecimal representation of the entire string. + * - Return the string obtained by converting the dataStr to hexadecimal if 'dataStr' can be parsed into numeric + * - Return the string obtained by converting the ASCII code corresponding to each character to hexadecimal otherwise */ -@TransformFunction(names = {"hex"}) +@TransformFunction(names = {"hex"}, parameter = "(String dataStr)", descriptions = { + "- Return \"\" if dataStr is NULL;", + "- Return the string obtained by converting the dataStr to hexadecimal if 'dataStr' can be parsed into numeric;", + "- Return the string obtained by converting the ASCII code corresponding to each character to hexadecimal otherwise." +}, examples = { + "hex(1007) = \"3EF\"", + "hex('abc') = \"616263\"" +}) public class HexFunction implements ValueParser { private static final Pattern BIG_DECIMAL_PATTERN = Pattern.compile("^[-+]?\\d+(\\.\\d+)?([eE][-+]?\\d+)?$"); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LcmFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LcmFunction.java index fca459cc772..0c70dc5fbab 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LcmFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LcmFunction.java @@ -23,7 +23,6 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; -import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; @@ -33,14 +32,20 @@ import java.util.List; /** - * LcmFunction -> lcm(numeric_type,numeric_type) + * LcmFunction -> lcm(numeric1,numeric2) * description: - * - return 0 if either input is zero - * - return least common multiple (the smallest strictly positive number that is an integral multiple of both inputs) - * Note: numeric_type includes floating-point number and integer + * - Return NULL if any parameter is NULL + * - Return 0 if either input is zero + * - Return least common multiple (the smallest strictly positive number that is an integral multiple of both inputs) */ -@Slf4j -@TransformFunction(names = {"lcm"}) +@TransformFunction(names = {"lcm"}, parameter = "(Numeric numeric1,Numeric numeric2)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return 0 if either input is zero;", + "- Return least common multiple (the smallest strictly positive number that is an integral multiple of both inputs)." +}, examples = { + "lcm(6,3) = 6", + "lcm(3.141,3.846) = 4026.762" +}) public class LcmFunction implements ValueParser { private final ValueParser firstNumParser; @@ -59,14 +64,9 @@ public Object parse(SourceData sourceData, int rowIndex, Context context) { if (firstNumObj == null || secondNumObj == null) { return null; } - try { - BigDecimal firstNum = OperatorTools.parseBigDecimal(firstNumObj); - BigDecimal secondNum = OperatorTools.parseBigDecimal(secondNumObj); - return lcm(firstNum, secondNum).toPlainString(); - } catch (Exception e) { - log.error("Parse error", e); - return null; - } + BigDecimal firstNum = OperatorTools.parseBigDecimal(firstNumObj); + BigDecimal secondNum = OperatorTools.parseBigDecimal(secondNumObj); + return lcm(firstNum, secondNum).toPlainString(); } public static BigInteger gcd(BigDecimal a, BigDecimal b) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LeastFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LeastFunction.java index dde998815eb..57f473272b5 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LeastFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LeastFunction.java @@ -29,12 +29,19 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; + /** - * LeastFunction - * description: LEAST(value1[, value2]*)--Returns the least value of the list of arguments. - * Returns NULL if any argument is NULL. + * LeastFunction -> LEAST(value1[, value2, ...]) + * description: + * Return NULL if any argument is NULL. + * Return the least value of the list of arguments. */ -@TransformFunction(names = {"least"}) +@TransformFunction(names = {"least"}, parameter = "(Numeric value1 [, Numeric value2, ...])", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return the least value of the list of arguments." +}, examples = { + "least(3.14, least(7, 2, 1)) = 1" +}) public class LeastFunction implements ValueParser { private List parserList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LnFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LnFunction.java index 557b01ccf67..824ca10ab84 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LnFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LnFunction.java @@ -28,31 +28,31 @@ import java.math.BigDecimal; /** - * LnFunction - * description: ln(numeric)--returns the natural logarithm (base e) of numeric + * LnFunction -> ln(numeric) + * description: + * - Return NULL if numeric is NULL + * - Return the natural logarithm (base e) of numeric */ -@TransformFunction(names = {"ln"}) +@TransformFunction(names = {"ln"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if numeric is NULL;", + "- Return the natural logarithm (base e) of numeric." +}, examples = { + "ln(10) = 2.302585092994046" +}) public class LnFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public LnFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.log(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Log10Function.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Log10Function.java index 3f912bdc1e2..b23023df4a0 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Log10Function.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Log10Function.java @@ -28,31 +28,31 @@ import java.math.BigDecimal; /** - * Log10Function - * description: log10(numeric)--returns the base 10 logarithm of numeric + * Log10Function -> log10(numeric) + * description: + * - Return NULL if 'numeric' is NULL + * - Return the base 10 logarithm of 'numeric' */ -@TransformFunction(names = {"log10"}) +@TransformFunction(names = {"log10"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the base 10 logarithm of 'numeric'." +}, examples = { + "log10(1000) = 3.0" +}) public class Log10Function implements ValueParser { private final ValueParser numberParser; - /** - * Constructor - * @param expr - */ public Log10Function(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.log10(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Log2Function.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Log2Function.java index 7db9b9b7e64..891803918a9 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Log2Function.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/Log2Function.java @@ -28,31 +28,31 @@ import java.math.BigDecimal; /** - * Log2Function - * description: log2(numeric)--returns the base 2 logarithm of numeric + * Log2Function -> log2(numeric) + * description: + * - Return NULL if 'numeric' is NULL + * - Return the base 2 logarithm of 'numeric' */ -@TransformFunction(names = {"log2"}) +@TransformFunction(names = {"log2"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the base 2 logarithm of 'numeric'." +}, examples = { + "log2(32) = 5" +}) public class Log2Function implements ValueParser { private final ValueParser numberParser; - /** - * Constructor - * @param expr - */ public Log2Function(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.log(numberValue.doubleValue()) / Math.log(2); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LogFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LogFunction.java index cef7d79dae0..db731497f94 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LogFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/LogFunction.java @@ -30,20 +30,23 @@ import java.util.List; /** - * LogFunction - * description: log(numeric) or log(numeric1, numeric2)--When called with one argument, returns the natural logarithm - * of numeric. When called with two arguments, this function returns the logarithm of numeric2 to the base numeric1 + * LogFunction -> log(numeric1,[numeric2]) + * description: + * - Return the natural logarithm of 'numeric1' when called with one argument + * - Return the logarithm of 'numeric2' to the base 'numeric1' when called with two arguments */ -@TransformFunction(names = {"log"}) +@TransformFunction(names = {"log"}, parameter = "(Numeric numeric1 [, Numeric numeric2])", descriptions = { + "- Return the natural logarithm of 'numeric1' when called with one argument;", + "- Return the logarithm of 'numeric2' to the base 'numeric1' when called with two arguments." +}, examples = { + "log(1) = 0.0", + "log(2,8) = 3.0" +}) public class LogFunction implements ValueParser { private ValueParser baseParser; private final ValueParser numberParser; - /** - * Constructor - * @param expr - */ public LogFunction(Function expr) { List expressions = expr.getParameters().getExpressions(); // Determine the number of arguments and build parser @@ -55,12 +58,6 @@ public LogFunction(Function expr) { } } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/MinScaleFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/MinScaleFunction.java index ffaec3aafca..bdab65f009e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/MinScaleFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/MinScaleFunction.java @@ -31,10 +31,15 @@ /** * MinScaleFunction -> min_scale(numeric) * description: - * return NULL if numeric is NULL - * return minimum scale (number of fractional decimal digits) needed to represent the supplied value precisely + * - Return NULL if 'numeric' is NULL + * - Return minimum scale (number of fractional decimal digits) needed to represent the supplied value precisely */ -@TransformFunction(names = {"min_scale"}) +@TransformFunction(names = {"min_scale"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return minimum scale (number of fractional decimal digits) needed to represent the supplied value precisely." +}, examples = { + "min_scale(3.1415000000000) = 4" +}) public class MinScaleFunction implements ValueParser { private final ValueParser numParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ModuloFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ModuloFunction.java index 553dbeddd8d..30d8901a50d 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ModuloFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ModuloFunction.java @@ -30,10 +30,18 @@ import java.util.List; /** - * ModuloFunction - * description: MOD(NUMERIC1, NUMERIC2) : Return the remainder of numeric1 divided by numeric2. + * ModuloFunction -> MOD(NUMERIC1, NUMERIC2) + * description: + * - Return NULL if any parameter is null + * - Return the remainder of 'numeric1' divided by 'numeric2' */ -@TransformFunction(names = {"mod"}) +@TransformFunction(names = {"mod"}, parameter = "(Numeric numeric1, Numeric numeric2)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return the remainder of 'numeric1' divided by 'numeric2'." +}, examples = { + "mod(3,2) = 1", + "mod(-3.1415926,100) = -3.1415926" +}) public class ModuloFunction implements ValueParser { private ValueParser dividendParser; @@ -49,6 +57,9 @@ public ModuloFunction(Function expr) { public Object parse(SourceData sourceData, int rowIndex, Context context) { Object dividendObj = dividendParser.parse(sourceData, rowIndex, context); Object divisorObj = divisorParser.parse(sourceData, rowIndex, context); + if (divisorObj == null || dividendObj == null) { + return null; + } BigDecimal dividend = OperatorTools.parseBigDecimal(dividendObj); BigDecimal divisor = OperatorTools.parseBigDecimal(divisorObj); return dividend.remainder(divisor); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/NumNonNullsFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/NumNonNullsFunction.java index edc1a1668ca..509d013c57b 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/NumNonNullsFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/NumNonNullsFunction.java @@ -33,9 +33,13 @@ /** * NumNonNullsFunction -> num_nonnulls(expr1,expr2,...) * description: - * - return the number of non-null arguments. + * - Return the number of non-null arguments. */ -@TransformFunction(names = {"num_nonnulls"}) +@TransformFunction(names = {"num_nonnulls"}, parameter = "([Expr expr1, Expr expr2, ...])", descriptions = { + "- Return the number of non-null arguments." +}, examples = { + "num_nonnulls(5, 3, null, null) = 2" +}) public class NumNonNullsFunction implements ValueParser { private final List nodeList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/NumNullsFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/NumNullsFunction.java index 06707f54e32..d08f64a7af3 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/NumNullsFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/NumNullsFunction.java @@ -31,11 +31,15 @@ import java.util.List; /** - * NumNonNullsFunction -> num_nulls(expr1,expr2,...) + * NumNullsFunction -> num_nulls(expr1,expr2,...) * description: - * - return the number of null arguments. + * - Return the number of null arguments. */ -@TransformFunction(names = {"num_nulls"}) +@TransformFunction(names = {"num_nulls"}, parameter = "([Expr expr1, Expr expr2, ...])", descriptions = { + "- Return the number of null arguments." +}, examples = { + "num_nulls(5, null, null, null) = 3" +}) public class NumNullsFunction implements ValueParser { private final List nodeList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/PiFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/PiFunction.java index 2cc7043f514..909df62f4da 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/PiFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/PiFunction.java @@ -24,10 +24,15 @@ import net.sf.jsqlparser.expression.Function; /** - * PiFunction - * returns the mathematical constant PI + * PiFunction -> pi() + * description: + * - Return the mathematical constant PI */ -@TransformFunction(names = {"pi"}) +@TransformFunction(names = {"pi"}, parameter = "()", descriptions = { + "- Return the mathematical constant PI." +}, examples = { + "pi() = 3.141592653589793" +}) public class PiFunction implements ValueParser { public PiFunction(Function expr) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/PowerFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/PowerFunction.java index f34413a03de..30a7b93db23 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/PowerFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/PowerFunction.java @@ -28,34 +28,34 @@ import java.math.BigDecimal; /** - * PowerFunction - * description: power(numeric1, numeric2)--returns numeric1.power(numeric2) + * PowerFunction -> power(numeric1, numeric2) + * description: + * - Return NULL if any parameter is NULL + * - Return 'numeric1'.power('numeric2') */ -@TransformFunction(names = {"power"}) +@TransformFunction(names = {"power"}, parameter = "(Numeric numeric1, Numeric numeric2)", descriptions = { + "- Return \"\" if any parameter is NULL.", + "- Return 'numeric1'.power('numeric2')." +}, examples = { + "power(4,0.5) = 2.0" +}) public class PowerFunction implements ValueParser { private ValueParser baseParser; private ValueParser exponentParser; - /** - * Constructor - * @param expr - */ public PowerFunction(Function expr) { baseParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); exponentParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(1)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object baseObj = baseParser.parse(sourceData, rowIndex, context); Object exponentObj = exponentParser.parse(sourceData, rowIndex, context); + if (baseObj == null || exponentObj == null) { + return null; + } BigDecimal baseValue = OperatorTools.parseBigDecimal(baseObj); BigDecimal exponentValue = OperatorTools.parseBigDecimal(exponentObj); return Math.pow(baseValue.doubleValue(), exponentValue.doubleValue()); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RadiansFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RadiansFunction.java index 955835bea26..8121baa9208 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RadiansFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RadiansFunction.java @@ -26,11 +26,17 @@ import net.sf.jsqlparser.expression.Function; /** - * RadiansFunction + * RadiansFunction -> RADIANS(x) * description: - * - RADIANS(x)--returns radians of x, Convert degrees to radians + * - Return NULL if x is NULL + * - Return radians of x, Convert degrees to radians */ -@TransformFunction(names = {"radians"}) +@TransformFunction(names = {"radians"}, parameter = "(Numeric x)", descriptions = { + "- Return \"\" if 'x' is NULL;", + "- Return radians of 'x', Convert degrees to radians." +}, examples = { + "radians(18.97) = 0.33108895910332425" +}) public class RadiansFunction implements ValueParser { private ValueParser degreeParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RadixConvertFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RadixConvertFunction.java index c2b28da01c1..ac5c85bb8ac 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RadixConvertFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RadixConvertFunction.java @@ -23,7 +23,6 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; -import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; @@ -31,15 +30,21 @@ import java.util.List; /** - * RadixConvertFunction -> radix_convert(N,from_base,to_base) - * description: Converts numbers between different number bases. The minimum base is 2 and the maximum base is 36. - * If from_base is a negative number, N is regarded as a signed number. Otherwise, N is treated as - * unsigned. This function works with 64-bit precision. - * - returns NULL if any of its arguments are NULL. - * - returns conversion results otherwise. + * RadixConvertFunction -> radix_convert(numeric,from_base,to_base) + * description: + * - Return NULL if any of its arguments are NULL + * - Return the result of converting 'numeric' from 'from_base' to 'to_base' + * Note: abs(base) between [2,36].'from_base' is a negative number, 'numeric' is regarded as a signed number. + * Otherwise, 'numeric' is treated as unsigned. This function works with 64-bit precision. */ -@Slf4j -@TransformFunction(names = {"radix_convert"}) +@TransformFunction(names = {"radix_convert"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if any of its arguments are NULL;", + "- Return the result of converting 'numeric' from 'from_base' to 'to_base'.", + "Note: abs(base) between [2,36].'from_base' is a negative number, 'numeric' is regarded as a signed number." + + "Otherwise, 'numeric' is treated as unsigned. This function works with 64-bit precision." +}, examples = { + "radix_convert('6E',18,8) = 172" +}) public class RadixConvertFunction implements ValueParser { private final ValueParser numParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RandFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RandFunction.java index 2a11792493b..f915ac35308 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RandFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RandFunction.java @@ -31,11 +31,17 @@ import java.util.Random; /** - * RandFunction - * description: Rand()--Returns a pseudo-random double precision value in the range [0.0, 1.0) - * Rand(Integer)--Returns a pseudo-random double precision value in the range [0.0, 1.0) with an initial seed of Integer. + * RandFunction -> Rand([seed]) + * description: + * - Return a pseudo-random double precision value in the range [0.0, 1.0) if seed is NULL + * - Return a pseudo-random double precision value in the range [0.0, 1.0) with an initial seed of Integer */ -@TransformFunction(names = {"rand"}) +@TransformFunction(names = {"rand"}, parameter = "(Integer seed)", descriptions = { + "- Return a pseudo-random double precision value in the range [0.0, 1.0) if seed is NULL;", + "- Return a pseudo-random double precision value in the range [0.0, 1.0) with an initial 'seed' of Integer." +}, examples = { + "rand(1)", "rand()" +}) public class RandFunction implements ValueParser { private ValueParser seedParser; @@ -51,6 +57,7 @@ public RandFunction(Function expr) { } } } + @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { if (seedParser != null) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RandIntegerFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RandIntegerFunction.java index af3177358a5..067ce4e64a5 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RandIntegerFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RandIntegerFunction.java @@ -30,12 +30,19 @@ import java.util.Random; /** - * RandIntegerFunction - * description: RAND_INTEGER(INT1)--Returns a pseudorandom integer value in the range [0, INT) - * RAND_INTEGER(INT1, INT2)--Returns a pseudorandom integer value in the range [0, INT1) with an initial seed INT2. - * Two RAND_INTEGER functions will return idential sequences of numbers if they have the same initial seed and bound. + * RandIntegerFunction -> rand_integer(INT1[, INT2]) + * description: + * - Return a pseudorandom integer value in the range [0, 'INT1') if 'INT2' is NULL + * - Return a pseudorandom integer value in the range [0, 'INT1') with an initial seed 'INT2' + * Note: Two RAND_INTEGER functions will return idential sequences of numbers if they have the same initial seed and bound. */ -@TransformFunction(names = {"rand_integer"}) +@TransformFunction(names = {"rand_integer"}, parameter = "(Integer INT1, [Integer INT2])", descriptions = { + "- Return a pseudorandom integer value in the range [0, 'INT1') if 'INT2' is NULL;", + "- Return a pseudorandom integer value in the range [0, 'INT1') with an initial seed 'INT2'.", + "Note: Two RAND_INTEGER functions will return idential sequences of numbers if they have the same initial seed and bound." +}, examples = { + "rand_integer(10)", "rand_integer(88, 89)" +}) public class RandIntegerFunction implements ValueParser { private ValueParser firstIntParser; @@ -54,6 +61,7 @@ public RandIntegerFunction(Function expr) { } } } + @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object firstIntObj = firstIntParser.parse(sourceData, rowIndex, context); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RoundFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RoundFunction.java index 3b077596ed5..d5ef19d7485 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RoundFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/RoundFunction.java @@ -31,10 +31,19 @@ import java.util.List; /** - * RoundFunction - * description: ROUND(x [,y]) -- Return the nearest integer to x, with optional parameter y indicating the number of decimal places to be rounded. If omitted, return the integer. + * RoundFunction -> ROUND(x [,y]) + * description: + * - Return NULL if 'x' is NULL + * - Return the nearest integer to 'x', with optional parameter 'y' indicating the number of decimal places to be rounded */ -@TransformFunction(names = {"round"}) +@TransformFunction(names = {"round"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'x' is NULL;", + "- Return the nearest integer to 'x', with optional parameter 'y' indicating the number of decimal " + + "places to be rounded." +}, examples = { + "round(3.5) = 4", + "round(3.14159265358979323846,10) = 3.1415926536" +}) public class RoundFunction implements ValueParser { private ValueParser numberParser; @@ -51,6 +60,9 @@ public RoundFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal number = OperatorTools.parseBigDecimal(numberObj); if (reservedDigitsParser != null) { Object reservedDigitsObj = reservedDigitsParser.parse(sourceData, rowIndex, context); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ScaleFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ScaleFunction.java index 3d72a97c170..739b956725e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ScaleFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/ScaleFunction.java @@ -31,10 +31,15 @@ /** * ScaleFunction -> scale(numeric) * description: - * return NULL if numeric is NULL - * return scale of the argument (the number of decimal digits in the fractional part) + * - Return NULL if 'numeric' is NULL + * - Return scale of the argument (the number of decimal digits in the fractional part) */ -@TransformFunction(names = {"scale"}) +@TransformFunction(names = {"scale"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return scale of the argument (the number of decimal digits in the fractional part)." +}, examples = { + "scale(3.1415000000000) = 13" +}) public class ScaleFunction implements ValueParser { private final ValueParser numParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SignFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SignFunction.java index b8d01c94db0..222fb767e00 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SignFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SignFunction.java @@ -28,10 +28,21 @@ import java.math.BigDecimal; /** - * SignFunction - * description: sign(x): Return the sign of x, where x is a negative number, 0, and positive numbers return -1, 0, and 1, respectively + * SignFunction -> sign(x) + * description: + * - Return NULL if 'x' is NULL + * - Return -1 if 'x' is a negative number + * - Return 0 if 'x' is equal to 0 + * - Return 1 if 'x' is a positive number */ -@TransformFunction(names = {"sign"}) +@TransformFunction(names = {"sign"}, parameter = "(Numeric x)", descriptions = { + "- Return \"\" if 'x' is NULL;", + "- Return -1 if 'x' is a negative number;", + "- Return 0 if 'x' is equal to 0;", + "- Return 1 if 'x' is a positive number." +}, examples = { + "sign(-3.5) = -1" +}) public class SignFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +54,9 @@ public SignFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); double value = numberValue.doubleValue(); if (value > 0) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SinFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SinFunction.java index b2182b526c7..744c6bdbeda 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SinFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SinFunction.java @@ -28,31 +28,31 @@ import java.math.BigDecimal; /** - * SinFunction - * description: sin(numeric)--returns the sine of numeric + * SinFunction -> sin(numeric) + * description: + * - Return NULL if 'numeric' is NULL + * - Return the sine of 'numeric' */ -@TransformFunction(names = {"sin"}) +@TransformFunction(names = {"sin"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the sine of 'numeric'." +}, examples = { + "sin(0) = 0.0" +}) public class SinFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public SinFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.sin(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SindFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SindFunction.java index 685a0c31b7d..134d865a16f 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SindFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SindFunction.java @@ -28,10 +28,17 @@ import java.math.BigDecimal; /** - * SindFunction - * description: sind(numeric)--returns the sine of numeric in units of degrees + * SindFunction -> sind(numeric) + * description: + * - Return NULL if 'numeric' is NULL + * - Return the sine of 'numeric' in units of degrees */ -@TransformFunction(names = {"sind"}) +@TransformFunction(names = {"sind"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the sine of 'numeric' in units of degrees." +}, examples = { + "sind(15) = 0.25881904510252074" +}) public class SindFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +50,9 @@ public SindFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.sin(Math.toRadians(numberValue.doubleValue())); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SinhFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SinhFunction.java index 54c8857a416..87a73fd08ec 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SinhFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SinhFunction.java @@ -28,31 +28,31 @@ import java.math.BigDecimal; /** - * SinhFunction - * description: sinh(numeric)--returns the hyperbolic sine of numeric + * SinhFunction -> sinh(numeric) + * description: + * - Return NULL if 'numeric' is NULL + * - Return the hyperbolic sine of 'numeric' */ -@TransformFunction(names = {"sinh"}) +@TransformFunction(names = {"sinh"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the hyperbolic sine of 'numeric'." +}, examples = { + "sinh(1) = 1.1752011936438014" +}) public class SinhFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public SinhFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.sinh(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SqrtFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SqrtFunction.java index 548d4e8934b..fd6336356dd 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SqrtFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/SqrtFunction.java @@ -28,31 +28,31 @@ import java.math.BigDecimal; /** - * SqrtFunction - * description: sqrt(numeric)--returns the square root of numeric + * SqrtFunction -> sqrt(numeric) + * description: + * - Return NULL if 'numeric' is NULL + * - Return the square root of 'numeric' */ -@TransformFunction(names = {"sqrt"}) +@TransformFunction(names = {"sqrt"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the square root of 'numeric'." +}, examples = { + "sqrt(9) = 3.0" +}) public class SqrtFunction implements ValueParser { private ValueParser numberParser; - /** - * Constructor - * @param expr - */ public SqrtFunction(Function expr) { numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.sqrt(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TanFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TanFunction.java index f472b987243..c6eb3746616 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TanFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TanFunction.java @@ -26,11 +26,19 @@ import net.sf.jsqlparser.expression.Function; import java.math.BigDecimal; + /** - * TanFunction - * description: tan(numeric)--returns the tangent of numeric + * TanFunction -> tan(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the tangent of 'numeric'. */ -@TransformFunction(names = {"tan"}) +@TransformFunction(names = {"tan"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the tangent of 'numeric'." +}, examples = { + "tan(1) = 1.5574077246549023" +}) public class TanFunction implements ValueParser { private ValueParser numberParser; @@ -42,6 +50,9 @@ public TanFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.tan(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TandFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TandFunction.java index aee5c3cab0f..21c1c175d29 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TandFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TandFunction.java @@ -28,10 +28,17 @@ import java.math.BigDecimal; /** - * TandFunction - * description: tand(numeric)--returns the tangent of numeric in units of degrees + * TandFunction -> tand(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the tangent of 'numeric' in units of degrees. */ -@TransformFunction(names = {"tand"}) +@TransformFunction(names = {"tand"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the tangent of 'numeric' in units of degrees." +}, examples = { + "tand(15) = 0.2679491924311227" +}) public class TandFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +50,9 @@ public TandFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.tan(Math.toRadians(numberValue.doubleValue())); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TanhFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TanhFunction.java index ba307d90fc9..02f5fcea992 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TanhFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TanhFunction.java @@ -28,10 +28,17 @@ import java.math.BigDecimal; /** - * TanhFunction - * description: tanh(numeric)--returns the hyperbolic tangent of numeric + * TanhFunction -> tanh(numeric) + * description: + * - Return NULL if 'numeric' is NULL; + * - Return the hyperbolic tangent of 'numeric'. */ -@TransformFunction(names = {"tanh"}) +@TransformFunction(names = {"tanh"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the hyperbolic tangent of 'numeric'." +}, examples = { + "tanh(1) = 0.7615941559557649" +}) public class TanhFunction implements ValueParser { private ValueParser numberParser; @@ -43,6 +50,9 @@ public TanhFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object numberObj = numberParser.parse(sourceData, rowIndex, context); + if (numberObj == null) { + return null; + } BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); return Math.tanh(numberValue.doubleValue()); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TrimScaleFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TrimScaleFunction.java index 7a098dea33e..0ebaf5cf85f 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TrimScaleFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TrimScaleFunction.java @@ -31,10 +31,15 @@ /** * TrimScaleFunction -> trim_scale(numeric) * description: - * return NULL if numeric is NULL - * return the result of reducing the proportion of values (decimal places) by removing trailing zeros + * - Return NULL if 'numeric' is NULL; + * - Return the result of reducing the proportion of values (decimal places) by removing trailing zeros */ -@TransformFunction(names = {"trim_scale"}) +@TransformFunction(names = {"trim_scale"}, parameter = "(Numeric numeric)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return the result of reducing the proportion of values (decimal places) by removing trailing zeros." +}, examples = { + "trim_scale(3.1415000000000) = 3.1415" +}) public class TrimScaleFunction implements ValueParser { private final ValueParser numParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TruncateFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TruncateFunction.java index 4212a3d716c..777826cd58c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TruncateFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TruncateFunction.java @@ -30,17 +30,18 @@ import java.math.RoundingMode; import java.util.List; /** - * TruncateFunction - * description: returns the number that intercepts integer2 decimal places. - * If numeric1 or integer2 is NULL, NULL is returned. - * If integer2 is 0, the result has no decimal point or fractional part. - * integer2 can be negative, making the integer2 digit to the left of the decimal point of the value zero. - * This function can also be used by passing only one numeric1 argument without setting Integer2. - * If Integer2 is not set, Integer2 is 0 - * for example: truncate(42.324, 2)--return 42.32 - * truncate(42.324)--return 42.0 + * TruncateFunction -> truncate(numeric, cnt) + * description: + * - Return NULL if any parameter is NULL; + * - Return the result of truncating 'numeric' values to 'cnt' decimal places. */ -@TransformFunction(names = {"truncate", "trunc"}) +@TransformFunction(names = {"truncate", "trunc"}, parameter = "(Numeric numeric, Integer cnt)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return the result of truncating 'numeric' values to 'cnt' decimal places." +}, examples = { + "truncate(42.324, 2) = 42.32", + "trunc(42.324, -1) = 40" +}) public class TruncateFunction implements ValueParser { private ValueParser bigDecimalParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayAppendFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayAppendFunction.java index 055aaef7bc7..c19b7c05648 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayAppendFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayAppendFunction.java @@ -27,13 +27,17 @@ import java.util.ArrayList; /** - * ArrayAppendFunction - * description: ARRAY_APPEND(array, element)--Appends an element to the end of the array and returns the result. - * If the array itself is null, the function will return null. If an element to add is null, the null - * element will be added to the end of the array. - * for example: array_append(array('he',7,'xxd'), 'cloud')--return[he, 7, xxd, cloud] + * ArrayAppendFunction -> ARRAY_APPEND(array, element) + * description: + * - Return NULL if either argument is NULL + * - Return the result of appends an element to the end of the 'array' */ -@TransformFunction(names = {"array_append"}) +@TransformFunction(names = {"array_append"}, parameter = "(Array array, Object element)", descriptions = { + "- Return \"\" if either argument is NULL;", + "- Return the result of appends an element to the end of the 'array'." +}, examples = { + "array_append(array('he',7,'xxd'), 'cloud') = [he, 7, xxd, cloud]" +}) public class ArrayAppendFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayConcatFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayConcatFunction.java index 046bf4fb778..1dbae6715cf 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayConcatFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayConcatFunction.java @@ -29,13 +29,17 @@ import java.util.ArrayList; import java.util.List; /** - * ArrayConcatFunction - * description: ARRAY_CONCAT(array1, …)--Returns an array that is the result of concatenating at least one array. - * This array contains all the elements in the first array, followed by all the elements in the second - * array, and so forth, up to the Nth array. If any input array is NULL, the function returns NULL. - * for example: array_concat(array('he',7),array('xxd', 'cloud'))--return [he, 7, xxd, cloud] + * ArrayConcatFunction -> array_concat([array1,array2,...]) + * description: + * - Return NULL if any input array is NULL + * - Return an array that is the result of concatenating at least one array. */ -@TransformFunction(names = {"array_concat"}) +@TransformFunction(names = {"array_concat"}, parameter = "([Array array1, Array array2, ...])", descriptions = { + "- Return \"\" if any input array is NULL;", + "- Return an array that is the result of concatenating at least one array." +}, examples = { + "array_concat(array('he',7),array('xxd', 'cloud')) = [he, 7, xxd, cloud]" +}) public class ArrayConcatFunction implements ValueParser { private List parserList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayContainsFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayContainsFunction.java index f583ced4acc..63bf0978a90 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayContainsFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayContainsFunction.java @@ -26,14 +26,22 @@ import net.sf.jsqlparser.expression.Function; import java.util.ArrayList; + /** - * ArrayContainsFunction - * description: ARRAY_CONTAINS(haystack, needle)--Returns whether the given element exists in an array. Checking for - * null elements in the array is supported. If the array itself is null, the function will return null. - * for example: array_contains(array('he',7,'xxd'), 'cloud')--return false - * array_contains(array('he',-1,''),'')--return true + * ArrayContainsFunction -> array_contains(haystack, needle) + * description: + * - Return NULL if the array itself is null + * - Return whether the given element exists in an array. + * Note: Checking for null elements in the array is supported. */ -@TransformFunction(names = {"array_contains"}) +@TransformFunction(names = {"array_contains"}, parameter = "(Array array, Object needle)", descriptions = { + "- Return \"\" if 'array' is NULL;", + "- Return whether the given element exists in 'array'.", + "Note: Checking for null elements in the array is supported." +}, examples = { + "array_contains(array('he',7,'xxd'), 'cloud') = false", + "array_contains(array('he',-1,''),'') = true" +}) public class ArrayContainsFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayDistinctFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayDistinctFunction.java index d601d531df1..c88066a02bb 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayDistinctFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayDistinctFunction.java @@ -28,13 +28,19 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Set; + /** - * ArrayDistinctFunction - * description: ARRAY_DISTINCT(haystack)--Returns an array with unique elements. If the array itself is null, - * the function will return null. Keeps ordering of elements. - * for example: array_distinct(array('he',-1,'he'))--return [he, -1] + * ArrayDistinctFunction -> ARRAY_DISTINCT(array) + * description: + * - Return NULL if 'array' is null + * - Return an array with unique elements. */ -@TransformFunction(names = {"array_distinct"}) +@TransformFunction(names = {"array_distinct"}, parameter = "(Array array)", descriptions = { + "- Return \"\" if 'array' is NULL;", + "- Return an array with unique elements.", +}, examples = { + "array_distinct(array('he',-1,'he')) = [he, -1]" +}) public class ArrayDistinctFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayExceptFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayExceptFunction.java index 2ca0f7e3cd2..70f9d98ada4 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayExceptFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayExceptFunction.java @@ -29,15 +29,20 @@ import java.util.LinkedHashSet; import java.util.Set; /** - * ArrayExceptFunction - * description: ARRAY_EXCEPT(array1, array2)--Returns an ARRAY that contains the elements from array1 that are not in - * array2, without duplicates. If no elements remain after excluding the elements in array2 from array1, - * the function returns an empty ARRAY. If one or both arguments are NULL, the function returns NULL. - * The order of the elements from array1 is kept. - * for example: array_except(array('he',7,'xxd'),array('he'))--return [7, xxd] - * array_except(array('he',7,'xxd'),array('cloud'))--return [he, 7, xxd] + * ArrayExceptFunction -> ARRAY_EXCEPT(array1, array2) + * description: + * - Return NULL if any parameter is null; + * - Return an ARRAY that contains the elements from 'array1' that are not in 'array2', without duplicates; + * - Return an empty ARRAY if no elements remain after excluding the elements in 'array2' from 'array1'. */ -@TransformFunction(names = {"array_except"}) +@TransformFunction(names = {"array_except"}, parameter = "(Array array1, Array array2)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return an ARRAY that contains the elements from 'array1' that are not in 'array2', without duplicates;", + "- Return an empty ARRAY if no elements remain after excluding the elements in 'array2' from 'array1'." +}, examples = { + "array_except(array('he',7,'xxd'),array('he')) = [7, xxd]", + "array_except(array('he',7,'xxd'),array('cloud')) = [he, 7, xxd]" +}) public class ArrayExceptFunction implements ValueParser { private final ValueParser leftArrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayFunction.java index 2c8051f7193..509f24bf608 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayFunction.java @@ -28,14 +28,19 @@ import java.util.ArrayList; import java.util.List; + /** - * ArrayFunction - * description: ARRAY(ANY1, ANY2, ...)--Returns an array created from a list of values (value1, value2, …). - * for example: array('he',7,'xxd')--return [he, 7, xxd] - * array(array('he',5),'xxd')--return [[he, 5], xxd] - * array(array('he',5),array('',''))--return [[he, 5], [, ]] + * ArrayFunction -> ARRAY(ANY1, ANY2, ...) + * description: + * - Return an array created from a list of values (value1, value2, …) */ -@TransformFunction(names = {"array"}) +@TransformFunction(names = {"array"}, parameter = "(String value1 [,String value2, ....])", descriptions = { + "- Return an array created from a list of values ('value1', 'value2', ....)." +}, examples = { + "array('he',7,'xxd') = [he, 7, xxd]", + "array(array('he',5),'xxd') = return [[he, 5], xxd]", + "array(array('he',5),array('','')) = return [[he, 5], [, ]]" +}) public class ArrayFunction implements ValueParser { private List parserList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayIntersectFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayIntersectFunction.java index b123fedeab5..945813f9d49 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayIntersectFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayIntersectFunction.java @@ -29,16 +29,22 @@ import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.Collectors; + /** - * ArrayIntersectFunction - * description: ARRAY_INTERSECT(array1, array2)--Returns an ARRAY that contains the elements from array1 that are also - * in array2, without duplicates. If no elements that are both in array1 and array2, the function returns - * an empty ARRAY. If any of the array is null, the function will return null. The order of the elements - * from array1 is kept. - * for example: array_intersect(array('he',7,'xxd'),array('he'))--return [he] - * array_intersect(array('he',7,'xxd'),array('cloud'))--return [] + * ArrayIntersectFunction -> ARRAY_INTERSECT(array1, array2) + * description: + * - Return NULL if any parameter is null; + * - Return an ARRAY that contains the elements from 'array1' that are also in 'array2', without duplicates. + * - Return an empty ARRAY if no elements that are both in 'array1' and 'array2'. */ -@TransformFunction(names = {"array_intersect"}) +@TransformFunction(names = {"array_intersect"}, parameter = "(Array array1, Array array2)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return an ARRAY that contains the elements from 'array1' that are not in 'array2', without duplicates;", + "- Return an empty ARRAY if no elements remain after excluding the elements in 'array2' from 'array1'." +}, examples = { + "array_intersect(array('he',7,'xxd'),array('he')) = [he]", + "array_intersect(array('he',7,'xxd'),array('cloud')) = []" +}) public class ArrayIntersectFunction implements ValueParser { private final ValueParser leftArrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayJoinFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayJoinFunction.java index 9c0ebe02781..c42eb0875f1 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayJoinFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayJoinFunction.java @@ -29,17 +29,24 @@ import java.util.ArrayList; import java.util.List; /** - * ArrayJoinFunction - * description: ARRAY_JOIN(array, delimiter[, nullReplacement])--Returns a string that represents the concatenation of - * the elements in the given array and the elements’ data type in the given array is string. The delimiter - * is a string that separates each pair of consecutive elements of the array. The optional nullReplacement - * is a string that replaces null elements in the array. If nullReplacement is not specified, null elements - * in the array will be omitted from the resulting string. Returns null if input array or delimiter or - * nullReplacement are null. - * for example: array_join(array('he',7,'xxd'),'~')--return he~7~xxd - * array_join(array('he',3,''),'~','oo')--return he~3~oo + * ArrayJoinFunction -> ARRAY_JOIN(array, delimiter[, nullReplacement]) + * description: + * - Return NULL if any parameter is null; + * - Return a string indicating that the elements in the given 'array' are concatenated using 'delimiter', + * and empty array elements are filled with 'nullReplacement'. + * Note: If nullReplacement is not specified, null elements in the array will be omitted from the resulting string. */ -@TransformFunction(names = {"array_join"}) +@TransformFunction(names = { + "array_join"}, parameter = "(Array array, String delimiter[, String nullReplacement])", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return a string indicating that the elements in the given 'array' are concatenated using a 'delimiter', " + + + "and empty array elements are filled with 'nullReplacement'.", + "- Note: If nullReplacement is not specified, null elements in the array will be omitted from the resulting string." + }, examples = { + "array_join(array('he',7,'xxd'),'~') = he~7~xxd", + "array_join(array('he',3,''),'~','oo') = he~3~oo" + }) public class ArrayJoinFunction implements ValueParser { private ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayMaxFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayMaxFunction.java index 4fd075ccb8b..1d8641791fe 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayMaxFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayMaxFunction.java @@ -27,12 +27,17 @@ import java.util.ArrayList; /** - * ArrayMaxFunction - * description: ARRAY_MAX(array)--Returns the maximum value from the array, if array itself is null - * , the function returns null. - * for example: array_max(array(4,3,56))--return 56 + * ArrayMaxFunction -> ARRAY_MAX(array) + * description: + * - Return NULL if 'array' is null; + * - Return the maximum value from the 'array'. */ -@TransformFunction(names = {"array_max"}) +@TransformFunction(names = {"array_max"}, parameter = "(Array array)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return the maximum value from the 'array'." +}, examples = { + "array_max(array(4,3,56)) = 56" +}) public class ArrayMaxFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayMinFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayMinFunction.java index b0fcfb716d5..5b319b5adef 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayMinFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayMinFunction.java @@ -27,12 +27,17 @@ import java.util.ArrayList; /** - * ArrayMinFunction - * description: ARRAY_MIN(array)--Returns the minimum value from the array, if array itself is null - * , the function returns null. - * for example: array_max(array(4,3,56))--return 3 + * ArrayMaxFunction -> ARRAY_MIN(array) + * description: + * - Return NULL if 'array' is null; + * - Return the maximum value from the 'array'. */ -@TransformFunction(names = {"array_min"}) +@TransformFunction(names = {"array_min"}, parameter = "(Array array)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return the minimum value from the 'array'." +}, examples = { + "array_min(array(4,3,56)) = 3" +}) public class ArrayMinFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayPositionFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayPositionFunction.java index 08d9e3f7d85..7d8621c0d3c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayPositionFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayPositionFunction.java @@ -27,15 +27,20 @@ import java.util.ArrayList; /** - * ArrayPositionFunction - * description: ARRAY_POSITION(haystack, needle)--Returns the position of the first occurrence of element in the given - * array as int. Returns 0 if the given value could not be found in the array. Returns null if either of - * the arguments are null. And this is not zero based, but 1-based index. The first element in the array - * has index 1. - * for example: array_position(array('he',7,'xxd'),'he')--return 1 - * array_position(array('he',7,''),'_')--return 0 + * ArrayPositionFunction -> ARRAY_POSITION(array, element) + * description: + * - Return NULL if 'array' is null; + * - Return the position of the first occurrence of 'element' in the given 'array' as int; + * - Return 0 if the given value could not be found in the 'array'. */ -@TransformFunction(names = {"array_position"}) +@TransformFunction(names = {"array_position"}, parameter = "(Array array,Object element)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return the position of the first occurrence of 'element' in the given 'array' as int (starts from 1);", + "- Return 0 if the given value could not be found in the 'array'." +}, examples = { + "array_position(array('he',7,'xxd'),'he') = 1", + "array_position(array('he',7,''),'_') = 0" +}) public class ArrayPositionFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayPrependFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayPrependFunction.java index 5975195e817..0e75d5a6b12 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayPrependFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayPrependFunction.java @@ -29,13 +29,17 @@ import java.util.ArrayList; import java.util.List; /** - * ArrayPrependFunction - * description: ARRAY_PREPEND(array, element)--Appends an element to the beginning of the array and returns the result. - * If the array itself is null, the function will return null. If an element to add is null, the null - * element will be added to the beginning of the array. - * for example: array_prepend(array(4,3),3)--return [3, 4, 3] + * ArrayPrependFunction -> ARRAY_PREPEND(array, element) + * description: + * - Return NULL if 'array' is null; + * - Return the result of appending an element to the beginning of the array. */ -@TransformFunction(names = {"array_prepend"}) +@TransformFunction(names = {"array_prepend"}, parameter = "(Array array,Object element)", descriptions = { + "- Return \"\" if 'array' is null;", + "- Return the result of appending an element to the beginning of the array." +}, examples = { + "array_prepend(array(4,3),3) = [3, 4, 3]" +}) public class ArrayPrependFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayRemoveFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayRemoveFunction.java index bf86e7e6b3d..f4190354c7d 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayRemoveFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayRemoveFunction.java @@ -28,13 +28,19 @@ import java.util.ArrayList; import java.util.List; + /** - * ArrayRemoveFunction - * description: ARRAY_REMOVE(haystack, needle)--Removes all elements that equal to element from array. If the array - * itself is null, the function will return null. Keeps ordering of elements. - * for example: array_remove(array('he',7,'xxd'),'he')--return [7, xxd] + * ArrayRemoveFunction -> ARRAY_REMOVE(array, element) + * description: + * - Return NULL if 'array' is null; + * - Return the result of removing all elements that equal to 'element' from 'array'. */ -@TransformFunction(names = {"array_remove"}) +@TransformFunction(names = {"array_remove"}, parameter = "(Array array,Object element)", descriptions = { + "- Return \"\" if 'array' is null;", + "- Return the result of removing all elements that equal to 'element' from 'array'." +}, examples = { + "array_remove(array('he',7,'xxd'),'he') = [7, xxd]" +}) public class ArrayRemoveFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayReverseFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayReverseFunction.java index ad8d4fad618..1707f19e8f7 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayReverseFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayReverseFunction.java @@ -27,13 +27,19 @@ import java.util.ArrayList; import java.util.Collections; + /** - * ArrayReverseFunction - * description: ARRAY_REVERSE(haystack)--Returns an array in reverse order. If the array itself is null, - * the function will return null. - * for example: array_reverse(array('he',7,'xxd'))--return [xxd, 7, he] + * ArrayReverseFunction -> ARRAY_REVERSE(array, element) + * description: + * - Return NULL if 'array' is null; + * - Return an array in reverse order. */ -@TransformFunction(names = {"array_reverse"}) +@TransformFunction(names = {"array_reverse"}, parameter = "(Array array)", descriptions = { + "- Return \"\" if 'array' is null;", + "- Return an array in reverse order." +}, examples = { + "array_reverse(array('he',7,'xxd')) = [xxd, 7, he]" +}) public class ArrayReverseFunction implements ValueParser { private final ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArraySliceFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArraySliceFunction.java index 95151022f31..625fd5beffd 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArraySliceFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArraySliceFunction.java @@ -27,17 +27,25 @@ import java.util.ArrayList; /** - * ArraySliceFunction - * description: ARRAY_SLICE(array, start_offset[, end_offset])--Returns a subarray of the input array between - * ‘start_offset’ and ’end_offset’ inclusive. The offsets are 1-based however 0 is also treated as the - * beginning of the array. Positive values are counted from the beginning of the array while negative from - * the end. If ’end_offset’ is omitted then this offset is treated as the length of the array. If ‘ - * start_offset’ is after ’end_offset’ or both are out of array bounds an empty array will be returned. - * Returns null if any input is null. - * for example: array_slice(array('he',7,'xxd'),1,2)--return [he, 7] - * array_slice(array('he',3,'b'),-2,-1)--return [3, xxd] + * ArraySliceFunction -> ARRAY_SLICE(array, start_offset[, end_offset]) + * description: + * - Return NULL if 'array' or 'start_offset' is null; + * - Return a subarray of the input 'array' between 'start_offset' and 'end_offset' inclusive; + * - Return an empty array if 'start_offset' is after 'end_offset' or both are out of 'array' bounds. + * Note: If 'end_offset' is omitted then this offset is treated as the length of the 'array'. + * Positive values are counted from the beginning of the array while negative from the end. */ -@TransformFunction(names = {"array_slice"}) +@TransformFunction(names = { + "array_slice"}, parameter = "(Array array, Integer start_offset[, Integer end_offset])", descriptions = { + "- Return \"\" if 'array' or 'start_offset' is null;", + "- Return a subarray of the input 'array' between 'start_offset' and 'end_offset' inclusive;", + "- Return an empty array if 'start_offset' is after 'end_offset' or both are out of 'array' bounds.", + "Note: If 'end_offset' is omitted then this offset is treated as the length of the 'array'. " + + "Positive values are counted from the beginning of the array while negative from the end." + }, examples = { + "array_slice(array('he',7,'xxd'),1,2) = ['he', 7]", + "array_slice(array('he','xxd','b'),-2,-1) = [3, 'xxd']" + }) public class ArraySliceFunction implements ValueParser { private ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArraySortFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArraySortFunction.java index 73680c98d9a..7e68f18e00b 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArraySortFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArraySortFunction.java @@ -31,18 +31,32 @@ import java.util.Comparator; import java.util.List; /** - * ArraySortFunction - * description: ARRAY_SORT(array[, ascending_order[, null_first]])--Returns the array in sorted order.The function sorts - * an array, defaulting to ascending order with NULLs at the start when only the array is input. Specifying - * ascending_order as true orders the array in ascending with NULLs first, and setting it to false orders - * it in descending with NULLs last. Independently, null_first as true moves NULLs to the beginning, and - * as false to the end, irrespective of the sorting order. The function returns null if any input is null. - * for example: array_sort(array('he',7,'xxd'))--return [7, he, xxd] - * array_sort(array(3,7,5))--return [3, 5, 7] - * array_sort(array(,3,7),false,false)--return [7, 3, ] - * array_sort(array(3,7,),true,false)--return [3, 7, ] + * ArraySortFunction -> ARRAY_SORT(array[, ascending_order[, null_first]]) + * description: + * - Return NULL if 'array' is null; + * - Return the array in sorted order. + * Note: The function sorts an array, defaulting to ascending order with NULLs at the start when only the array is input. + * Specifying ascending_order as true orders the array in ascending with NULLs first, and setting it to false orders + * it in descending with NULLs last. Independently, null_first as true moves NULLs to the beginning, and as false + * to the end, irrespective of the sorting order. The function returns null if any input is null. */ -@TransformFunction(names = {"array_sort"}) +@TransformFunction(names = { + "array_sort"}, parameter = "(Array array[,Boolean ascending_order[,Boolean null_first]])", descriptions = { + "- Return \"\" if 'array' is null;", + "- Return the array in sorted order.", + "Note: The function sorts an array, defaulting to ascending order with NULLs at the start when only the array " + + + "is input. Specifying 'ascending_order' as true orders the array in ascending with NULLs first, and" + + + " setting it to false orders it in descending with NULLs last. Independently, 'null_first' as true " + + + "moves NULLs to the beginning, and as false to the end, irrespective of the sorting order." + }, examples = { + "array_sort(array('he',7,'xxd')) = [7, he, xxd]", + "array_sort(array(3,7,5)) = [3, 5, 7]", + "array_sort(array(,3,7),false,false) = [7, 3, ]", + "array_sort(array(3,7,),true,false) = [3, 7, ]" + }) public class ArraySortFunction implements ValueParser { private ValueParser arrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayUnionFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayUnionFunction.java index 4bf4d62cb07..82fd933d999 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayUnionFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ArrayUnionFunction.java @@ -28,14 +28,19 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Set; + /** - * ArrayConcatFunction - * description: ARRAY_CONCAT(array1, …)--Returns an array that is the result of concatenating at least one array. - * This array contains all the elements in the first array, followed by all the elements in the second - * array, and so forth, up to the Nth array. If any input array is NULL, the function returns NULL. - * for example: array_concat(array('he',7),array('xxd', 'cloud'))--return [he, 7, xxd, cloud] + * ArrayConcatFunction -> ARRAY_CONCAT([array1, ...]) + * description: + * - Return NULL if any input array is NULL; + * - Return an array that is the result of concatenating at least one array. */ -@TransformFunction(names = {"array_union"}) +@TransformFunction(names = {"array_union"}, parameter = "(Array array1[, Array array2, ...])", descriptions = { + "- Return \"\" if any input array is NULL;", + "- Return an array that is the result of concatenating at least one array." +}, examples = { + "array_concat(array('he',7),array('xxd', 'cloud')) = [he, 7, xxd, cloud]" +}) public class ArrayUnionFunction implements ValueParser { private final ValueParser leftArrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/CardinalityFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/CardinalityFunction.java index 9fbc4d7847c..a39ae111439 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/CardinalityFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/CardinalityFunction.java @@ -28,13 +28,20 @@ import java.util.ArrayList; import java.util.Map; /** - * CardinalityFunction - * description: CARDINALITY(array)--Returns the number of elements in array. - * CARDINALITY(map)--Returns the number of entries in map. - * for example: cardinality(array('he',7,'xxd'))--return 3 - * cardinality(map('he',7,'xxd',3))--return 2 + * CardinalityFunction -> CARDINALITY(array) or CARDINALITY(map) + * description: + * - Return NULL if the input is NULL; + * - Return the number of elements in array if the input is array. + * - Return the number of entries in map if the input is map. */ -@TransformFunction(names = {"cardinality"}) +@TransformFunction(names = {"cardinality"}, parameter = "(Object input)", descriptions = { + "- Return \"\" if the input is NULL;", + "- Return the number of elements in array if the input is array;", + "- Return the number of entries in map if the input is map." +}, examples = { + "cardinality(array('he',7,'xxd')) = 3", + "cardinality(map('he',7,'xxd',3)) = 2" +}) public class CardinalityFunction implements ValueParser { private final ValueParser valueParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ElementFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ElementFunction.java index c1c0d4493fa..e8842554b37 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ElementFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/ElementFunction.java @@ -28,13 +28,20 @@ import java.util.ArrayList; /** - * ElementFunction - * description: ELEMENT(array)--Returns the sole element of array (whose cardinality should be one); returns NULL if - * array is empty. Throws an exception if array has more than one element. - * for example: element(array('he'))--return he + * ElementFunction -> ELEMENT(array) + * description: + * - Return NULL if 'array' is empty or NULL; + * - Return the sole element of 'array' (whose cardinality should be one). + * Note: Throws an exception if array has more than one element. */ @Slf4j -@TransformFunction(names = {"element"}) +@TransformFunction(names = {"element"}, parameter = "(Array array)", descriptions = { + "- Return \"\" if 'array' is empty or NULL;", + "- Return the sole element of 'array' (whose cardinality should be one).", + "Note: Throws an exception if array has more than one element." +}, examples = { + "element(array('he')) = he" +}) public class ElementFunction implements ValueParser { private final ValueParser valueParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/FindInSetFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/FindInSetFunction.java index 1ecdcd63e86..94f7302887f 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/FindInSetFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/FindInSetFunction.java @@ -26,15 +26,25 @@ import net.sf.jsqlparser.expression.Function; /** - * LengthFunction -> FindInSetFunction(str,strList) - * description: - * - return a value in the range of 1 to N if the string str is in the string list strList consisting of N substrings. - * - return 0 if str is not in strList or if strList is the empty string. - * - return NULL if either argument is NULL. - * Note: `strList` is a string composed of substrings separated by ',' characters. This function does not work properly - * if the first argument contains a comma (,) character. + * FindInSetFunction -> FIND_IN_SET(str,strList) + * Description: + * - Return NULL if either argument is NULL + * - Return 0 if str is not in strList or if strList is the empty string + * - Return a value in the range of 1 to N if the string str is in the string list strList consisting of N substrings. + * Note: strList is a string composed of substrings separated by ',' characters. This function does not work properly + * if the first argument contains a comma (,) character. */ -@TransformFunction(names = {"find_in_set"}) +@TransformFunction(names = {"find_in_set"}, parameter = "(String str,String strList)", descriptions = { + "- Return \"\" if either argument is NULL;", + "- Return 0 if 'str' is not in 'strList' or if 'strList' is the empty string;", + "- Return a value in the range of 1 to N if the string 'str' is in the string list 'strList' consisting of N substrings.", + "Note: strList is a string composed of substrings separated by ',' characters. This function does not work properly" + + + "if the first argument contains a comma (,) character." +}, examples = { + "FIND_IN_SET('b','a,b,b,c,d') = 2", + "FIND_IN_SET('','a,,b,c,d') = 2" +}) public class FindInSetFunction implements ValueParser { private final ValueParser strParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapEntriesFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapEntriesFunction.java index 33d191441de..bf5d10b3f73 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapEntriesFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapEntriesFunction.java @@ -27,13 +27,20 @@ import java.util.Arrays; import java.util.Map; + /** - * MapEntriesFunction - * description: MAP_ENTRIES(map)--Returns an array of all entries in the given map. No order guaranteed. - * for example: map_entries(Map('he',1,'xxd','cloud'))--return [he=1, xxd=cloud] - * map_entries(Map(1,2,'cloud','xxd'))--return [xxd=cloud, 1=2] + * MapEntriesFunction -> MAP_ENTRIES(map) + * description: + * - Return NULL if mapStr is NULL + * - Return an array of all entries in the given map */ -@TransformFunction(names = {"map_entries"}) +@TransformFunction(names = {"map_entries"}, parameter = "(Map map)", descriptions = { + "- Return \"\" if 'map' is NULL;", + "- Return an array of all entries in the given 'map'." +}, examples = { + "map_entries(Map('he',1,'xxd','cloud')) = [he=1, xxd=cloud]", + "map_entries(Map(1,2,'cloud','xxd')) = [xxd=cloud, 1=2]" +}) public class MapEntriesFunction implements ValueParser { private final ValueParser mapParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapFromArraysFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapFromArraysFunction.java index 9e1d13eed67..2a0f953fd4e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapFromArraysFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapFromArraysFunction.java @@ -29,15 +29,22 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; + /** - * MapFromArraysFunction - * description: MAP_FROM_ARRAYS(array_of_keys, array_of_values)--Returns a map created from an arrays of keys and values. - * Note that the lengths of two arrays should be the same. - * for example: map_from_arrays(array('he', 'xxd'),array(1, 3))--return {he=1, xxd=3} - * map_from_arrays(array('xxd', array('cloud')),array(1, array(2)))--return {1=xxd, [2]=[cloud]} + * MapFromArraysFunction -> MAP_FROM_ARRAYS(array_of_keys, array_of_values) + * description: + * - Return NULL if any parameter is NULL + * - Return a map created from an arrays of keys and values */ @Slf4j -@TransformFunction(names = {"map_from_arrays"}) +@TransformFunction(names = { + "map_from_arrays"}, parameter = "(Array array_of_keys, Array array_of_values)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return a map created from an arrays of keys and values." + }, examples = { + "map_from_arrays(array('he', 'xxd'),array(1, 3)) = {he=1, xxd=3}", + "map_from_arrays(array('xxd', array('cloud')),array(1, array(2))) = {1=xxd, [2]=[cloud]}" + }) public class MapFromArraysFunction implements ValueParser { private ValueParser keyArrayParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapFunction.java index cba62fc85ea..400fabfb0c8 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapFunction.java @@ -30,15 +30,21 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + /** - * MapFunction - * description: MAP(ANY1, ANY2, ANY3, ANY4, ...)--Returns a map created from a list of - * key-value pairs ((value1, value2), (value3, value4), …). - * for example: Map('he',7,'xxd')--return null - * Map('he',1,'xxd','cloud')--return {he=1, xxd=cloud} - * Map('xxd','cloud',map(1,2),map(3,'apple'))--return {xxd=cloud, {1=2}={3=apple}} + * MapFunction -> MAP(value1, value2, ...) + * description: + * - Return NULL if the number of parameters is not even + * - Return a map created from a list of key-value pairs ((value1, value2), ... ) */ -@TransformFunction(names = {"map"}) +@TransformFunction(names = {"map"}, parameter = "([String value1, String value2, ...])", descriptions = { + "- Return \"\" if the number of parameters is not even;", + "- Return a map created from a list of key-value pairs ((value1, value2), ... )." +}, examples = { + "Map('he',7,'xxd') = null", + "Map('he',1,'xxd','cloud') = {he=1, xxd=cloud}", + "Map('xxd','cloud',map(1,2),map(3,'apple')) = {xxd=cloud, {1=2}={3=apple}}" +}) public class MapFunction implements ValueParser { private List parserList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapKeysFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapKeysFunction.java index 1628de29c1c..921f4a8b810 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapKeysFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapKeysFunction.java @@ -28,12 +28,18 @@ import java.util.Arrays; import java.util.Map; /** - * MapKeysFunction - * description: MAP_KEYS(map)--Returns the keys of the map as array. No order guaranteed. - * for example: map_keys(Map('he',1,'xxd','cloud'))--return [he, xxd] - * map_keys(Map('xxd','cloud',map(1,2),map(3,'apple')))--return [xxd, {1=2}] + * MapFunction -> MAP_KEYS(map) + * description: + * - Return NULL if map is NULL + * - Return the keys of the map as array. No order guaranteed. */ -@TransformFunction(names = {"map_keys"}) +@TransformFunction(names = {"map_keys"}, parameter = "(Map map)", descriptions = { + "- Return \"\" if 'map' is NULL;", + "- Return the keys of the 'map' as array. No order guaranteed." +}, examples = { + "map_keys(Map('he',1,'xxd','cloud')) = [he, xxd]", + "map_keys(Map('xxd','cloud',map(1,2),map(3,'apple'))) = [xxd, {1=2}]" +}) public class MapKeysFunction implements ValueParser { private final ValueParser mapParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapUnionFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapUnionFunction.java index 68bc55d4cfe..a5ac0f3ed54 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapUnionFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapUnionFunction.java @@ -31,15 +31,19 @@ import java.util.List; import java.util.Map; /** - * MapUnionFunction - * description: MAP_UNION(map1, …)--Returns a map created by merging at least one map. These maps should have a common - * map type. If there are overlapping keys, the value from ‘map2’ will overwrite the value from ‘map1’ - * , the value from ‘map3’ will overwrite the value from ‘map2’, the value from ‘mapn’ will overwrite - * the value from ‘map(n-1)’. If any of maps is null, return null. - * for example: map_union(map('he', 1),map('xxd', 3))--return {he=1, xxd=3} - * map_union(map('he', 1),map('he', 3))--return {he=3} + * MapUnionFunction -> MAP_UNION([map1, map2, ...]) + * description: + * - Return NULL if any of maps is null + * - Return a map created by merging at least one map.These maps should have a common map type,the following map will overwrite the previous one. */ -@TransformFunction(names = {"map_union"}) +@TransformFunction(names = {"map_union"}, parameter = "([Map map1, Map map2, ...])", descriptions = { + "- Return \"\" if any of maps is null;", + "- Return a map created by merging at least one map.These maps should have a common map type, " + + "the following map will overwrite the previous one." +}, examples = { + "map_union(map('he', 1),map('xxd', 3)) = {he=1, xxd=3}", + "map_union(map('he', 1),map('he', 3)) = {he=3}" +}) public class MapUnionFunction implements ValueParser { private List parserList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapValueFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapValueFunction.java index 493136e3393..9a1c56ac0bc 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapValueFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/collection/MapValueFunction.java @@ -28,12 +28,18 @@ import java.util.Arrays; import java.util.Map; /** - * MapValueFunction - * description: MAP_VALUES(map)--Returns the values of the map as array. No order guaranteed. - * for example: map_values(Map('he',1,'xxd','cloud'))--return [1, cloud] - * map_values(Map('xxd','cloud',map(1,2),map(3,'apple')))--return [cloud, {3=apple}] + * MapValueFunction -> MAP_VALUES(map) + * description: + * - Return NULL if map is null + * - Return the values of the map as array. No order guaranteed. */ -@TransformFunction(names = {"map_values"}) +@TransformFunction(names = {"map_values"}, parameter = "(Map map)", descriptions = { + "- Return \"\" if 'map' is null;", + "- Return the values of the 'map' as array. No order guaranteed." +}, examples = { + "map_values(Map('he',1,'xxd','cloud')) = [1, cloud]", + "map_values(Map('xxd','cloud',map(1,2),map(3,'apple'))) = [cloud, {3=apple}]" +}) public class MapValueFunction implements ValueParser { private final ValueParser mapParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/compression/CompressFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/compression/CompressFunction.java index 85e9ee19fc0..8a0c8c7036a 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/compression/CompressFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/compression/CompressFunction.java @@ -36,14 +36,28 @@ import java.util.List; /** - * CompressFunction - * description: compress(string_to_compress[,compress_type(default:deflater)]) - * - Return NULL if string_to_compress is NULL. - * - Return "" if string_to_compress is "". - * - Return the result as a binary string. + * CompressFunction -> compress(string_to_compress[,compress_type(default:deflater)]) + * description: + * - Return NULL if 'string_to_compress' is NULL + * - Return "" if 'string_to_compress' is "" + * - Return the result as a binary string + * Note: This function supports three compression algorithms: deflater, gzip and zip. 'compress_type' defaults to defer. + * In addition, in order to output the compressed results in the form of strings, this method uses the ISO_8859_1 + * character set. */ @Slf4j -@TransformFunction(names = {"compress"}) +@TransformFunction(names = { + "compress"}, parameter = "(String string_to_compress [, String compress_type])", descriptions = { + "- Return \"\" if 'string_to_compress' is NULL;", + "- Return \"\" if 'string_to_compress' is \"\";", + "- Return the result as a binary string.", + "Note: This function supports three compression algorithms: deflater, gzip, and zip. " + + "'compress_type' defaults to defer. In addition, in order to output the compressed " + + "results in the form of strings, this method uses the ISO_8859_1 character set." + }, examples = { + "length(compress(replicate(string1,100)),'ISO_8859_1') = 33", + "length(compress(''),'ISO_8859_1') = 0" + }) public class CompressFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/compression/UnCompressFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/compression/UnCompressFunction.java index 5411c7d5dea..9b7e087b6ce 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/compression/UnCompressFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/compression/UnCompressFunction.java @@ -35,14 +35,24 @@ import java.util.List; /** - * UnCompressFunction - * description: uncompress(string_to_uncompress[,compress_type(default:deflater)]) - * - Return NULL if string_to_uncompress is NULL. - * - Return "" if string_to_uncompress is "". + * UnCompressFunction -> uncompress(string_to_uncompress [,compress_type]) + * description: + * - Return NULL if 'string_to_uncompress' is NULL; + * - Return "" if 'string_to_uncompress' is ""; * - Return the result as a string. + * Note: This function supports three compression algorithms: deflater, gzip, and zip. compress_type defaults to defer. */ @Slf4j -@TransformFunction(names = {"uncompress"}) +@TransformFunction(names = { + "uncompress"}, parameter = "(String string_to_uncompress, String compress_type)", descriptions = { + "- Return \"\" if 'string_to_uncompress' is NULL;", + "- Return \"\" if 'string_to_uncompress' is \"\";", + "- Return the result as a string.", + "Note: This function supports three compression algorithms: deflater, gzip and zip. " + + "'compress_type' defaults to defer." + }, examples = { + "uncompress(compress('inlong')) = \"inlong\"" + }) public class UnCompressFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/CoalesceFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/CoalesceFunction.java index bf060243258..c10ba0e593f 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/CoalesceFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/CoalesceFunction.java @@ -33,14 +33,21 @@ import java.util.List; /** - * CoalesceFunction - * description: COALESCE(value1 [, value2]*)--Returns the first argument that is not NULL.If all arguments are NULL, - * it returns NULL as well. The return type is the least restrictive, common type of all of its arguments. - * The return type is nullable if all arguments are nullable as well. - * for example: COALESCE(f0, f1, 'default') -- Returns the first non-null value among f0 and f1, - * or 'default' if f0 and f1 are both NULL + * CoalesceFunction -> COALESCE(value1 [, value2, ...]) + * description: + * - Return the first argument that is not NULL + * - Return NULL If all arguments are NULL + * Note: The return type is the least restrictive, common type of all of its arguments. + * The return type is nullable if all arguments are nullable as well. */ -@TransformFunction(names = {"coalesce"}) +@TransformFunction(names = {"coalesce"}, parameter = "(String value1 [, String value2, ...])", descriptions = { + "- Return \"\" If all arguments are NULL or \"\";", + "- Return the first argument that is not NULL or \"\".", + "Note: The return type is the least restrictive, common type of all of its arguments." + + "The return type is nullable if all arguments are nullable as well." +}, examples = { + "coalesce('', 'SQL', 'hh') = \"SQL\"" +}) public class CoalesceFunction implements ValueParser { private List parserList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IfFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IfFunction.java index 12037293158..7a31e24243c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IfFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IfFunction.java @@ -30,10 +30,17 @@ import java.util.List; /** - * IfFunction - * description: if(expr,r1,r2) -- expr is an expression, if it holds, return r1; otherwise, return r2 + * IfFunction -> if(expr,r1,r2) + * description: + * - Return r1 if expr holds + * - Return r2 otherwise */ -@TransformFunction(names = {"if"}) +@TransformFunction(names = {"if"}, parameter = "(Expr expr1,Expr expr2,Expr expr3)", descriptions = { + "- Return 'expr2' if 'expr1' returns true;", + "- Return 'expr3' otherwise." +}, examples = { + "if(1 = 1,true,false) = true" +}) public class IfFunction implements ValueParser { private final ExpressionOperator expressionOperator; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IfNullFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IfNullFunction.java index 14ff346e882..77307694737 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IfNullFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IfNullFunction.java @@ -30,13 +30,19 @@ import java.util.List; /** - * IfNullFunction - * description: IFNULL(expr1,expr2) - * - return expr1 if expr1 is not NULL - * - return expr2 otherwise + * IfNullFunction -> IFNULL(expr1,expr2) + * description: + * - Return expr1 if expr1 is not NULL + * - Return expr2 otherwise */ @Slf4j -@TransformFunction(names = {"ifnull", "if_null"}) +@TransformFunction(names = {"ifnull", "if_null"}, parameter = "(Expr expr1,Expr expr2)", descriptions = { + "- Return 'expr1' if 'expr1' returns not NULL;", + "- Return 'expr2' otherwise." +}, examples = { + "ifnull(null, 3) = 3", + "ifnull(6,'YES') = 6" +}) public class IfNullFunction implements ValueParser { private final ValueParser firstExprParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IsNullFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IsNullFunction.java index ff5ae5e1066..395302646f8 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IsNullFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/IsNullFunction.java @@ -28,12 +28,18 @@ import net.sf.jsqlparser.expression.Function; /** - * IsNullFunction - * description: isnull(expr) + * IsNullFunction -> isnull(expr) + * description: * - return true if expr is NULL * - return false otherwise. */ -@TransformFunction(names = {"isnull"}) +@TransformFunction(names = {"isnull"}, parameter = "(Expr expr)", descriptions = { + "- Return true if 'expr' is NULL;", + "- Return false otherwise." +}, examples = { + "isnull(5 + 3) = false", + "isnull(5 / 0) = true" +}) public class IsNullFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/NullIfFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/NullIfFunction.java index d5be978d4f7..f346b124cd6 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/NullIfFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/condition/NullIfFunction.java @@ -23,20 +23,23 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; -import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; import java.util.List; /** - * NullIfFunction - * description: NULLIF(expr1,expr2) - * - return NULL if expr1 = expr2 is true - * - returns expr1 otherwise + * NullIfFunction -> NULLIF(expr1,expr2) + * description: + * - Return NULL if expr1 = expr2 is true + * - Return expr1 otherwise */ -@Slf4j -@TransformFunction(names = {"nullif", "null_if"}) +@TransformFunction(names = {"nullif", "null_if"}, parameter = "(Expr expr1, Expr expr2)", descriptions = { + "- Return \"\" if 'expr1' = 'expr2' is true;", + "- Return 'expr1' otherwise." +}, examples = { + "nullif(5, 3) = 5" +}) public class NullIfFunction implements ValueParser { private final ValueParser firstExprParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/DecodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/DecodeFunction.java index e1a812bf51b..51faa9e0974 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/DecodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/DecodeFunction.java @@ -32,13 +32,21 @@ import java.util.HashSet; import java.util.List; import java.util.Set; + /** - * DecodeFunction - * description: decode(binary, string) - * Decode using the supplied character set (' US-ASCII ', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). - * If either parameter is empty, the result will also be empty. + * DecodeFunction -> decode(binary, charsetStr) + * Description: + * - Return NULL if any parameter is NULL + * - Return the result of encoding binary using the character set specified by charsetStr + * Note: charsetStr is one of ('US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). */ -@TransformFunction(names = {"decode"}) +@TransformFunction(names = {"decode"}, parameter = "(Binary binary,String charsetStr)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return the result of encoding 'binary' using the character set specified by 'charsetStr'.", + "Note: 'charsetStr' is one of ('US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16')." +}, examples = { + "decode(encode('Hello','UTF-8'),'UTF-8') = \"Hello\"" +}) public class DecodeFunction implements ValueParser { private ValueParser binaryParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/EncodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/EncodeFunction.java index 520622dd81d..30671df200f 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/EncodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/EncodeFunction.java @@ -32,13 +32,21 @@ import java.util.HashSet; import java.util.List; import java.util.Set; + /** - * EncodeFunction - * description: encode(string1, string2) - * Encode using the provided character set (' US-ASCII ', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). - * If either parameter is empty, the result will also be empty. + * EncodeFunction -> encode(strInfo, charsetStr) + * Description: + * - Return NULL if any parameter is NULL + * - Return the result of encoding strInfo using the character set specified by charsetStr + * Note: charsetStr is one of ('US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). */ -@TransformFunction(names = {"encode"}) +@TransformFunction(names = {"encode"}, parameter = "(String strInfo,String charsetStr)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return the result of encoding 'strInfo' using the character set specified by 'charsetStr'.", + "- Note: 'charsetStr' is one of ('US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16')." +}, examples = { + "decode(encode('Hello','UTF-8'),'UTF-8') = \"Hello\"" +}) public class EncodeFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/FromBase64Function.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/FromBase64Function.java index bdb99c0a5db..e1a075c6785 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/FromBase64Function.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/FromBase64Function.java @@ -31,10 +31,17 @@ import java.util.List; /** - * FromBase64Function - * description: Returns the base64-decoded result from string; returns NULL if string is NULL + * FromBase64Function -> from_base64(base64Str) + * description: + * - Return NULL if base64Str is NULL + * - Return the base64-decoded result from string */ -@TransformFunction(names = {"from_base64"}) +@TransformFunction(names = {"from_base64"}, parameter = "(String base64Str)", descriptions = { + "- Return \"\" if 'base64Str' is NULL;", + "- Return the base64-decoded result from 'base64Str'." +}, examples = { + "from_base64('QXBhY2hlIEluTG9uZw==') = \"Apache InLong\"" +}) public class FromBase64Function implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/Md5Function.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/Md5Function.java index e9665efbed1..3fccde0e58e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/Md5Function.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/Md5Function.java @@ -29,10 +29,18 @@ import java.nio.charset.StandardCharsets; /** - * Md5Function - * description: MD5(string): Return the MD5 hash value of a string in the form of a 32-bit hexadecimal digit string; If the string is NULL, return NULL. + * Md5Function -> MD5(string) + * description: + * - Return NULL if the string is NULL + * - Return the MD5 hash value of a string in the form of a 32-bit hexadecimal digit string */ -@TransformFunction(names = {"md5"}) +@TransformFunction(names = {"md5"}, parameter = "(String string)", descriptions = { + "- Return \"\" if the 'string' is NULL;", + "- Return the MD5 hash value of 'string' in the form of a 32-bit hexadecimal digit string." +}, examples = { + "md5(\"\") = \"d41d8cd98f00b204e9800998ecf8427e\"", + "md5(\"1\") = \"c4ca4238a0b923820dcc509a6f75849b\"" +}) public class Md5Function implements ValueParser { private ValueParser msgParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/Sha2Function.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/Sha2Function.java index 0862cc29b00..0bc05f1034d 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/Sha2Function.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/Sha2Function.java @@ -32,12 +32,17 @@ import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA_224; /** - * Sha2Function - * description: SHA2(str, hash_length): Calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512) - * return NULL If either argument is NULL or the hash length(224 256 384 512) is not one of the permitted values - * return a hash value containing the desired number of bits. + * Sha2Function -> SHA2(str, hash_length) + * description: + * - Return NULL if either argument is NULL or the hash_length(224 256 384 512) is not one of the permitted values + * - Return a hash value containing the 'hash_length' of bits */ -@TransformFunction(names = {"sha2"}) +@TransformFunction(names = {"sha2"}, parameter = "(String str, Integer hash_length)", descriptions = { + "- Return \"\" if either argument is NULL or the 'hash_length' is not one of (224,256,384,512);", + "- Return scale of the argument (the number of decimal digits in the fractional part)." +}, examples = { + "sha2(\"5\",224) = \"b51d18b551043c1f145f22dbde6f8531faeaf68c54ed9dd79ce24d17\"" +}) public class Sha2Function implements ValueParser { private final ValueParser msgParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/ShaFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/ShaFunction.java index a15aa1e6285..a093c220e10 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/ShaFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/ShaFunction.java @@ -27,12 +27,17 @@ import org.apache.commons.codec.digest.DigestUtils; /** - * ShaFunction - * description: sha(string): Compute the SHA-1 160 bit checksum of a string. - * return NULL if the parameter is NULL - * return a string of 40 hexadecimal digits. + * ShaFunction -> sha(str) + * description: + * - Return NULL if 'str' is NULL + * - Return a string of 40 hexadecimal digits (the SHA-1 160 bit) */ -@TransformFunction(names = {"sha"}) +@TransformFunction(names = {"sha"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return a string of 40 hexadecimal digits (the SHA-1 160 bit)." +}, examples = { + "sha(\"5\") = \"ac3478d69a3c81fa62e60f5c3696165a4e5e6ac4\"" +}) public class ShaFunction implements ValueParser { private final ValueParser msgParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/ToBase64Function.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/ToBase64Function.java index e6bd4716580..d8f04fb8dcf 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/ToBase64Function.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/encryption/ToBase64Function.java @@ -29,10 +29,17 @@ import java.util.Base64; /** - * ToBase64Function - * description: to_base64(string1)--returns the base64-encoded result from string1 + * ToBase64Function -> to_base64(str) + * description: + * - Return NULL if 'str' is NULL; + * - Return the base64-encoded result from 'str'. */ -@TransformFunction(names = {"to_base64"}) +@TransformFunction(names = {"to_base64"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the base64-encoded result from 'str'." +}, examples = { + "to_base64('app-fun') = \"YXBwLWZ1bg==\"" +}) public class ToBase64Function implements ValueParser { private final ValueParser stringParser; @@ -44,6 +51,9 @@ public ToBase64Function(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj = stringParser.parse(sourceData, rowIndex, context); + if (stringObj == null) { + return null; + } String string = OperatorTools.parseString(stringObj); return Base64.getEncoder().encodeToString(string.getBytes(StandardCharsets.UTF_8)); } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayAppendFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayAppendFunction.java index c1511ac6e31..c7d5fbb6843 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayAppendFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayAppendFunction.java @@ -35,10 +35,16 @@ /** * JsonArrayAppendFunction -> JSON_ARRAY_APPEND(json_doc, path, val[, path, val] ...) * description: - * - return NULL if any argument is NULL. - * - return the result of appends values to the end of the indicated arrays within a JSON document. + * - Return NULL if any argument is NULL. + * - Return the result of appends values to the end of the indicated arrays within a JSON document. */ -@TransformFunction(names = {"json_array_append"}) +@TransformFunction(names = { + "json_array_append"}, parameter = "(String json_doc, String path1, String val1[,String path2, String val2, ...])", descriptions = { + "- Return \"\" if any argument is NULL;", + "- Return the result of appends values to the end of the indicated arrays within a JSON document." + }, examples = { + "json_array_append([\"a\", [\"b\", \"c\"], \"d\"],$[0],2,$[1],3) = [[\"a\",\"2\"],[\"b\",\"c\",\"3\"],\"d\"]" + }) public class JsonArrayAppendFunction implements ValueParser { private ValueParser jsonDocParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayInsertFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayInsertFunction.java index a49e145d198..580c427ed21 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayInsertFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayInsertFunction.java @@ -41,7 +41,15 @@ * Note: If multiple groups of parameters are passed in, the parameter subscripts of the latter groups * need to be based on the document subscripts after the previous group of parameters are updated. */ -@TransformFunction(names = {"json_array_insert"}) +@TransformFunction(names = { + "json_array_insert"}, parameter = "(String json_doc, String path1, String val1[, String path2, String val2, ...] )", descriptions = { + "- Return \"\" if any argument is NULL;", + "- Return the 'json_doc' inserted into the array.", + "Note: If multiple groups of parameters are passed in, the parameter subscripts of the latter groups " + + "need to be based on the document subscripts after the previous group of parameters are updated." + }, examples = { + "json_array_append([\"a\", {\"b\": [1, 2]}, [3, 4]], $[1], x) = [\"a\",\"x\",{\"b\":[1,2]},[3,4]]" + }) public class JsonArrayInsertFunction implements ValueParser { private ValueParser jsonDocParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArraysFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArraysFunction.java index 9dc7edcddea..d08e46f0c43 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArraysFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArraysFunction.java @@ -31,14 +31,17 @@ import java.util.ArrayList; import java.util.List; /** - * JsonArraysFunction - * description: JSON_ARRAYS()--Builds a JSON array string from a list of values. This function returns a JSON string. - * The values can be arbitrary expressions. - * for example: JSON_ARRAYS()--'[]' - * JSON_ARRAYS(1, '2')--'[1,"2"]' - * JSON_ARRAYS(JSON_ARRAY(1))--'[[1]]' + * JsonArraysFunction -> JSON_ARRAYS([value1, value2, ...]) + * description: + * - Return a JSON array string constructed from a list of values */ -@TransformFunction(names = {"json_arrays"}) +@TransformFunction(names = {"json_arrays"}, parameter = "([String value1, String value2, ...])", descriptions = { + "- Return a JSON array string constructed from a list of values." +}, examples = { + "JSON_ARRAYS() = []", + "JSON_ARRAYS(1, '2') = [1,\"2\"]", + "JSON_ARRAYS(JSON_ARRAY(1)) = [[1]]" +}) public class JsonArraysFunction implements ValueParser { private List parserList; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonExistsFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonExistsFunction.java index f65f57ac3b3..abf52f01202 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonExistsFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonExistsFunction.java @@ -30,13 +30,19 @@ import java.util.List; /** - * JsonExistsFunction - * description: JSON_EXISTS(jsonValue, path)--Determines whether a JSON string satisfies a given path search criterion. - * for example: JSON_EXISTS('{"a": true}', '$.a')--return true - * JSON_EXISTS('{"a": true}', '$.b')--return false - * JSON_EXISTS('{"a": [{ "b": 1 }]}', '$.a[0].b')--return true + * JsonExistsFunction -> JSON_EXISTS(jsonValue, path) + * description: + * - Return true if a JSON string satisfies a given path search criterion + * - Return false otherwise */ -@TransformFunction(names = {"json_exists"}) +@TransformFunction(names = {"json_exists"}, parameter = "(String json_doc, String path)", descriptions = { + "- Return true if 'json_doc' satisfies a given 'path' search criterion;", + "- Return false otherwise." +}, examples = { + "JSON_EXISTS('{\"a\": true}', '$.a') = true", + "JSON_EXISTS('{\"a\": true}', '$.b') = false", + "JSON_EXISTS('{\"a\": [{ \"b\": 1 }]}', '$.a[0].b') = true" +}) public class JsonExistsFunction implements ValueParser { private final ValueParser jsonParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonQueryFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonQueryFunction.java index d9927a5c1c1..3c312ba3434 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonQueryFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonQueryFunction.java @@ -29,14 +29,19 @@ import java.util.List; /** - * JsonQueryFunction - * description: JSON_QUERY(jsonValue, path)--Extracts JSON values from a JSON string. - * for example: json_query({\"people\": [{\"name\": \"Alice\"}, {\"name\": \"Bob\"}]}, $.people) - * --return [{"name":"Alice"},{"name":"Bob"}] - * json_query({\"list\": [null, {\"name\": \"John\"}]}, $.list[1].name) - * --return John + * JsonQueryFunction -> JSON_QUERY(json_doc, path) + * description: + * - Return NULL if any parameter is NULL + * - Return the string parsed from the path in json_doc */ -@TransformFunction(names = {"json_query"}) +@TransformFunction(names = {"json_query"}, parameter = "(String json_doc, String path)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return the string parsed from the 'path' in 'json_doc'." +}, examples = { + "json_query({\\\"people\\\": [{\\\"name\\\": \\\"Alice\\\"}, {\\\"name\\\": \\\"Bob\\\"}]}, $.people)" + + " = [{\"name\":\"Alice\"},{\"name\":\"Bob\"}]", + "json_query({\\\"list\\\": [null, {\\\"name\\\": \\\"John\\\"}]}, $.list[1].name) = John" +}) public class JsonQueryFunction implements ValueParser { private final ValueParser jsonParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonQuoteFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonQuoteFunction.java index 964672c23d7..c14f201a061 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonQuoteFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonQuoteFunction.java @@ -25,22 +25,22 @@ import com.alibaba.fastjson.JSON; import net.sf.jsqlparser.expression.Function; + /** - * JsonQuoteFunction - * description: JSON_QUOTE(string)--Quotes a string as a JSON value by wrapping it with double quote characters, - * escaping interior quote and special characters (’"’, ‘', ‘/’, ‘b’, ‘f’, ’n’, ‘r’, ’t’), and returning - * the result as a string. If the argument is NULL, the function returns NULL. - * - * JSON_STRING(string)--Serializes a value into JSON. returns a JSON string containing the serialized value. - * If the value is NULL, the function returns NULL. - * - * for example: json_quote('Hello, World!')--return "Hello, World!" - * json_quote('Complex string with / and \\')--return "Complex string with / and \\" - * - * json_string(1)--return 1 - * json_string(true)--return "true" + * JsonQuoteFunction -> JSON_QUOTE(str) or JSON_STRING(str) + * description: + * - Return NULL if str is NULL + * - Return a valid JSON string converted from a string (JSON_QUOTE) or any type of data (JSON_STRING) + * Note: JSON_QUOTE will escape interior quote and special characters (’"’, ‘', ‘/’, ‘b’, ‘f’, ’n’, ‘r’, ’t’) */ -@TransformFunction(names = {"json_quote", "json_string"}) +@TransformFunction(names = {"json_quote", "json_string"}, parameter = "(String data)", descriptions = { + "- Return \"\" if data is NULL;", + "- Return a valid JSON string converted from a string (JSON_QUOTE) or any type of data (JSON_STRING).", + "Note: JSON_QUOTE will escape interior quote and special characters (’\"’, ‘', ‘/’, ‘b’, ‘f’, ’n’, ‘r’, ’t’)" +}, examples = { + "json_quote('Column1\\tColumn2) = \\\"Column1\\\\tColumn2\\\"", + "json_string(true) = \"true\"" +}) public class JsonQuoteFunction implements ValueParser { private ValueParser jsonParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonUnQuoteFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonUnQuoteFunction.java index 1fa0e533ca4..91f5c07a80d 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonUnQuoteFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonUnQuoteFunction.java @@ -26,16 +26,24 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONException; import net.sf.jsqlparser.expression.Function; + /** - * JsonUnQuoteFunction - * description: JSON_UNQUOTE(string)--Unquotes JSON value, unescapes escaped special characters (’"’, ‘', ‘/’, ‘b’, - * ‘f’, ’n’, ‘r’, ’t’, ‘u’ hex hex hex hex), and returns the result as a string. If the argument is NULL, - * returns NULL. If the value does not start and end with double quotes or if it starts and ends with double - * quotes but is not a valid JSON string literal, the value is passed through unmodified. - * for example: json_unquote('Hello, World!')--return "Hello, World!" - * json_unquote('Complex string with / and \\')--return "Complex string with / and \\" + * JsonUnQuoteFunction -> JSON_UNQUOTE(string) + * description: + * - Return NULL if str is NULL + * - Return the value unmodified if the value does not start and end with double quotes or if it starts and ends with + * double quotes but is not a valid JSON string literal + * Note: JSON_UNQUOTE will unescapes escaped special characters ('"', '', '/', 'b', 'f', 'n', 'r', 't') */ -@TransformFunction(names = {"json_unquote"}) +@TransformFunction(names = {"json_unquote"}, parameter = "(String data)", descriptions = { + "- Return \"\" if data is NULL;", + "- Return the 'data' unmodified if the value does not start and end with double quotes or if it starts" + + " and ends with double quotes but is not a valid JSON string literal.", + "Note: JSON_UNQUOTE will unescapes escaped special characters ('\"', '', '/', 'b', 'f', 'n', 'r', 't')" +}, examples = { + "json_unquote('Hello, World!') = \"Hello, World!\"", + "json_unquote('Complex string with / and \\\\') = \"Complex string with / and \\\\\"" +}) public class JsonUnQuoteFunction implements ValueParser { private ValueParser jsonParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonValueFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonValueFunction.java index 6a69c3cb180..e21696a1035 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonValueFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonValueFunction.java @@ -30,12 +30,18 @@ import java.util.List; /** - * JsonValueFunction - * description: JSON_VALUE(jsonValue, path)--Extracts a scalar from a JSON string. - * for example: json_value({"a": 1}, $.a)--return 1 - * json_value({\"person\": {\"name\": \"Alice\" ,\"age\": 30}}, $.person.name)--return Alice + * JsonValueFunction -> JSON_VALUE(json_doc, path) + * description: + * - Return NULL if any parameter is NULL + * - Return the scalar extracted from JSON string (json_doc) based on path */ -@TransformFunction(names = {"json_value"}) +@TransformFunction(names = {"json_value"}, parameter = "(String json_doc,String path)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return the scalar extracted from JSON string ('json_doc') based on 'path'." +}, examples = { + "json_value({\"a\": 1}, $.a) = 1", + "json_value({\\\"person\\\": {\\\"name\\\": \\\"Alice\\\" ,\\\"age\\\": 30}}, $.person.name) = Alice" +}) public class JsonValueFunction implements ValueParser { private final ValueParser jsonParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/AsciiFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/AsciiFunction.java index 2c18bf16f48..fb925262856 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/AsciiFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/AsciiFunction.java @@ -29,29 +29,28 @@ import java.util.List; /** - * ASCIIFunction - * description: ASCII(string) -- Returns the numeric value of the first character of string. Returns NULL if string is NULL. + * ASCIIFunction ASCII(string) + * description: + * - Return NULL if string is NULL. + * - Return the numeric value of the first character of string. */ -@TransformFunction(names = {"ascii"}) +@TransformFunction(names = {"ascii"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the numeric value of the first character of 'str'." +}, examples = { + "ascii('abc') = 97", + "ascii('A') = 65", + "ascii(null) = \"\"" +}) public class AsciiFunction implements ValueParser { private final ValueParser stringParser; - /** - * Constructor - * @param expr - */ public AsciiFunction(Function expr) { List expressions = expr.getParameters().getExpressions(); stringParser = OperatorTools.buildParser(expressions.get(0)); } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj = stringParser.parse(sourceData, rowIndex, context); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/BitLengthFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/BitLengthFunction.java index 9513f7ccf6d..205fcbcd0f2 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/BitLengthFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/BitLengthFunction.java @@ -31,13 +31,20 @@ import java.util.List; /** - * BitLengthFunction - * description: bit_length(string,[charset]) - * - return NULL if the string is NULL. - * - return number of bits in string. + * BitLengthFunction -> bit_length(string,[charset]) + * description: + * - Return NULL if the string is NULL. + * - Return number of bits in string. */ @Slf4j -@TransformFunction(names = {"bit_length"}) +@TransformFunction(names = {"bit_length"}, parameter = "(String str,[String charset])", descriptions = { + "- Return \"\" if the 'str' is NULL;", + "- Return number of bits in 'str'.", + "Note: Charset is aligned with the JVM by default." +}, examples = { + "bit_length(\"hello world\") = 88", + "bit_length(\"hello 你好\",\"utf-8\") = 96" +}) public class BitLengthFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/CharLengthFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/CharLengthFunction.java index 58c2c48ded7..7679195ebc5 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/CharLengthFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/CharLengthFunction.java @@ -29,12 +29,18 @@ import java.util.List; /** - * LengthFunction - * description: char_length(string) - * - return the character length of the string - * - return NULL if the string is NULL + * CharLengthFunction -> char_length(string) + * Description: + * - Return NULL if the string is NULL + * - Return the character length of the string */ -@TransformFunction(names = {"char_length"}) +@TransformFunction(names = {"char_length"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the character length of 'str'." +}, examples = { + "char_length('hello world') = 11", + "case2: char_length('应龙') = 2" +}) public class CharLengthFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ConcatFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ConcatFunction.java index a441820b922..1f3f14fc943 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ConcatFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ConcatFunction.java @@ -23,6 +23,7 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; @@ -30,18 +31,22 @@ import java.util.List; /** - * ConcatFunction - * + * ConcatFunction -> concat(string1, string2, ...) + * description: + * - Return NULL If any parameter is NULL + * - Return the string of the connection (string1, string2,...) */ -@TransformFunction(names = {"concat"}) +@Slf4j +@TransformFunction(names = {"concat"}, parameter = "(String string1 [, String string2, ...])", descriptions = { + "- Return NULL If any parameter is NULL;", + "- Return the string of the connection ('string1', 'string2',...)." +}, examples = { + "CONCAT(\"AA\", \"BB\", \"CC\") = \"AABBCC\"" +}) public class ConcatFunction implements ValueParser { private List nodeList; - /** - * Constructor - * @param expr - */ public ConcatFunction(Function expr) { if (expr.getParameters() == null) { this.nodeList = new ArrayList<>(); @@ -55,12 +60,6 @@ public ConcatFunction(Function expr) { } } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { StringBuilder builder = new StringBuilder(); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ConcatWsFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ConcatWsFunction.java index 2ca6e688c27..3c7276b2de1 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ConcatWsFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ConcatWsFunction.java @@ -23,6 +23,7 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; import net.sf.jsqlparser.expression.NullValue; @@ -31,12 +32,20 @@ import java.util.List; /** - * ConcatWsFunction - * description: concat_ws(string1, string2, string3,…)--Returns a string that concatenates STRING2, - * STRING3, … with a separator STRING1. The separator is added between the strings to be concatenated. - * Returns NULL If STRING1 is NULL. + * ConcatWsFunction -> concat_ws(string1, string2, string3,...) + * description: + * - Return NULL If STRING1 is NULL. + * - Return a string that concatenates (STRING2, STRING3, ...) with a separator STRING1. */ -@TransformFunction(names = {"concat_ws"}) +@Slf4j +@TransformFunction(names = {"concat_ws"}, parameter = "(String string1 [, String string2, ...])", descriptions = { + "- Return NULL If 'STRING1' is NULL;", + "- Return a string that concatenates ('STRING2', 'STRING3', ...) with a separator STRING1." +}, examples = { + "concat_ws('-', 'apple', 'banana', 'cloud') = \"apple-banana-cloud\"", + "concat_ws('-', 'apple', '', 'cloud') = \"apple--cloud\"", + "concat_ws('-', 'apple', null, 'cloud') = \"apple-cloud\"" +}) public class ConcatWsFunction implements ValueParser { private final String separator; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ContainsFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ContainsFunction.java index 90a024982a4..1699e578142 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ContainsFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ContainsFunction.java @@ -23,18 +23,27 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; import java.util.List; /** - * ContainsFunction - * description: contains(left, right) - Returns a boolean. - * The value is True if right is found inside left, otherwise, returns False. - * Both left or right must be of STRING type. + * ContainsFunction -> contains(left, right) + * description: + * - Return NULL if left or right is NULL + * - Return True if right is found inside left + * - Return False otherwise */ -@TransformFunction(names = {"contains"}) +@Slf4j +@TransformFunction(names = {"contains"}, parameter = "(String leftStr , String rightStr)", descriptions = { + "- Return \"\" if 'leftStr' or rightStr is NULL;", + "- Return True if 'rightStr' is found inside 'leftStr';", + "- Return False otherwise." +}, examples = { + "contains('Transform SQL', 'SQL') = true" +}) public class ContainsFunction implements ValueParser { private ValueParser leftStrParser; @@ -50,6 +59,9 @@ public ContainsFunction(Function expr) { public Object parse(SourceData sourceData, int rowIndex, Context context) { Object leftStrObj = leftStrParser.parse(sourceData, rowIndex, context); Object rightStrObj = rightStrParser.parse(sourceData, rowIndex, context); + if (leftStrObj == null || rightStrObj == null) { + return null; + } String leftStr = OperatorTools.parseString(leftStrObj); String rightStr = OperatorTools.parseString(rightStrObj); return (leftStr == null || rightStr == null) ? null : leftStr.contains(rightStr); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/EltFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/EltFunction.java index 85acc9bf266..3182cc02dc9 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/EltFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/EltFunction.java @@ -30,13 +30,17 @@ import java.util.List; /** - * EltFunction -> elt(index, expr[, exprs]*) + * EltFunction -> elt(index, expr1[, expr2, ...]) * description: - * - Returns the index-th expression. - * - index must be an integer between 1 and the number of expressions. - * - Returns NULL if index is NULL or out of range. + * - Return NULL if 'index' is NULL or out of range; + * - Return the index-th('index' starts from 1) expression. */ -@TransformFunction(names = {"elt"}) +@TransformFunction(names = {"elt"}, parameter = "(Integer index, Expr expr1[, Expr expr2, ...])", descriptions = { + "- Return \"\" if 'index' is NULL or out of range;", + "- Return the index-th('index' starts from 1) expression." +}, examples = { + "elt(2, 'a', 'b', 'c') = \"b\"" +}) public class EltFunction implements ValueParser { private ValueParser indexParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/EndsWithFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/EndsWithFunction.java index 1a609995b38..b060fa44ec9 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/EndsWithFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/EndsWithFunction.java @@ -29,10 +29,17 @@ import java.util.List; /** - * EndsWithFunction - * description: Returns whether expr ends with endExpr. + * EndsWithFunction -> endswith(s1,s2) + * description: + * - Return NULL if either argument is NULL; + * - Return whether 's2' ends with 's2'. */ -@TransformFunction(names = {"endswith"}) +@TransformFunction(names = {"endswith"}, parameter = "(String s1, String s2)", descriptions = { + "- Return \"\" if either argument is NULL;", + "- Return whether 's2' ends with 's2'." +}, examples = { + "endswith('Apache InLong', 'Long') = true" +}) public class EndsWithFunction implements ValueParser { private ValueParser exprParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/FormatFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/FormatFunction.java index 179c553d6b6..7bd8e30de29 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/FormatFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/FormatFunction.java @@ -39,7 +39,13 @@ * return NULL if X or D is NULL. * return the result of formatting the number X to "#,###,###.##" format, rounded to D decimal places. */ -@TransformFunction(names = {"format"}) +@TransformFunction(names = {"format"}, parameter = "(Numeric X,Integer D)", descriptions = { + "- Return \"\" if 'X' or 'D' is NULL;", + "- Return the result of formatting the number 'X' to \"#,###,###.##\" format, rounded to 'D' decimal places." +}, examples = { + "FORMAT(12332.123456, 4) = \"12,332.1235\"", + "FORMAT(12332.2,0) = \"12,332\"" +}) public class FormatFunction implements ValueParser { private ValueParser numberParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/InitCapFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/InitCapFunction.java similarity index 76% rename from inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/InitCapFunction.java rename to inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/InitCapFunction.java index 67c2e6d17fb..8b93f3ac484 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/InitCapFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/InitCapFunction.java @@ -15,10 +15,11 @@ * limitations under the License. */ -package org.apache.inlong.sdk.transform.process.function; +package org.apache.inlong.sdk.transform.process.function.string; import org.apache.inlong.sdk.transform.decode.SourceData; import org.apache.inlong.sdk.transform.process.Context; +import org.apache.inlong.sdk.transform.process.function.TransformFunction; import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; @@ -28,11 +29,19 @@ import java.util.List; /** - * InitCapFunction - * description: initcap(string)--returns a new form of STRING with the first character of each word converted to - * uppercase and the rest characters to lowercase + * InitCapFunction -> initcap(str) + * description: + * - Return NULL if 'str' is NULL; + * - Return a new form of STRING with the first character of each word converted to uppercase + * and the rest characters to lowercase. */ -@TransformFunction(names = {"initcap", "init_cap"}) +@TransformFunction(names = {"initcap", "init_cap"}, parameter = "(String s1, String s2)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return a new form of 'str' with the first character of each word converted to uppercase " + + "and the rest characters to lowercase." +}, examples = { + "initcap('hello world') = \"Hello world\"" +}) public class InitCapFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/InsertFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/InsertFunction.java index 67167fa7b10..91c9c6b7e8a 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/InsertFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/InsertFunction.java @@ -27,27 +27,30 @@ import net.sf.jsqlparser.expression.Function; import java.util.List; + /** - * InsertFunction - * - * Description: - * Returns a string where a specified substring is replaced by another string, starting at a given position and for a specified length. - * If the position is out of the string's bounds, the original string is returned. - * If the length exceeds the remaining length of the string from the given position, the replacement continues to the end of the string. - * If any argument is null, the function returns null. - * - * Arguments: - * - str: The original string. - * - pos: The position to start the replacement (1-based index). - * - len: The number of characters to replace. - * - newstr: The string to insert. - * - * Examples: - * - INSERT('12345678', 3, 4, 'word') = '12word78' - * - INSERT('12345678', -1, 4, 'word') = '12345678' - * - INSERT('12345678', 3, 100, 'word') = '12word' + * InsertFunction -> insert(str,pos,len,newStr) + * description: + * - Return NULL If any parameter is NULL + * - Return the result of replacing the substring of length len with newStr starting from the given position pos in Str. + * Note: If the position is out of the string's bounds, the original string is returned.If the length exceeds the + * remaining length of the string from the given position, the replacement continues to the end of the string. + * If any argument is null, the function returns null. */ -@TransformFunction(names = {"insert"}) +@TransformFunction(names = { + "insert"}, parameter = "(String str,Integer pos,Integer len,String newStr)", descriptions = { + "- Return \"\" If any parameter is NULL;", + "- Return the result of replacing the substring of length len with 'newStr' starting from the given position 'pos' in 'str'.", + "Note: If the position is out of the string's bounds, the original string is returned.If the length exceeds the " + + + "remaining length of the string from the given position, the replacement continues to the end of the string." + + + "If any argument is null, the function returns null." + }, examples = { + "INSERT('12345678', 3, 4, 'word') = '12word78'", + "INSERT('12345678', -1, 4, 'word') = '12345678'", + "INSERT('12345678', 3, 100, 'word') = '12word'" + }) public class InsertFunction implements ValueParser { private ValueParser strParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsAlphaFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsAlphaFunction.java index 1a5365aff6d..2ac0773fe2c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsAlphaFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsAlphaFunction.java @@ -26,12 +26,19 @@ import net.sf.jsqlparser.expression.Function; /** - * IsAlphaFunction - * description: is_alpha(string) - * - return true if all characters in string are letter - * - return false otherwise (Including cases where string is null and ''). + * IsAlphaFunction -> is_alpha(string) + * description: + * - Return true if all characters in string are letter + * - Return false otherwise (Including cases where string is null and ''). */ -@TransformFunction(names = {"is_alpha"}) +@TransformFunction(names = {"is_alpha"}, parameter = "(String str)", descriptions = { + "- Return \"\" If 'str' is NULL;", + "- Return true if all characters in 'str' are letter;", + "- Return false otherwise (Including cases where string is null and '')." +}, examples = { + "is_alpha('inlong') = true", + "is_alpha('inlong~') = false", +}) public class IsAlphaFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsDecimalFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsDecimalFunction.java index e8e09086adf..42da83c3cdb 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsDecimalFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsDecimalFunction.java @@ -26,12 +26,19 @@ import net.sf.jsqlparser.expression.Function; /** - * IsDecimalFunction - * description: is_decimal(string) - * - return true if string can be parsed to a valid numeric. - * - return false otherwise (Including cases where string is null and ''). + * IsDecimalFunction -> is_decimal(string) + * description: + * - Return true if string can be parsed to a valid numeric. + * - Return false otherwise (Including cases where string is null and ''). */ -@TransformFunction(names = {"is_decimal"}) +@TransformFunction(names = {"is_decimal"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return true if 'str' can be parsed to a valid numeric;", + "- Return false otherwise (Including cases where string is null and '')." +}, examples = { + "is_decimal('3he') = false", + "is_decimal('3.5') = true", +}) public class IsDecimalFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsDigitFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsDigitFunction.java index bff3d6a736e..31c32020109 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsDigitFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/IsDigitFunction.java @@ -26,12 +26,18 @@ import net.sf.jsqlparser.expression.Function; /** - * IsDigitFunction - * description: is_digit(string) + * IsDigitFunction -> is_digit(string) + * description: * - return true if all characters in string are digit. * - return false otherwise (Including cases where string is null and ''). */ -@TransformFunction(names = {"is_digit"}) +@TransformFunction(names = {"is_digit"}, parameter = "(String str)", descriptions = { + "- Return \"\" If 'str' is NULL;", + "- Return true if all characters in 'str' are digit;", + "- Return false otherwise (Including cases where 'str' is null and '')." +}, examples = { + "is_digit('3.5') = false" +}) public class IsDigitFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LeftFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LeftFunction.java index fd9d5625241..d63f5738a6c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LeftFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LeftFunction.java @@ -29,13 +29,20 @@ import java.util.List; /** - * LeftFunction - * description: left(string,length) + * LeftFunction -> left(string,length) + * description: * - return null if either string or length is null * - return "" if it is less than or equal to zero * - return a substring of length starting from the right side of the string. */ -@TransformFunction(names = {"left"}) +@TransformFunction(names = {"left"}, parameter = "(String str, Integer len)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return \"\" if 'len' is less than or equal to zero;", + "- Return a substring of len starting from the right side of the 'str'." +}, examples = { + "left('hello world',100) = \"hello world\"", + "left('hello world',-15) = \"\"" +}) public class LeftFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LengthFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LengthFunction.java index 8e2696172ec..6445c21df49 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LengthFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LengthFunction.java @@ -30,12 +30,20 @@ import java.util.List; /** - * LengthFunction - * description: length(string,[charsetName]) - * - return the byte length of the string + * LengthFunction -> length(string,[charset]) + * description: * - return NULL if the string is NULL + * - return the byte length of the string + * Note: charset defaults to matching with JVM. */ -@TransformFunction(names = {"length"}) +@TransformFunction(names = {"length"}, parameter = "(String str, String charset)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the byte length of the 'str'.", + "Note: charset defaults to matching with JVM." +}, examples = { + "length(应龙, utf-8) = 6", + "length('hello world') = 11" +}) public class LengthFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LocateFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LocateFunction.java index 67d05709095..1ac5225255e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LocateFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LocateFunction.java @@ -29,24 +29,27 @@ import java.util.List; /** - * LocateFunction - * description: locate(string1, string2[, integer]) - * - returns the position of the first occurrence of string1 in string2 after position integer - * - returns 0 if not found - * - returns NULL if any of arguments is NULL + * LocateFunction -> locate(string1, string2[, integer]) + * description: + * - Return NULL if any of arguments is NULL + * - Return 0 if not found + * - Return the position of the first occurrence of string1 in string2 after position integer */ -@TransformFunction(names = {"locate", "instr"}) +@TransformFunction(names = {"locate", + "instr"}, parameter = "(String str1, String str2, Integer pos)", descriptions = { + "- Return \"\" if any of arguments is NULL'", + "- Return 0 if not found'", + "- Return the position of the first occurrence of 'str1' in 'str2' after position 'pos'." + }, examples = { + "locate('app', 'apple') = 1", + "locate('app', 'appapp', 2) = 4" + }) public class LocateFunction implements ValueParser { private ValueParser stringParser1; private ValueParser stringParser2; private ValueParser startPositionParser; - /** - * Constructor - * - * @param expr - */ public LocateFunction(Function expr) { List expressions = expr.getParameters().getExpressions(); // Determine the number of arguments and build parser @@ -57,13 +60,6 @@ public LocateFunction(Function expr) { } } - /** - * parse - * - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj1 = stringParser1.parse(sourceData, rowIndex, context); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LowerFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LowerFunction.java index 2b88d6be4db..7f9a1796bec 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LowerFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LowerFunction.java @@ -26,10 +26,17 @@ import net.sf.jsqlparser.expression.Function; /** - * LowerFunction - * description: LOWER(s): Convert all letters of the string s to lowercase letters + * LowerFunction -> LOWER(str) + * description: + * - Return NULL if str is NULL + * - Return the string obtained by converting all letters of the string to lowercase letters */ -@TransformFunction(names = {"lower", "lcase"}) +@TransformFunction(names = {"lower", "lcase"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the string obtained by converting all letters of 'str' to lowercase letters." +}, examples = { + "lower(\"ApPlE\") = \"apple\"" +}) public class LowerFunction implements ValueParser { private ValueParser stringParser; @@ -41,8 +48,9 @@ public LowerFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj = stringParser.parse(sourceData, rowIndex, context); - if (stringObj == null) + if (stringObj == null) { return null; + } return stringObj.toString().toLowerCase(); } } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LpadFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LpadFunction.java index ba1bd8e204d..f57ea8ee910 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LpadFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LpadFunction.java @@ -29,16 +29,24 @@ import java.util.List; /** - * LpadFunction - * description: Lpad(s1,len,s2) Fill string s2 at the beginning of string s1 to make the string length len - * - return null if any of the three parameters is null or len is less than 0 - * - return the substring of s1 with subscripts in the range of [0, len) if len is less than or equal to the length of s1 + * LpadFunction -> Lpad(str1,len,str2) + * description: Fill string s2 at the beginning of string s1 to make the string length len + * - Return null if any of the three parameters is null or len is less than 0 + * - Return the substring of s1 with subscripts in the range of [0, len) if len is less than or equal to the length of s1 * - if s2 is "" - * - return "" if len is longer than the length of s1 + * - Return "" if len is longer than the length of s1 * - if s2 is not "" - * - return the filled string + * - Return the filled string */ -@TransformFunction(names = {"lpad"}) +@TransformFunction(names = {"lpad"}, parameter = "(String str1, Integer len, String str2)", descriptions = { + "- Return null if any of the three parameters is null or 'len' is less than 0;", + "- Return the substring of 'str1' with subscripts in the range of [0, 'len') if 'len' is less than or equal to the length of 'str1';", + "- Return \"\" if 'len' is longer than the length of 'str1' and 'str2' is \"\";", + "- Return the filled string if 'str2' is not \"\"." +}, examples = { + "lpad('he',7,'xxd') = \"xxdxxhe\"", + "lpad('he',1,'') = \"h\"" +}) public class LpadFunction implements ValueParser { private final ValueParser leftStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LtrimFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LtrimFunction.java index 188c4e80ad0..5b9dc9eb7b4 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LtrimFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/LtrimFunction.java @@ -26,12 +26,17 @@ import net.sf.jsqlparser.expression.Function; /** - * TrimFunction - * description: ltrim(string) - * - Return NULL if str is NULL. + * LtrimFunction -> ltrim(str) + * description: + * - Return NULL if str is NULL * - Return the string str without leading spaces */ -@TransformFunction(names = {"ltrim"}) +@TransformFunction(names = {"ltrim"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the string 'str' without leading spaces." +}, examples = { + "ltrim(' in long ') = \"in long \"" +}) public class LtrimFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ParseUrlFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ParseUrlFunction.java index 9ed081c7eba..28032940d64 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ParseUrlFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ParseUrlFunction.java @@ -33,13 +33,24 @@ import java.util.Map; /** - * ParseUrlFunction - * description: Returns the specified part from the URL. Valid values for string2 - * include ‘HOST’, ‘PATH’, ‘QUERY’, ‘REF’, ‘PROTOCOL’, ‘AUTHORITY’, ‘FILE’, and ‘USERINFO’. - * Returns NULL if any of arguments is NULL. - * Also a value of a particular key in QUERY can be extracted by providing the key as the third argument string3. + * ParseUrlFunction -> parse_url(urlStr, keyword[, parameter]) + * description: + * - Return NULL any required parameter is NULL + * - Return the specified part from the urlStr. Valid values for keyword. + * Note: The keyword is one of ('HOST', 'PATH', 'QUERY', 'REF', 'PROTOCOL', 'AUTHORITY', 'FILE', 'USERINFO'). + * Also a value of a particular key in QUERY can be extracted by providing the key as the third argument. */ -@TransformFunction(names = {"parse_url"}) +@TransformFunction(names = { + "parse_url"}, parameter = "(String urlStr, String keyword[, String parameter])", descriptions = { + "- Return NULL any required parameter is NULL;", + "- Return the specified part from the 'urlStr'. Valid values for 'keyword'.", + "Note: The 'keyword' is one of ('HOST', 'PATH', 'QUERY', 'REF', 'PROTOCOL', 'AUTHORITY', 'FILE', 'USERINFO')." + + + "Also a value of a particular key in QUERY can be extracted by providing the key as the third argument." + }, examples = { + "parse_url('http://inlong.apache.org/p.php?k1=v1&k2=v2#Ref1', 'QUERY', 'k1') = v1", + "parse_url('http://inlong.apache.org/p.php?k1=v1&k2=v2#Ref1', 'PROTOCOL') = http" + }) public class ParseUrlFunction implements ValueParser { private ValueParser urlParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/PrintfFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/PrintfFunction.java index 4b9c93fb676..1be00003df0 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/PrintfFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/PrintfFunction.java @@ -29,10 +29,16 @@ import java.util.ArrayList; import java.util.List; /** - * PrintfFunction - * description: printf(strfmt, obj, ...) - Returns a formatted string from printf-style format strings. + * PrintfFunction -> printf(strfmt [,obj ,...]) + * description: + * - Return a formatted string from printf-style format strings */ -@TransformFunction(names = {"printf"}) +@TransformFunction(names = {"printf"}, parameter = "(String strfmt [, Object obj, ...])", descriptions = { + "- Return a formatted string from printf-style format strings." +}, examples = { + "printf(\"User %s has %d points and a balance of %.2f.\", \"Bob\", 1500, 99.99) = \"" + + "User Bob has 1500 points and a balance of 99.99.\"" +}) public class PrintfFunction implements ValueParser { private ValueParser strfmtParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpCountFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpCountFunction.java index a7d1f3faa6c..4c8382ef6e2 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpCountFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpCountFunction.java @@ -31,13 +31,19 @@ import java.util.regex.Pattern; /** - * RegexpCountFunction - * description: REGEXP_COUNT(str, regexp)--Returns the number of times str matches the regexp pattern. - * regexp must be a Java regular expression. - * Returns an INTEGER representation of the number of matches. - * NULL if any of the arguments are NULL or regexp is invalid. + * RegexpCountFunction -> regexp_count(str, regexp) + * description: + * - Return NULL if any of the arguments are NULL or 'regexp' is invalid + * - Return the number of times 'str' matches the 'regexp' pattern + * Note: 'regexp' must be a Java regular expression. */ -@TransformFunction(names = {"regexp_count"}) +@TransformFunction(names = {"regexp_count"}, parameter = "(Integer INT1, [Integer INT2])", descriptions = { + "- Return \"\" if any of the arguments are NULL or 'regexp' is invalid;", + "- Return the number of times 'str' matches the 'regexp' pattern.", + "Note: 'regexp' must be a Java regular expression." +}, examples = { + "regexp_count(\"The quick brown fox quick\", \"quick\") = 2" +}) public class RegexpCountFunction implements ValueParser { private ValueParser inputStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpExtractAllFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpExtractAllFunction.java index 9fa4200ac13..74d559c2b80 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpExtractAllFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpExtractAllFunction.java @@ -32,17 +32,27 @@ import java.util.regex.Pattern; /** - * RegexpExtractAllFunction - * description: REGEXP_EXTRACT_ALL(str, regexp[, extractIndex])--Returns an ARRAY representation of all the matched substrings. - * NULL if any of the arguments are NULL or invalid.Extracts all the substrings in str that match the regexp - * expression and correspond to the regexp group extractIndex. regexp may contain multiple groups. extractIndex - * indicates which regexp group to extract and starts from 1, also the default value if not specified. - * 0 means matching the entire regular expression. - * for example: REGEXP_EXTRACT_ALL("abc123def456ghi789", "(\\d+)", 0)--return [123, 456, 789] - * REGEXP_EXTRACT_ALL("Name: John, Age: 25, Location: NY", "Name: (\\w+), Age: (\\d+), Location: (\\w+)", 1)--return [John] - * REGEXP_EXTRACT_ALL("Name: John, Age: 25, Location: NY", "Name: (\\w+), Age: (\\d+), Location: (\\w+)", 0)--return [Name: John, Age: 25, Location: NY] + * RegexpExtractAllFunction -> regexp_extract_all(str, regexp[, extractIndex]) + * description: + * - Return NULL if any of the arguments are NULL or invalid + * - Return an array consisting of all substrings from the 'str' that match the 'regexp' expression and correspond to + * the 'extractIndex' set of regular expressions. + * Note: 'regexp' must be a Java regular expression. 'extractIndex' indicates which regexp group to extract and starts + * from 1, also the default value if not specified. 0 means matching the entire 'regexp' expression. */ -@TransformFunction(names = {"regexp_extract_all"}) +@TransformFunction(names = { + "regexp_extract_all"}, parameter = "(String str, String regexp, [Integer extractIndex])", descriptions = { + "- Return \"\" if any of the arguments are NULL or invalid;", + "- Return an array consisting of all substrings from the 'str' that match the 'regexp' expression " + + "and correspond to the 'extractIndex' set of regular expressions.", + "Note: 'regexp' must be a Java regular expression. 'extractIndex' indicates which regexp group to " + + "extract and starts from 1, also the default value if not specified. 0 means matching the " + + "entire 'regexp' expression." + }, examples = { + "REGEXP_EXTRACT_ALL(\"abc123def456ghi789\", \"(\\\\d+)\", 0) = [123, 456, 789]", + "REGEXP_EXTRACT_ALL(\"Name: John, Age: 25, Location: NY\", \"Name: (\\\\w+), Age: (\\\\d+), Location: (\\\\w+)\", 1) = [John]", + "REGEXP_EXTRACT_ALL(\"Name: John, Age: 25, Location: NY\", \"Name: (\\\\w+), Age: (\\\\d+), Location: (\\\\w+)\", 0) = [Name: John, Age: 25, Location: NY]" + }) public class RegexpExtractAllFunction implements ValueParser { private ValueParser inputStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpExtractFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpExtractFunction.java index 3103688312e..1bcfb778401 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpExtractFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpExtractFunction.java @@ -31,17 +31,31 @@ import java.util.regex.Pattern; /** - * RegexpExtractFunction - * description: REGEXP_EXTRACT(string1, string2[, integer])--Returns a string from string1 which extracted with a specified - * regular expression string2 and a regexp match group index integer.The regexp match group index starts - * from 1 and 0 means matching the whole regexp. In addition, the regexp match group index should not exceed - * the number of the defined groups. - * for example: REGEXP_EXTRACT("abc123def", "(\\d+)", 1)--return 123 - * REGEXP_EXTRACT("Name: John, Age: 25, Location: NY", "Name: (\\w+), Age: (\\d+), Location: (\\w+)", 2)--return 25 - * REGEXP_EXTRACT("abc123def", "(\\d+)", 2)--return null - * REGEXP_EXTRACT("abc123def", "abcdef", 1)--return null + * RegexpExtractFunction -> REGEXP_EXTRACT(str, regexp [, extractIndex]) + * description: + * - Return NULL if any of the arguments are NULL or invalid + * - Return a string from 'str' which extracted with a specified regexp expression 'regexp' and a regexp match group + * index 'extractIndex'. + * Note: 'regexp' must be a Java regular expression. 'extractIndex' indicates which regexp group to extract and starts + * from 1, also the default value if not specified. 0 means matching the entire 'regexp' expression.In addition, + * the regexp match group index should not exceed the number of the defined groups */ -@TransformFunction(names = {"regexp_extract"}) +@TransformFunction(names = { + "regexp_extract"}, parameter = "(String str, String regexp, [Integer extractIndex])", descriptions = { + "- Return \"\" if any of the arguments are NULL or invalid;", + "- Return a string from 'str' which extracted with a specified regexp expression 'regexp' and a regexp " + + + "match group index 'extractIndex'.", + "Note: 'regexp' must be a Java regular expression. 'extractIndex' indicates which regexp group to " + + "extract and starts from 1, also the default value if not specified. 0 means matching the " + + "entire 'regexp' expression. In addition, the regexp match group index should not exceed " + + "the number of the defined groups." + }, examples = { + "REGEXP_EXTRACT(\"abc123def\", \"(\\\\d+)\", 1) = 123", + "REGEXP_EXTRACT(\"Name: John, Age: 25, Location: NY\", \"Name: (\\\\w+), Age: (\\\\d+), Location: (\\\\w+)\", 2) = 25", + "REGEXP_EXTRACT(\"abc123def\", \"(\\\\d+)\", 2) = null", + "REGEXP_EXTRACT(\"abc123def\", \"abcdef\", 1) = null" + }) public class RegexpExtractFunction implements ValueParser { private ValueParser inputStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpFunction.java index 83bee368ac3..5143043cc86 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpFunction.java @@ -29,13 +29,21 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; + /** - * RegexpFunction - * description: REGEX(string1, string2)--Returns TRUE if any (possibly empty) substring of string1 matches the Java - * regular expression string2, otherwise FALSE. Returns NULL if any of arguments is NULL. - * SIMILAR(string1, string2)--Same as above + * RegexpFunction -> REGEX(str, regexp) + * description: + * - Return NULL if any of the arguments are NULL or invalid + * - Return TRUE if any (possibly empty) substring of 'str' matches the Java regular expression 'regexp' */ -@TransformFunction(names = {"regex", "similar", "regexp_like"}) +@TransformFunction(names = {"regex", "similar", + "regexp_like"}, parameter = "(String str, String regexp)", descriptions = { + "- Return \"\" if any of the arguments are NULL or invalid;", + "- Return TRUE if any (possibly empty) substring of 'str' matches the Java regular expression 'regexp'." + }, examples = { + "regexp(\"The quick brown fox\", \"quick\") = true", + "regexp(\"The quick brown fox\", \"cold\") = false" + }) public class RegexpFunction implements ValueParser { private ValueParser inputParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpInstrFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpInstrFunction.java index efacb5d3947..98d22b87e91 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpInstrFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpInstrFunction.java @@ -31,13 +31,18 @@ import java.util.regex.Pattern; /** - * RegexpInstrFunction - * description: REGEXP_INSTR(str, regexp)--Returns the position of the first substring in str that matches regexp. - * Result indexes begin at 1, 0 if there is no match. - * Returns an INTEGER representation of the first matched substring index. - * NULL if any of the arguments are NULL or regexp is invalid. + * RegexpInstrFunction -> REGEXP_INSTR(str, regexp) + * description: + * - Return NULL if any of the arguments are NULL or invalid + * - Return the position of the first substring in 'str' that matches 'regexp' + * Note: Result indexes begin at 1, 0 if there is no match. */ -@TransformFunction(names = {"regexp_instr"}) +@TransformFunction(names = {"regexp_instr"}, parameter = "(String str, String regexp)", descriptions = { + "- Return \"\" if any of the arguments are NULL or invalid;", + "- Return the position of the first substring in 'str' that matches 'regexp'." +}, examples = { + "regexp_instr(\"abc123def\", \"(\\\\d+)\") = 4" +}) public class RegexpInstrFunction implements ValueParser { private ValueParser inputStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpMatchesFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpMatchesFunction.java index b1c17ac6550..365a258f824 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpMatchesFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpMatchesFunction.java @@ -34,18 +34,29 @@ import java.util.stream.Collectors; /** - * RegexpMatchesFunction - * description: REGEX_MATCHES(source_string, pattern [, flags]) → set of text[]--returns the result - * of the first match of the specified regular expression from a string - * parameters: 1) source_string: the string to be matched - * 2) pattern: POSIX regular expression for matching - * 3) flags: one or more characters that control the behavior of a function, - * 'g' flag can be used when we want to match all the substrings that occur, - * 'i' flag to ignore case for matching, - * 'x' flag to extend syntax (ignoring whitespace and comments in regular expressions) - * 'm' and 'n' flag allows regular expressions to match across multiple lines + * RegexpMatchesFunction -> REGEX_MATCHES(source_string, regexp [, flags]) + * description: + * - Return NULL if any of the arguments are NULL or invalid + * - Return the result of the first match of the specified regular expression 'regexp' from 'source_string' + * Note: 'flags' is one of ('g' flag can be used when we want to match all the substrings that occur, + * 'i' flag to ignore case for matching), + * 'x' flag to extend syntax (ignoring whitespace and comments in regular expressions), + * 'm' and 'n' flag allows regular expressions to match across multiple lines) */ -@TransformFunction(names = {"regexp_matches"}) +@TransformFunction(names = { + "regexp_matches"}, parameter = "(String source_string, String regexp [,String flags])", descriptions = { + "- Return \"\" if any of the arguments are NULL or invalid;", + "- Return the result of the first match of the specified regular expression 'regexp' from 'source_string'.", + "Note: 'flags' is one of ('g' -> flag can be used when we want to match all the substrings that occur," + + + "'i' -> flag to ignore case for matching, 'x' -> flag to extend syntax (ignoring whitespace and " + + + "comments in regular expressions), 'm' and 'n' -> flag allows regular expressions to match " + + "across multiple lines)" + }, examples = { + "regexp_matches(\"The quick brown fox\", \"quick\") = [{\"quick\"}]", + "regexp_matches(\"foo 123 bar 456\", \"\\\\d+\", \"g\") = [{\"123\"},{\"456\"}]" + }) public class RegexpMatchesFunction implements ValueParser { private ValueParser inputParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpReplaceFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpReplaceFunction.java index 588d9385448..a7e8dc10c0e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpReplaceFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpReplaceFunction.java @@ -30,11 +30,21 @@ import java.util.regex.Pattern; /** - * RegexpReplaceFunction - * description: REGEXP_REPLACE(string1, string2, string3)--Returns a string from STRING1 with all the substrings that - * match a regular expression STRING2 consecutively being replaced with STRING3. + * RegexpReplaceFunction -> REGEXP_REPLACE(source_string, regexp, replacement) + * description: + * - Return NULL if any of the arguments are NULL or invalid + * - Return a string from 'source_string' with all the substrings that match a regular expression 'regexp' + * consecutively being replaced with 'replacement'. */ -@TransformFunction(names = {"regexp_replace"}) +@TransformFunction(names = { + "regexp_replace"}, parameter = "(String source_string, String regexp, String replacement)", descriptions = { + "- Return \"\" if any of the arguments are NULL or invalid;", + "- Return a string from 'source_string' with all the substrings that match a regular expression 'regexp' " + + + "consecutively being replaced with 'replacement'." + }, examples = { + "regexp_replace('foobarbaz', 'b..', 'X') = \"fooXbaz\"" + }) public class RegexpReplaceFunction implements ValueParser { private ValueParser inputStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpSplitToArrayFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpSplitToArrayFunction.java index 45c9a446fe3..db6ea849862 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpSplitToArrayFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpSplitToArrayFunction.java @@ -31,19 +31,30 @@ import java.util.regex.Pattern; /** - * RegexpSplitToArrayFunction - * description: REGEXP_SPLIT_TO_ARRAY( string, pattern text|, flags text l) → text[] - * Splits string using a POslX regular expression as the delimiter, producing an array of results - * parameters: 1) source_string: the string to be matched - * 2) pattern: POSIX regular expression for matching - * 3) flags: one or more characters that control the behavior of a function, - * 'g' flag can be used when we want to match all the substrings that occur, - * 'i' flag to ignore case for matching, - * 'x' flag to extend syntax (ignoring whitespace and comments in regular expressions), - * 'm' and 'n' flag allows regular expressions to match across multiple lines - * for example: regexp_split_to_array("hello world","\s+")--return {hello, world} + * RegexpReplaceFunction -> REGEXP_SPLIT_TO_ARRAY(source_string, regexp, flags) + * description: + * - Return NULL if any of the arguments are NULL or invalid + * - Return the result array generated by splitting ’source_string‘ using regular expression ’regexp‘ as a delimiter. + * Note: 'flags' is one of ('g' flag can be used when we want to match all the substrings that occur, + * 'i' flag to ignore case for matching), + * 'x' flag to extend syntax (ignoring whitespace and comments in regular expressions), + * 'm' and 'n' flag allows regular expressions to match across multiple lines) */ -@TransformFunction(names = {"regexp_split_to_array"}) +@TransformFunction(names = { + "regexp_split_to_array"}, parameter = "(String source_string, String regexp, String flags)", descriptions = { + "- Return \"\" if any of the arguments are NULL or invalid;", + "- Return a string from 'source_string' with all the substrings that match a regular expression 'regexp' " + + + "consecutively being replaced with 'replacement'.", + "Note: 'flags' is one of ('g' -> flag can be used when we want to match all the substrings that occur," + + + "'i' -> flag to ignore case for matching, 'x' -> flag to extend syntax (ignoring whitespace and " + + + "comments in regular expressions), 'm' and 'n' -> flag allows regular expressions to match " + + "across multiple lines)." + }, examples = { + "regexp_split_to_array(\"hello world\",\"\\s+\") = {hello, world}" + }) public class RegexpSplitToArrayFunction implements ValueParser { private ValueParser inputParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpSubstrFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpSubstrFunction.java index 2a49f691115..add7f765805 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpSubstrFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RegexpSubstrFunction.java @@ -31,12 +31,17 @@ import java.util.regex.Pattern; /** - * RegexpSubstrFunction - * description: REGEXP_SUBSTR(str, regexp)--Returns the first substring in str that matches regexp. - * Returns an STRING representation of the first matched substring. NULL if any of the arguments are NULL - * or regexp if invalid or pattern is not found. + * RegexpReplaceFunction -> REGEXP_SUBSTR(str, regexp) + * description: + * - Return NULL if any of the arguments are NULL or regexp if invalid or pattern is not found + * - Return the first substring in 'str' that matches 'regexp' */ -@TransformFunction(names = {"regex_substr"}) +@TransformFunction(names = {"regex_substr"}, parameter = "(String source_string, String regexp)", descriptions = { + "- Return \"\" if any of the arguments are NULL or regexp if invalid or pattern is not found;", + "- Return the first substring in 'str' that matches 'regexp'." +}, examples = { + "regex_substr(\"abc123def\", \"(\\\\d+)\") = 123" +}) public class RegexpSubstrFunction implements ValueParser { private ValueParser inputStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RepeatFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RepeatFunction.java index 9afd181ab4a..258d2197cbc 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RepeatFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RepeatFunction.java @@ -28,11 +28,17 @@ import java.util.List; /** - * RepeatFunction - * description: repeat(string, numeric)--Repeat the string numeric times and return a new string - * replicate(string, numeric)--Repeat the string numeric times and return a new string + * RepeatFunction -> repeat(str, times) + * description: + * - Return NULL if any parameter is null + * - Return a new string that repeats the 'str' by a certain number of 'times' */ -@TransformFunction(names = {"repeat", "replicate"}) +@TransformFunction(names = {"repeat", "replicate"}, parameter = "(String str, Integer times)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return a new string that repeats the 'str' by a certain number of 'times'." +}, examples = { + "repeat('apple', 2) = \"appleapple\"" +}) public class RepeatFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ReplaceFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ReplaceFunction.java index 71162417129..4327a47a271 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ReplaceFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ReplaceFunction.java @@ -29,10 +29,17 @@ import java.util.List; /** - * ReplaceFunction - * description: replace(s, s1, s2)--replace string s1 in string s with string s2. + * ReplaceFunction -> replace(s, s1, s2) + * description: + * - Return NULL if any parameter is null + * - Return the result of replacing string 's1' with string 's2' in string 's' */ -@TransformFunction(names = {"replace"}) +@TransformFunction(names = {"replace"}, parameter = "(String s, String s1, String s2)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return the result of replacing string 's1' with string 's2' in string 's'." +}, examples = { + "replace('Hello World', '', 'J') = \"JHJeJlJlJoJ JWJoJrJlJdJ\"" +}) public class ReplaceFunction implements ValueParser { private ValueParser stringParser; @@ -51,6 +58,9 @@ public Object parse(SourceData sourceData, int rowIndex, Context context) { Object strObj = stringParser.parse(sourceData, rowIndex, context); Object targetObj = targetParser.parse(sourceData, rowIndex, context); Object replacementObj = replacementParser.parse(sourceData, rowIndex, context); + if (strObj == null || targetObj == null || replacementObj == null) { + return null; + } String str = OperatorTools.parseString(strObj); String target = OperatorTools.parseString(targetObj); String replacement = OperatorTools.parseString(replacementObj); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ReverseFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ReverseFunction.java index 0e6a4f5229c..8720f605eb1 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ReverseFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/ReverseFunction.java @@ -25,11 +25,17 @@ import net.sf.jsqlparser.expression.Function; /** - * ReverseFunction - * description: reverse(string)--returns the string with the order of the characters reversed. - * returns NULL if string is a empty string. + * ReverseFunction -> reverse(str) + * description: + * - Return NULL if 'str' is a empty string or NULL + * - Return the 'str' with the order of the characters reversed */ -@TransformFunction(names = {"reverse"}) +@TransformFunction(names = {"reverse"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is a empty string or NULL;", + "- Return the 'str' with the order of the characters reversed." +}, examples = { + "reverse('apple') = \"elppa\"" +}) public class ReverseFunction implements ValueParser { private ValueParser stringParser; @@ -37,15 +43,6 @@ public ReverseFunction(Function expr) { stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); } - /** - * parse - * Parse and reverse string by reverse() in StringBuilder. - * @param sourceData - * @param rowIndex - * @param context - * @return - */ - @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj = stringParser.parse(sourceData, rowIndex, context); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RightFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RightFunction.java index 7bf067d9b54..5fb3879c3c1 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RightFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RightFunction.java @@ -29,13 +29,19 @@ import java.util.List; /** - * RightFunction - * description: right(string,length) - * - return null if either string or length is null - * - return "" if it is less than or equal to zero - * - return a substring of length starting from the right side of the string. + * RightFunction -> right(str,len) + * description: + * - Return NULL if either 'str' or 'len' is NULL + * - Return "" if it is less than or equal to zero + * - Return a substring of 'len' starting from the right side of the 'str'. */ -@TransformFunction(names = {"right"}) +@TransformFunction(names = {"right"}, parameter = "(String str)", descriptions = { + "- Return \"\" if either 'str' or 'len' is NULL;", + "- Return \"\" if it is less than or equal to zero;", + "- Return a substring of 'len' starting from the right side of the 'str'." +}, examples = { + "right('hello world',100) = \"hello world\"" +}) public class RightFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RpadFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RpadFunction.java index 0cbe784ac67..bd26141d449 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RpadFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RpadFunction.java @@ -29,16 +29,25 @@ import java.util.List; /** - * RpadFunction - * description: RPAD(s1,len,s2) : Fill string s2 at the end of string s1 to make the length of the string len - * - return null if any of the three parameters is null or len is less than 0 - * - return the substring of s1 with subscripts in the range of [0, len) if len is less than or equal to the length of s1 - * - if s2 is "" - * - return "" if len is longer than the length of s1 - * - if s2 is not "" - * - return the filled string + * RpadFunction -> RPAD(s1,len,s2) + * description: + * - Return NULL if any of the three parameters is NULL or 'len' is less than 0 + * - Return the substring of 's1' with subscripts in the range of [0, 'len') if 'len' is less than or equal to the length of 's1' + * - Return "" if 's2' is "" and 'len' is longer than the length of 's1' + * - Return the result string of padding string 's2' at the end of string 's1' to make the length of the string 'len' + * if 's2' is not "" */ -@TransformFunction(names = {"rpad"}) +@TransformFunction(names = {"rpad"}, parameter = "(String str)", descriptions = { + "- Return \"\" if any of the three parameters is NULL or 'len' is less than 0;", + "- Return the substring of 's1' with subscripts in the range of [0, 'len') if 'len' is less " + + "than or equal to the length of 's1';", + "- Return \"\" if 's2' is \"\" and 'len' is longer than the length of 's1';", + "- Return the result string of padding string 's2' at the end of string 's1' to make the length of the " + + "string 'len' if 's2' is not \"\"." +}, examples = { + "rpad('he',1,'xxd') = \"h\"", + "rpad('he',7,'') = \"\"" +}) public class RpadFunction implements ValueParser { private final ValueParser leftStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RtrimFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RtrimFunction.java index 4c4b1decbb4..a9717646c76 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RtrimFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/RtrimFunction.java @@ -26,12 +26,17 @@ import net.sf.jsqlparser.expression.Function; /** - * TrimFunction - * description: rtrim(string) - * - Return NULL if str is NULL. - * - Return the string str with trailing space characters removed. + * RtrimFunction -> rtrim(str) + * description: + * - Return NULL if 'str' is NULL + * - Return the string 'str' with trailing space characters removed */ -@TransformFunction(names = {"rtrim"}) +@TransformFunction(names = {"rtrim"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the string 'str' with trailing space characters removed." +}, examples = { + "rtrim(' in long ') = \" in long\"" +}) public class RtrimFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SoundexFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SoundexFunction.java index 80f8394eed0..d425b69fa9b 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SoundexFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SoundexFunction.java @@ -28,11 +28,17 @@ import java.nio.charset.StandardCharsets; /** - * SoundexFunction - * description: soundex(string)---Returns a four character code representing the sound of a string. This method returns a string, or null if parameter is null. - * See https://en.wikipedia.org/wiki/Soundex for more information. + * SoundexFunction -> soundex(str) + * description: + * - Return NULL if 'str' is NULL + * - Return a four character code representing the sound of 'str' */ -@TransformFunction(names = {"soundex"}) +@TransformFunction(names = {"soundex"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return a four character code representing the sound of 'str'." +}, examples = { + "soundex('hello world') = \"H464\"" +}) public class SoundexFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SpaceFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SpaceFunction.java index d983300a0bd..6632398432e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SpaceFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SpaceFunction.java @@ -26,13 +26,18 @@ import net.sf.jsqlparser.expression.Function; /** - * SpaceFunction - * description: SPACE(N) - * - return NULL if N is NULL. - * - return "" if N is less than or equal to 0 - * - return a string consisting of N space characters + * SpaceFunction -> SPACE(N) + * description: + * - Return NULL if 'N' is NULL + * - Return "" if 'N' is less than or equal to 0 + * - Return a string consisting of 'N' space characters */ -@TransformFunction(names = {"space"}) +@TransformFunction(names = {"space"}, parameter = "(Integer N)", descriptions = { + "- Return \"\" if 'N' is NULL or less than or equal to 0;", + "- Return a string consisting of 'N' space characters." +}, examples = { + "space(5) = \" \"" +}) public class SpaceFunction implements ValueParser { private final ValueParser cntParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SplitIndexFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SplitIndexFunction.java index f5489a469b5..c879819f5ee 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SplitIndexFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SplitIndexFunction.java @@ -27,17 +27,22 @@ import net.sf.jsqlparser.expression.Function; import java.util.List; -/* - * SplitIndexFunction - * - * Description: - * Split_index(string1, string2, integer) -> string - * Splits string1 by delimiter string2 and returns the string at the given index integer(zero-based). - * - Returns null if the index is negative or any of the arguments is null. - * - Returns null if the index is out of bounds of the split strings. - * + +/** + * SplitIndexFunction -> Split_index(str, delimiter, index) + * description: + * - Return NULL if the index is negative or any of the arguments is NULL + * - Return NULL if the index is out of bounds of the split strings + * - Return the string at the given 'index' integer(zero-based) after splitting 'str' by 'delimiter' */ -@TransformFunction(names = {"split_index", "splitindex"}) +@TransformFunction(names = {"split_index", + "splitindex"}, parameter = "(String str, String delimiter, Integer index)", descriptions = { + "- Return \"\" if the index is negative or any of the arguments is NULL;", + "- Return \"\" NULL if the index is out of bounds of the split strings;", + "- Return the string at the given 'index' integer(zero-based) after splitting 'str' by 'delimiter'." + }, examples = { + "split_index('a,b,c', ',', 1) = \"b\"" + }) public class SplitIndexFunction implements ValueParser { private final ValueParser strParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StartsWithFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StartsWithFunction.java index ff2b747b461..ad3579931d3 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StartsWithFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StartsWithFunction.java @@ -29,10 +29,17 @@ import java.util.List; /** - * StartsWithFunction - * description: Returns whether expr starts with startExpr. + * StartsWithFunction -> startswith(s1,s2) + * description: + * - Return NULL if either argument is NULL; + * - Return whether 's2' starts with 's2'. */ -@TransformFunction(names = {"startswith"}) +@TransformFunction(names = {"startswith"}, parameter = "(String s1, String s2)", descriptions = { + "- Return \"\" if either argument is NULL;", + "- Return whether 's2' starts with 's2'." +}, examples = { + "startswith('Apache InLong', 'A') = true" +}) public class StartsWithFunction implements ValueParser { private ValueParser exprParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StrToMapFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StrToMapFunction.java index 58de7fb35e9..5e653e399d0 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StrToMapFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StrToMapFunction.java @@ -30,14 +30,26 @@ import java.util.List; import java.util.Map; /** - * StrToMapFunction - * description: str_to_map(string1, string2, string3) - Returns a map after splitting the string1 into key/value pairs - * using delimiters. string2 is the pair delimiter, default is ‘,’. And string3 is the key-value delimiter, - * default is ‘=’. Both pair delimiter and key-value delimiter are treated as regular expressions.So special - * characters (e.g. <([{^-=$!|]})?*+.>) need to be properly escaped before using as a delimiter literally. - * for example: STR_TO_MAP('item1:10,item2:5,item3:2', ':', ',')--{'item1' -> 10, 'item2' -> 5, 'item3' -> 2} + * StrToMapFunction -> str_to_map(str, pairDelimiter, keyValueDelimiter) + * description: + * - Return NULL if 'str' is NULL + * - Return a map after splitting the 'str' into key/value pairs using 'pairDelimiter'(default is ',') + * and 'keyValueDelimiter'(default is '=') + * Note: Both 'pairDelimiter' and 'keyValueDelimiter' are treated as regular expressions.So special characters + * (e.g. <([{^-=$!|]})?*+.>) need to be properly escaped before using as a delimiter literally. */ -@TransformFunction(names = {"str_to_map"}) +@TransformFunction(names = { + "str_to_map"}, parameter = "(String s1, String pairDelimiter, String keyValueDelimiter)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return a map after splitting the 'str' into key/value pairs using 'pairDelimiter'(default is ',') " + + "and 'keyValueDelimiter'(default is '=');", + "Note: Both 'pairDelimiter' and 'keyValueDelimiter' are treated as regular expressions.So special " + + "characters(e.g. <([{^-=$!|]})?*+.>) need to be properly escaped before using as a delimiter " + + "literally." + }, examples = { + "str_to_map('key1=value1,key2=value2,key3=value3') = {key1=value1, key2=value2, key3=value3}", + "str_to_map(\"name->John!age->30!city->China\" , \"!\" , \"->\") = {name=John, age=30, city=China}" + }) public class StrToMapFunction implements ValueParser { private ValueParser inputParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StrcmpFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StrcmpFunction.java index 9369b342fa1..5145b7b5672 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StrcmpFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/StrcmpFunction.java @@ -29,14 +29,21 @@ import java.util.List; /** - * StrcmpFunction - * description: strcmp(s1,s2) - * return NULL if either argument is NULL - * return 0 if the strings are the same - * return -1 if the first argument is smaller than the second according to the current sort order - * return 1 otherwise + * StrcmpFunction -> strcmp(s1,s2) + * description: + * - Return NULL if either argument is NULL + * - Return 0 if the strings are the same + * - Return -1 if the first argument is smaller than the second according to the current sort order + * - Return 1 otherwise */ -@TransformFunction(names = {"strcmp"}) +@TransformFunction(names = {"strcmp"}, parameter = "(String s1, String s2)", descriptions = { + "- Return \"\" if either argument is NULL;", + "- Return 0 if the strings are the same;", + "- Return -1 if 's1' is smaller than 's2' according to the current sort order;", + "- Return 1 otherwise." +}, examples = { + "strcmp('hello world','banana') = 1" +}) public class StrcmpFunction implements ValueParser { private final ValueParser leftStringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SubstringFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SubstringFunction.java index ab5503f4b96..5a5d59f71fe 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SubstringFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SubstringFunction.java @@ -30,11 +30,19 @@ import java.util.List; /** - * SubstringFunction -> substring(string FROM INT1 [ FOR INT2 ]) + * SubstringFunction -> substring(str FROM pos [ FOR len ]) or substring(str,pos,len) * description: - * return a substring of STRING starting from position INT1 with length INT2 (to the end by default) + * - Return NULL if 'str' is NULL + * - Return a substring of 'str' starting from position 'pos' with length 'len' (to the end by default) */ -@TransformFunction(names = {"substring", "substr", "mid"}) +@TransformFunction(names = {"substring", "substr", + "mid"}, parameter = "(String s1, Integer pos, Integer len)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return a substring of 'str' starting from position 'pos' with length 'len' (to the end by default).", + "Note: This function also supports \"substring(str FROM pos [ FOR len ])\"." + }, examples = { + "substring('apple', 1, 3) = \"app\"" + }) public class SubstringFunction implements ValueParser { private ValueParser stringParser; @@ -60,6 +68,9 @@ public SubstringFunction(Function expr) { public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj = stringParser.parse(sourceData, rowIndex, context); Object startPositionObj = startPositionParser.parse(sourceData, rowIndex, context); + if (stringObj == null || startPositionObj == null) { + return null; + } String str = OperatorTools.parseString(stringObj); int start = OperatorTools.parseBigDecimal(startPositionObj).intValue(); if (start > str.length()) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SubstringIndexFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SubstringIndexFunction.java index 3dce677d236..3a23b5c49c9 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SubstringIndexFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/SubstringIndexFunction.java @@ -31,12 +31,21 @@ /** * SubstringIndexFunction -> SUBSTRING_INDEX(str,delim,count) - * description: Returns the substring from string str before count occurrences of the delimiter delim - * return NULL if any parameter is NULL; - * return everything to the left of the final delimiter (counting from the left) if count is positive; - * return everything to the right of the final delimiter (counting from the right) if count is negative. + * description: + * - Return NULL if any parameter is NULL; + * - Return everything to the left of the last count occurrences of 'delim' (counting from the left), if 'count' is positive; + * - Return everything to the right of the last count occurrences of 'delim' (counting from the right) if 'count' is negative. */ -@TransformFunction(names = {"substring_index"}) +@TransformFunction(names = { + "substring_index"}, parameter = "(String str, String delim, Integer count)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return everything to the left of the last count occurrences of 'delim' (counting from the " + + "left), if 'count' is positive;", + "- Return everything to the right of the last count occurrences of 'delim' (counting from the " + + "right) if 'count' is negative." + }, examples = { + "SUBSTRING_INDEX('AA. ',' ',1) = \"AA.\"" + }) public class SubstringIndexFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/TranslateFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/TranslateFunction.java index 5f87580d62e..af692ca1ad5 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/TranslateFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/TranslateFunction.java @@ -33,26 +33,21 @@ import java.util.Map; /** - * TranslateFunction - * translate(expression, find_chars, replace_chars) - * Description: - * For a given expression, replaces all occurrences of specified characters with specified substitutes. - * Existing characters are mapped to replacement characters by their positions in the find_chars and replace_chars arguments. - * If more characters are specified in the find_chars argument than in the replace_chars argument, the extra characters from the find_chars argument are omitted in the return value. - * - * Translate function is similar to the replace function and the regexp_replace function, - * except that replace substitutes one entire string with another string and regexp_replace lets you search a string for a regular expression pattern, - * while translate makes multiple single-character substitutions. - * - * Arguments: - * expression: The expression to be translated. - * find_chars: A string containing the characters to be replaced. - * replace_chars: A string containing the characters to substitute. - * examples: - * case1: translate(harry@inlong.com, '@', '.') -> original_expression: harry@inlong.com target_expression: harry.inlong.com - * case2: translate(hello WorD, 'WD', 'wd') -> original_expression: hello WorD target_expression: hello word + * TranslateFunction -> translate(origin_string, find_chars, replace_chars) + * description: + * - Return NULL if any parameter is NULL; + * - Return the result of replacing all occurrences of both 'find_chars' and 'origin_string' with the characters in 'replace_chars'. + * Note: If more characters are specified in the find_chars argument than in the replace_chars argument, the + * extra characters from the find_chars argument are omitted in the return value. */ -@TransformFunction(names = {"translate"}) +@TransformFunction(names = { + "translate"}, parameter = "(String origin_string, String find_chars, String replace_chars)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return the result of replacing all occurrences of both 'find_chars' and 'origin_string' with the characters in 'replace_chars'." + }, examples = { + "translate(apache@inlong.com, '@', '.') = \"apache.inlong.com\"", + "translate(hello WorD, 'WD', 'wd') = \"hello word\"" + }) public class TranslateFunction implements ValueParser { private ValueParser originalStrParser; @@ -73,6 +68,9 @@ public Object parse(SourceData sourceData, int rowIndex, Context context) { Object originalStrObject = originalStrParser.parse(sourceData, rowIndex, context); Object findCharsObject = findCharsParser.parse(sourceData, rowIndex, context); Object replaceCharsObject = replaceCharsParser.parse(sourceData, rowIndex, context); + if (originalStrObject == null || findCharsObject == null || replaceCharsObject == null) { + return null; + } String originalStr = OperatorTools.parseString(originalStrObject); String findChars = OperatorTools.parseString(findCharsObject); String replaceChars = OperatorTools.parseString(replaceCharsObject); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/TrimFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/TrimFunction.java index 744f1953f15..be22bb20d88 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/TrimFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/TrimFunction.java @@ -26,11 +26,17 @@ import net.sf.jsqlparser.expression.Function; /** - * TrimFunction - * description: trim(string)--Remove Spaces before and after the string. - * btrim(string)--Remove Spaces before and after the string. + * TrimFunction -> trim(str) or btrim(string) + * description: + * - Return NULL if 'str' is NULL; + * - Return the result of deleting spaces before and after the 'str'. */ -@TransformFunction(names = {"trim", "btrim"}) +@TransformFunction(names = {"trim", "btrim"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the result of deleting spaces before and after the 'str'." +}, examples = { + "trim(' in long ') = \"in long\"" +}) public class TrimFunction implements ValueParser { private ValueParser stringParser; @@ -42,6 +48,9 @@ public TrimFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj = stringParser.parse(sourceData, rowIndex, context); + if (stringObj == null) { + return null; + } return OperatorTools.parseString(stringObj).trim(); } } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UnHexFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UnHexFunction.java index f67ae34cf36..2f96ba45236 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UnHexFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UnHexFunction.java @@ -27,11 +27,18 @@ /** * UnHexFunction -> unhex(str) - * description: unhex(str) interprets each pair of characters in the argument as a hexadecimal number and converts it to the byte represented by the number. - * return null if str is null; - * return a binary string otherwise. + * description: + * Return null if 'str' is null; + * Return the result of interpreting each pair of characters in the argument as the character corresponding + * to its hexadecimal number. */ -@TransformFunction(names = {"unhex"}) +@TransformFunction(names = {"unhex"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the result of interpreting each pair of characters in the argument as the character" + + " corresponding to its hexadecimal number.", +}, examples = { + "unhex(\"696E6C6F6E67\") = \"inlong\"" +}) public class UnHexFunction implements ValueParser { private ValueParser valueParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UpperFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UpperFunction.java index 465dec10c82..ebdf72f001c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UpperFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UpperFunction.java @@ -26,10 +26,17 @@ import net.sf.jsqlparser.expression.Function; /** - * UpperFunction - * description: UPPER(s): Convert a string to uppercase + * UpperFunction -> UPPER(s) + * description: + * - Return NULL if 's' is NULL; + * - Return the result of converting 's' to uppercase */ -@TransformFunction(names = {"upper", "ucase"}) +@TransformFunction(names = {"upper", "ucase"}, parameter = "(String s)", descriptions = { + "- Return \"\" if 's' is NULL;", + "- Return the result of converting 's' to uppercase" +}, examples = { + "upper(\"ApPlE\") = \"APPLE\"" +}) public class UpperFunction implements ValueParser { private ValueParser stringParser; @@ -41,8 +48,9 @@ public UpperFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj = stringParser.parse(sourceData, rowIndex, context); - if (stringObj == null) + if (stringObj == null) { return null; + } return stringObj.toString().toUpperCase(); } } diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlDecodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlDecodeFunction.java index d39beedef98..7e8282d4f67 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlDecodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlDecodeFunction.java @@ -29,12 +29,22 @@ import java.nio.charset.StandardCharsets; /** - * UrlDecodeFunction - * description: Decodes a given string in ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme. - * If the input is NULL, or there is an issue with the decoding process(such as encountering an illegal escape pattern), - * or the encoding scheme is not supported, the function returns NULL. + * UrlDecodeFunction -> url_decode(str) + * description: + * - Return NULL if 'str' is NULL, or there is an issue with the decoding process(such as encountering an illegal + * escape pattern), or the encoding scheme is not supported; + * - Return the result of decoding a given 'str' in 'application/x-www-form-urlencoded' format using the UTF-8 encoding scheme. */ -@TransformFunction(names = {"url_decode"}) +@TransformFunction(names = {"url_decode"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL, or there is an issue with the decoding process(such as encountering an illegal " + + + "escape pattern), or the encoding scheme is not supported;", + "- Return the result of decoding a given 'str' in 'application/x-www-form-urlencoded' format using the UTF-8 " + + "encoding scheme." +}, examples = { + "url_decode('https%3A%2F%2Fapache.inlong.com%2Fsearch%3Fq%3Djava+url+encode') = " + + "\"https://apache.inlong.com/search?q=java url encode\"" +}) public class UrlDecodeFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlEncodeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlEncodeFunction.java index a165129e948..eba61f51656 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlEncodeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UrlEncodeFunction.java @@ -29,12 +29,22 @@ import java.nio.charset.StandardCharsets; /** - * UrlEncodeFunction - * description: Translates a string into ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme. - * If the input is NULL, or there is an issue with the encoding process, - * or the encoding scheme is not supported, will return NULL. + * UrlEncodeFunction -> url_encode(str) + * description: + * - Return NULL if 'str' is NULL, or there is an issue with the decoding process(such as encountering an illegal + * escape pattern), or the encoding scheme is not supported; + * - Return the result of translating 'str' into ‘application/x-www-form-urlencoded’ format using the UTF-8 encoding scheme. */ -@TransformFunction(names = {"url_encode"}) +@TransformFunction(names = {"url_encode"}, parameter = "(String str)", descriptions = { + "- Return \"\" if 'str' is NULL, or there is an issue with the decoding process(such as encountering an illegal " + + + "escape pattern), or the encoding scheme is not supported;", + "- Return the result of translating 'str' into 'application/x-www-form-urlencoded' format using the UTF-8 " + + "encoding scheme." +}, examples = { + "url_encode('https://apache.inlong.com/search?q=java url encode') = " + + "\"https%3A%2F%2Fapache.inlong.com%2Fsearch%3Fq%3Djava+url+encode\"" +}) public class UrlEncodeFunction implements ValueParser { private final ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UuidFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UuidFunction.java index aa109637ad8..178f5ad1e2e 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UuidFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/string/UuidFunction.java @@ -25,11 +25,18 @@ import net.sf.jsqlparser.expression.Function; import java.util.UUID; + /** - * UuidFunction - * returns a UUID (universally unique identifier) string based on RFC 4122 Type 4 (pseudo-randomly generated) UUID + * UuidFunction -> UPPER(s) + * description: + * - Return a UUID (universally unique identifier) string based on RFC 4122 Type 4 (pseudo-randomly generated) UUID. */ -@TransformFunction(names = {"uuid"}) +@TransformFunction(names = {"uuid"}, parameter = "(String s)", descriptions = { + "- Return a UUID (universally unique identifier) string based on RFC 4122 Type 4 " + + "(pseudo-randomly generated) UUID." +}, examples = { + "uuid()" +}) public class UuidFunction implements ValueParser { private final UUID uuid; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ConvertTzFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ConvertTzFunction.java index 4d471416cd5..5334bd05b64 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ConvertTzFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ConvertTzFunction.java @@ -23,6 +23,7 @@ import org.apache.inlong.sdk.transform.process.operator.OperatorTools; import org.apache.inlong.sdk.transform.process.parser.ValueParser; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Function; @@ -31,15 +32,27 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.List; + /** - * ConvertTzFunction - * Description: CONVERT_TZ(string1, string2, string3)--Converts a datetime string1 (with default ISO timestamp format - * ‘yyyy-MM-dd HH:mm:ss’) from time zone string2 to time zone string3. The format of time zone should be - * either an abbreviation such as “PST”, a full name such as “America/Los_Angeles”, or a custom ID such - * as “GMT-08:00”. - * for example: CONVERT_TZ(‘1970-01-01 00:00:00’, ‘UTC’, ‘America/Los_Angeles’) returns ‘1969-12-31 16:00:00’. + * ConvertTzFunction -> CONVERT_TZ(string1, string2, string3) + * description: + * - Return NULL if any parameter is NULL + * - Return the result of converts a datetime string1 (with default ISO timestamp format yyyy-MM-dd HH:mm:ss’) from time + * zone string2 to time zone string3. + * Note: The format of time zone should beeither an abbreviation such as “PST”, a full name such as + * “America/Los_Angeles”, or a custom ID suchas “GMT-08:00”. */ -@TransformFunction(names = {"convert_tz"}) +@Slf4j +@TransformFunction(names = {"convert_tz"}, parameter = "(String leftStr , String rightStr)", descriptions = { + "- Return NULL if any parameter is NULL;", + "- Return the result of converts a datetime 'string1' (with default ISO timestamp format yyyy-MM-dd HH:mm:ss’) " + + + "from time zone 'string2' to time zone 'string3'.", + "Note: The format of time zone should be either an abbreviation such as “PST”, " + + "a full name such as “America/Los_Angeles”, or a custom ID such as “GMT-08:00”." +}, examples = { + "CONVERT_TZ('1970-01-01 00:00:00', 'UTC', 'America/Los_Angeles') = \"1969-12-31 16:00:00\"" +}) public class ConvertTzFunction implements ValueParser { private ValueParser dateTimeParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateAddFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateAddFunction.java index 44e3e35d6d9..3e39b5b1cd8 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateAddFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateAddFunction.java @@ -31,22 +31,33 @@ import java.util.List; /** - * DateAddFunction + * DateAddFunction -> DATE_ADD(dateStr,INTERVAL intervalExprStr KEYWORD) * Description: - * - return NULL if date is NULL. - * - return DATE if the date argument is a DATE value and your calculations involve only YEAR, MONTH, and DAY parts + * - Return NULL if dateStr is NULL. + * - Return DATE if the date argument is a DATE value and your calculations involve only YEAR, MONTH, and DAY parts * (that is, no time parts). - * - return TIME if the date argument is a TIME value and the calculations involve only HOURS, MINUTES, + * - Return TIME if the date argument is a TIME value and the calculations involve only HOURS, MINUTES, * and SECONDS parts (that is, no date parts). - * - return DATETIME if the first argument is a DATETIME (or TIMESTAMP) value, or if the first argument is a DATE + * - Return DATETIME if the first argument is a DATETIME (or TIMESTAMP) value, or if the first argument is a DATE * and the unit value uses HOURS, MINUTES, or SECONDS, or if the first argument is of type TIME and the * unit value uses YEAR, MONTH, or DAY. - * - return If the first argument is a dynamic parameter (for example, of a prepared statement), its resolved type - * is DATE if the second argument is an interval that contains some combination of YEAR, MONTH, or DAY values - * only; otherwise, its type is DATETIME. - * - return String otherwise (type VARCHAR). + * - Return String otherwise (type VARCHAR). + * Note: Regarding the type of KEYWORD, please refer to the description of Interval on the MySQL official website. */ -@TransformFunction(names = {"date_add"}) +@TransformFunction(names = {"date_add"}, parameter = "(String dateStr,String intervalExprStr)", descriptions = { + "- Return \"\" if 'dateStr' is NULL;", + "- Return DATE if 'dateStr' is a DATE value and your calculations involve only YEAR, MONTH, and DAY parts(that is, no time parts);", + "- Return TIME if 'dateStr' is a TIME value and the calculations involve only HOURS, MINUTES,and SECONDS parts (that is, no date parts);", + "- Return DATETIME if the first argument is a DATETIME (or TIMESTAMP) value, or if the first argument is a DATE" + + + "and the unit value uses HOURS, MINUTES, or SECONDS, or if the first argument is of type TIME and the" + + "unit value uses YEAR, MONTH, or DAY;", + "- Return String otherwise (type VARCHAR).", + "Note: Regarding intervalExpr, please refer to the MySQL official website." +}, examples = { + "date_add('2020-12-31 23:59:59',INTERVAL 999 DAY) = \"2023-09-26 23:59:59\"", + "DATE_ADD('1992-12-31 23:59:59', INTERVAL '-1.999999' SECOND_MICROSECOND) = \"1992-12-31 23:59:57.000001\"" +}) public class DateAddFunction implements ValueParser { private final ValueParser datetimeParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateDiffFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateDiffFunction.java index 5d9df23fff3..a1f74171c67 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateDiffFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateDiffFunction.java @@ -33,13 +33,20 @@ import java.util.Objects; /** - * DateDiffFunction - * description: DATEDIFF(d1, d2) - * - return null if one of the two parameters is null or "" - * - return null if one of the two parameters has an incorrect date format - * - return the number of days between the dates d1->d2. + * DateDiffFunction -> datediff(dateStr1, dateStr2) + * Description: + * - Return null if one of the two parameters is null or "" + * - Return null if one of the two parameters has an incorrect date format + * - Return the number of days between the dates dateStr1->dateStr2. */ -@TransformFunction(names = {"datediff", "date_diff"}) +@TransformFunction(names = {"datediff"}, parameter = "(String dateStr1, String dateStr2)", descriptions = { + "- Return \"\" if one of the two parameters is null or \"\";", + "- Return \"\" if one of the two parameters has an incorrect date format;", + "- Return the number of days between the dates 'dateStr1'->'dateStr2'." +}, examples = { + "datediff('2018-12-10 12:30:00', '2018-12-09 13:30:00') = 1", + "datediff('2018-12', '2018-12-12') = \"\"" +}) public class DateDiffFunction implements ValueParser { private final ValueParser leftDateParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateExtractFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateExtractFunction.java index 244bc0742f6..379704d9a40 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateExtractFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateExtractFunction.java @@ -55,7 +55,12 @@ public enum DateExtractFunctionType { YEAR, QUARTER, MONTH, WEEK, DAY_OF_YEAR, DAY_OF_MONTH, DAY_OF_WEEK, DAY_NAME } - @TransformFunction(names = {"year"}) + @TransformFunction(names = {"year"}, parameter = "(String dateStr)", descriptions = { + "- Return \"\" if 'dateStr' is null;", + "- Return the year from SQL date." + }, examples = { + "year(2024-08-08) = 2024" + }) public static class YearExtractFunction extends DateExtractFunction { public YearExtractFunction(Function expr) { @@ -63,7 +68,12 @@ public YearExtractFunction(Function expr) { } } - @TransformFunction(names = {"quarter"}) + @TransformFunction(names = {"quarter"}, parameter = "(String dateStr)", descriptions = { + "- Return \"\" if 'dateStr' is null;", + "- Return the quarter of a year (an integer between 1 and 4) from 'dateStr'." + }, examples = { + "quarter(2024-08-08) = 3" + }) public static class QuarterExtractFunction extends DateExtractFunction { public QuarterExtractFunction(Function expr) { @@ -71,7 +81,12 @@ public QuarterExtractFunction(Function expr) { } } - @TransformFunction(names = {"month"}) + @TransformFunction(names = {"month"}, parameter = "(String dateStr)", descriptions = { + "- Return \"\" if 'dateStr' is null;", + "- Return the month of a year (an integer between 1 and 12) from 'dateStr'." + }, examples = { + "month(2024-08-08) = 8" + }) public static class MonthExtractFunction extends DateExtractFunction { public MonthExtractFunction(Function expr) { @@ -79,7 +94,12 @@ public MonthExtractFunction(Function expr) { } } - @TransformFunction(names = {"week"}) + @TransformFunction(names = {"week"}, parameter = "(String dateStr)", descriptions = { + "- Return \"\" if 'dateStr' is null;", + "- Return the week of a year (an integer between 1 and 53) from 'dateStr'." + }, examples = { + "week(2024-02-29) = 9" + }) public static class WeekExtractFunction extends DateExtractFunction { public WeekExtractFunction(Function expr) { @@ -87,7 +107,12 @@ public WeekExtractFunction(Function expr) { } } - @TransformFunction(names = {"day_of_year", "dayofyear"}) + @TransformFunction(names = {"day_of_year", "dayofyear"}, parameter = "(String dateStr)", descriptions = { + "- Return \"\" if 'dateStr' is null;", + "- Return the day of a year (an integer between 1 and 366) from 'dateStr'." + }, examples = { + "dayofyear(2024-02-29) = 60" + }) public static class DayOfYearExtractFunction extends DateExtractFunction { public DayOfYearExtractFunction(Function expr) { @@ -95,7 +120,12 @@ public DayOfYearExtractFunction(Function expr) { } } - @TransformFunction(names = {"day_of_month", "dayofmonth"}) + @TransformFunction(names = {"day_of_month", "dayofmonth"}, parameter = "(String dateStr)", descriptions = { + "- Return \"\" if 'dateStr' is null;", + "- Return the day of a month (an integer between 1 and 31) from 'dateStr'." + }, examples = { + "dayofmonth(2024-02-29) = 29" + }) public static class DayOfMonthExtractFunction extends DateExtractFunction { public DayOfMonthExtractFunction(Function expr) { @@ -103,7 +133,12 @@ public DayOfMonthExtractFunction(Function expr) { } } - @TransformFunction(names = {"day_of_week", "dayofweek"}) + @TransformFunction(names = {"day_of_week", "dayofweek"}, parameter = "(String dateStr)", descriptions = { + "- Return \"\" if 'dateStr' is null;", + "- Return the day of a week (an integer between 1(Sunday) and 7(Saturday)) from 'dateStr'." + }, examples = { + "dayofweek(2024-02-29) = 5" + }) public static class DayOfWeekExtractFunction extends DateExtractFunction { public DayOfWeekExtractFunction(Function expr) { @@ -111,7 +146,12 @@ public DayOfWeekExtractFunction(Function expr) { } } - @TransformFunction(names = {"day_name", "dayname"}) + @TransformFunction(names = {"day_name", "dayname"}, parameter = "(String dateStr)", descriptions = { + "- Return \"\" if 'dateStr' is null;", + "- Return the name of the day of the week from 'dateStr'." + }, examples = { + "dayname(2024-02-29) = THURSDAY" + }) public static class DayNameExtractFunction extends DateExtractFunction { public DayNameExtractFunction(Function expr) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateFormatFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateFormatFunction.java index d914cf9674d..0ebc3b38d9d 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateFormatFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateFormatFunction.java @@ -34,39 +34,38 @@ import java.util.concurrent.ConcurrentHashMap; /** - * DateFormatFunction - * description: date_format(timestamp,format)--converts timestamp(in seconds) to a value of string in the format - * specified by the date format string. The format string is compatible with Java’s SimpleDateFormat + * DateFormatFunction -> date_format(timestamp,format) + * Description: + * - Return NULL if any parameter is NULL + * - Return a string value that converts a timestamp (in seconds) to a date format string in the specified format + * Note: The format string is compatible with Java’s SimpleDateFormat */ -@TransformFunction(names = {"date_format"}) +@TransformFunction(names = {"date_format"}, parameter = "(String timestampStr, String formatStr)", descriptions = { + "- Return \"\" if any parameter is NULL;", + "- Return a string value that converts a timestamp (in seconds) to a date format string in the specified format.", + "Note: The format string is compatible with Java’s SimpleDateFormat" +}, examples = { + "date_format('2024-08-01 22:56:56', 'yyyy/MM/dd HH:mm:ss') = \"2024/08/01 22:56:56\"" +}) public class DateFormatFunction implements ValueParser { private ValueParser timestampParser; private ValueParser formatParser; private static final Map SIMPLE_DATE_FORMATS = new ConcurrentHashMap<>(); - /** - * Constructor - * - * @param expr - */ public DateFormatFunction(Function expr) { List expressions = expr.getParameters().getExpressions(); timestampParser = OperatorTools.buildParser(expressions.get(0)); formatParser = OperatorTools.buildParser(expressions.get(1)); } - /** - * parse - * - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object timestampObj = timestampParser.parse(sourceData, rowIndex, context); Object formatObj = formatParser.parse(sourceData, rowIndex, context); + if (timestampObj == null || formatObj == null) { + return null; + } Timestamp timestamp = OperatorTools.parseTimestamp(timestampObj); String format = OperatorTools.parseString(formatObj); SimpleDateFormat sdf = getSimpleDateFormat(format); @@ -74,12 +73,6 @@ public Object parse(SourceData sourceData, int rowIndex, Context context) { return sdf.format(date); } - /** - * getSimpleDateFormat - * - * @param pattern - * @return - */ private SimpleDateFormat getSimpleDateFormat(String pattern) { SimpleDateFormat sdf = SIMPLE_DATE_FORMATS.get(pattern); if (sdf == null) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateSubFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateSubFunction.java index ffcd73b639f..6dba6118205 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateSubFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/DateSubFunction.java @@ -31,22 +31,34 @@ import java.util.List; /** - * DateAddFunction + * DateSubFunction -> DATE_SUB(dateStr,INTERVAL intervalExprStr KEYWORD) * Description: - * - return NULL if date is NULL. - * - return DATE if the date argument is a DATE value and your calculations involve only YEAR, MONTH, and DAY parts + * - Return NULL if dateStr is NULL. + * - Return DATE if the date argument is a DATE value and your calculations involve only YEAR, MONTH, and DAY parts * (that is, no time parts). - * - return TIME if the date argument is a TIME value and the calculations involve only HOURS, MINUTES, + * - Return TIME if the date argument is a TIME value and the calculations involve only HOURS, MINUTES, * and SECONDS parts (that is, no date parts). - * - return DATETIME if the first argument is a DATETIME (or TIMESTAMP) value, or if the first argument is a DATE + * - Return DATETIME if the first argument is a DATETIME (or TIMESTAMP) value, or if the first argument is a DATE * and the unit value uses HOURS, MINUTES, or SECONDS, or if the first argument is of type TIME and the * unit value uses YEAR, MONTH, or DAY. - * - return If the first argument is a dynamic parameter (for example, of a prepared statement), its resolved type - * is DATE if the second argument is an interval that contains some combination of YEAR, MONTH, or DAY values - * only; otherwise, its type is DATETIME. - * - return String otherwise (type VARCHAR). + * - Return String otherwise (type VARCHAR). + * Note: Regarding the type of KEYWORD, please refer to the description of Interval on the MySQL official website. */ -@TransformFunction(names = {"date_sub", "datesub"}) +@TransformFunction(names = {"date_sub", + "datesub"}, parameter = "(String dateStr,String intervalExprStr)", descriptions = { + "- Return \"\" if 'dateStr' is NULL;", + "- Return DATE if the date argument is a DATE value and your calculations involve only YEAR, MONTH, and DAY parts(that is, no time parts);", + "- Return TIME if the date argument is a TIME value and the calculations involve only HOURS, MINUTES,and SECONDS parts (that is, no date parts);", + "- Return DATETIME if the first argument is a DATETIME (or TIMESTAMP) value, or if the first argument is a DATE" + + + "and the unit value uses HOURS, MINUTES, or SECONDS, or if the first argument is of type TIME and the" + + + "unit value uses YEAR, MONTH, or DAY;", + "- Return String otherwise (type VARCHAR).", + "Note: Regarding 'intervalExpr', please refer to the MySQL official website." + }, examples = { + "DATE_SUB('1992-12-31 23:59:59', INTERVAL '-1.999999' SECOND_MICROSECOND) = \"1993-01-01 00:00:00.999999\"" + }) public class DateSubFunction implements ValueParser { private final ValueParser datetimeParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/FromUnixTimeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/FromUnixTimeFunction.java index 20deecdbc5a..5de24fc69b9 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/FromUnixTimeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/FromUnixTimeFunction.java @@ -37,12 +37,23 @@ import java.util.concurrent.ConcurrentHashMap; /** - * FromUnixTimeFunction - * description: form_unixtime(numeric[, string])--returns a representation of the numeric argument as a value in string - * format(default is ‘yyyy-MM-dd HH:mm:ss’). numeric is an internal timestamp value representing seconds - * since ‘1970-01-01 00:00:00’ UTC, such as produced by the UNIX_TIMESTAMP() function. + * FromUnixTimeFunction -> form_unixtime(numeric[, formatStr]) + * description: + * - Return NULL if numeric is NULL + * - Return a representation of the numeric argument as a value in string + * Note: formatStr defaults to 'yyyy-MM-dd HH:mm:ss'. numeric is an internal timestamp value representing seconds + * since ‘1970-01-01 00:00:00’ UTC, such as produced by the UNIX_TIMESTAMP() function. */ -@TransformFunction(names = {"from_unix_time", "form_unixtime"}) +@TransformFunction(names = {"from_unix_time", + "form_unixtime"}, parameter = "(Numeric numeric,String formatStr)", descriptions = { + "- Return \"\" if 'numeric' is NULL;", + "- Return a representation of the numeric argument as a value in string.", + "Note: 'formatStr' defaults to 'yyyy-MM-dd HH:mm:ss'. numeric is an internal timestamp value representing" + + + " seconds since ‘1970-01-01 00:00:00’ UTC, such as produced by the UNIX_TIMESTAMP() function." + }, examples = { + "from_unix_time(44) = \"1970-01-01 08:00:44\"" + }) public class FromUnixTimeFunction implements ValueParser { private ValueParser numericParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/LocalDateFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/LocalDateFunction.java index a4b3bc664a9..3ceef2ec796 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/LocalDateFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/LocalDateFunction.java @@ -29,12 +29,18 @@ import java.time.ZoneId; /** - * LocalDateFunction - * description: - * localDate([string1]) returns the current date in the specified time zone. - * (by default: the current date in the system time zone) + * LocalDateFunction -> localDate([timeZoneStr]) + * description: + * - Return the current date in the specified time zone. + * Note: timeZoneStr is the system time zone */ -@TransformFunction(names = {"localdate", "currentdate", "current_date", "curdate"}) +@TransformFunction(names = {"localdate", "currentdate", "current_date", + "curdate"}, parameter = "([String timeZoneStr])", descriptions = { + "- Return the current date in the specified 'timeZoneStr'." + }, examples = { + "localDate(\"UTC\") = currentDate", + "localDate() = currentDate" + }) public class LocalDateFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/LocalTimeFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/LocalTimeFunction.java index 2455b60a18b..f479b1aaaf8 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/LocalTimeFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/LocalTimeFunction.java @@ -29,12 +29,17 @@ import java.time.ZoneId; /** - * LocalTimeFunction - * description: - * localTime([string1]) returns the current time in the specified time zone. - * (by default: the current time in the system time zone) + * LocalTimeFunction -> localTime([timeZoneStr]) + * description: + * - Return the current time in the specified time zone. + * Note: timeZoneStr is the system time zone */ -@TransformFunction(names = {"localtime", "current_time"}) +@TransformFunction(names = {"localtime", "current_time"}, parameter = "([String timeZoneStr])", descriptions = { + "- Return the current time in the specified time zone." +}, examples = { + "localTime() = currentTime", + "currentTime(\"UTC\") = currentTime" +}) public class LocalTimeFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/NowFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/NowFunction.java index 3517be69437..f6d36b4642c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/NowFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/NowFunction.java @@ -25,25 +25,20 @@ import net.sf.jsqlparser.expression.Function; /** - * NowFunction - * + * NowFunction -> now() + * description: + * - Return the current SQL timestamp for the local time zone */ -@TransformFunction(names = {"now"}) +@TransformFunction(names = {"now"}, parameter = "()", descriptions = { + "- Return the current SQL timestamp for the local time zone." +}, examples = { + "now()" +}) public class NowFunction implements ValueParser { - /** - * Constructor - * @param expr - */ public NowFunction(Function expr) { } - /** - * parse - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { return String.valueOf(System.currentTimeMillis()); diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimeDiffFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimeDiffFunction.java index 17d2d578c4e..68d8763af20 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimeDiffFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimeDiffFunction.java @@ -33,14 +33,21 @@ import java.util.List; /** - * TimeDiffFunction -> TIMEDIFF(expr1,expr2) + * TimeDiffFunction -> TIMEDIFF(dateStr1,dateStr2) * description: - * - return NULL if expr1 or expr2 is NULL and the conversion types of expr1 and expr2 are different - * - returns expr1 − expr2 expressed as a time value. - * Note: expr1 and expr2 are strings converted to TIME or DATETIME expressions. + * - Return NULL if 'dateStr1' or 'dateStr2' is NULL and the conversion types of 'dateStr1' and 'dateStr2' are different; + * - Return 'dateStr1' - 'dateStr2' expressed as a time value. + * Note: 'dateStr1' and 'dateStr2' are strings converted to TIME or DATETIME expressions. */ -@TransformFunction(names = {"timediff", "time_diff"}) @Slf4j +@TransformFunction(names = {"timediff", "time_diff"}, parameter = "(String dateStr1, String dateStr2)", descriptions = { + "- Return \"\" if 'dateStr1' or 'dateStr2' is NULL and the conversion types of 'dateStr1' and " + + "'dateStr2' are different;", + "- Return 'dateStr1' - 'dateStr2' expressed as a time value.", + "Note: 'dateStr1' and 'dateStr2' are strings converted to TIME or DATETIME expressions." +}, examples = { + "timediff('23:59:59.000001','01:01:01.000002') = \"22:58:57.999998\"" +}) public class TimeDiffFunction implements ValueParser { private final ValueParser leftDateParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampAddFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampAddFunction.java index 63f1e671b53..c8a2be52b00 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampAddFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampAddFunction.java @@ -31,12 +31,20 @@ import java.util.List; /** - * TimestampAddFunction - * Description: Add integer expression intervals to the date or date time expression expr. - * The unit of the time interval is specified by the unit parameter, which should be one of the following values: - * MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR. + * TimestampAddFunction -> timestamp_add(unit,cnt,baseDateStr) + * description: + * - Return NULL if any parameter is null; + * - Return the result of adding the integer expression interval to the date or datetime expression 'baseDateStr'. + * Note: 'unit' is one of (MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR). */ -@TransformFunction(names = {"timestamp_add", "timestampadd"}) +@TransformFunction(names = {"timestamp_add", + "timestampadd"}, parameter = "(String unit, Integer cnt, String baseDateStr)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return the result of adding the integer expression interval to the date or datetime expression 'baseDateStr'.", + "Note: 'unit' is one of (MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR)." + }, examples = { + "timestamp_add('MICROSECOND',3,'1970-01-01 00:00:44') = \"1970-01-01 00:00:44.000003\"" + }) public class TimestampAddFunction implements ValueParser { private final ValueParser intervalParser; @@ -52,9 +60,15 @@ public TimestampAddFunction(Function expr) { @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { - String interval = intervalParser.parse(sourceData, rowIndex, context).toString(); - Long amount = Long.parseLong(amountParser.parse(sourceData, rowIndex, context).toString()); - String dateString = datetimeParser.parse(sourceData, rowIndex, context).toString(); + Object amountObj = amountParser.parse(sourceData, rowIndex, context); + Object intervalObj = intervalParser.parse(sourceData, rowIndex, context); + Object dateTimeObj = datetimeParser.parse(sourceData, rowIndex, context); + if (amountObj == null || intervalObj == null || dateTimeObj == null) { + return null; + } + String interval = intervalObj.toString(); + Long amount = Long.parseLong(amountObj.toString()); + String dateString = dateTimeObj.toString(); return evalDate(dateString, interval, amount); } @@ -99,6 +113,8 @@ private String evalDate(String dateString, String interval, Long amount) { case "YEAR": dateTime = dateTime.plusYears(amount); break; + default: + return null; } StringBuilder format = new StringBuilder("yyyy-MM-dd"); if (hasTime) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampDiffFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampDiffFunction.java index 55592fc2a7a..f3af758530c 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampDiffFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampDiffFunction.java @@ -35,11 +35,18 @@ /** * TimestampDiffFunction -> TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) * Description: - * - returns NULL if datetime_expr1 or datetime_expr2 is NULL. - * - returns datetime_expr2 − datetime_expr1, where datetime_expr1 and datetime_expr2 are date or datetime expressions. - * The unit parameter: MICROSECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR. + * - Return NULL if any parameter is null; + * - Return 'datetime_expr2' − 'datetime_expr1', where 'datetime_expr1' and 'datetime_expr2' are date or datetime expressions. + * The 'unit' parameter: MICROSECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR. */ -@TransformFunction(names = {"timestamp_diff", "timestampdiff"}) +@TransformFunction(names = {"timestamp_diff", + "timestampdiff"}, parameter = "(String unit, String datetime_expr1, String datetime_expr2)", descriptions = { + "- Return \"\" if any parameter is null;", + "- Return 'datetime_expr2' − 'datetime_expr1', where 'datetime_expr1' and 'datetime_expr2' are date or datetime expressions.", + "Note: 'unit' is one of (MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR)." + }, examples = { + "timestampdiff('MONTH','2003-02-01','2003-05-01') = 3" + }) public class TimestampDiffFunction implements ValueParser { private final ValueParser unitParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampExtractFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampExtractFunction.java index 83c19b553bc..ab2232506b6 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampExtractFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampExtractFunction.java @@ -46,7 +46,12 @@ public enum TimestampExtractFunctionType { HOUR, MINUTE, SECOND } - @TransformFunction(names = {"hour"}) + @TransformFunction(names = {"hour"}, parameter = "(String timestamp)", descriptions = { + "- Return \"\" if 'timestamp' is null;", + "- Return the hour of a day (an integer between 0 and 23) from SQL 'timestamp'." + }, examples = { + "hour(2024-08-12 12:23:34) = 12" + }) public static class HourExtractFunction extends TimestampExtractFunction { public HourExtractFunction(Function expr) { @@ -54,7 +59,12 @@ public HourExtractFunction(Function expr) { } } - @TransformFunction(names = {"minute"}) + @TransformFunction(names = {"minute"}, parameter = "(String timestamp)", descriptions = { + "- Return \"\" if 'timestamp' is null;", + "- Return the minute of an hour (an integer between 0 and 59) from SQL 'timestamp'." + }, examples = { + "minute(2024-08-12 12:23:34) = 23" + }) public static class MinuteExtractFunction extends TimestampExtractFunction { public MinuteExtractFunction(Function expr) { @@ -62,7 +72,12 @@ public MinuteExtractFunction(Function expr) { } } - @TransformFunction(names = {"second"}) + @TransformFunction(names = {"second"}, parameter = "(String timestamp)", descriptions = { + "- Return \"\" if 'timestamp' is null;", + "- Return the second of a minute (an integer between 0 and 59) from SQL 'timestamp'." + }, examples = { + "second(2024-08-12 12:23:34) = 34" + }) public static class SecondExtractFunction extends TimestampExtractFunction { public SecondExtractFunction(Function expr) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampFunction.java index 1b3c387c6c3..6c144af7030 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/TimestampFunction.java @@ -32,13 +32,20 @@ import java.util.List; /** - * TimestampFunction -> timestamp(expr1[, expr2]) + * TimestampFunction -> timestamp(datetime_expr1[, datetime_expr2]) * description: - * - return NULL if expr1 or expr2 is NULL. - * - return the date or datetime expression expr as a datetime value if there is only one parameter - * - return the result of the date or date time expression expr1 plus the time expression expr2 if there are two parameters + * - Return NULL if 'datetime_expr1' or 'datetime_expr2' is NULL; + * - Return the date or datetime expression expr as a datetime value if there is only one parameter; + * - Return the result of the date or date time expression 'datetime_expr1' plus the time expression 'datetime_expr2' if there are two parameters. */ -@TransformFunction(names = {"timestamp"}) +@TransformFunction(names = { + "timestamp"}, parameter = "(String unit, String datetime_expr1, String datetime_expr2)", descriptions = { + "- Return \"\" if 'datetime_expr1' or 'datetime_expr2' is NULL;", + "- Return the date or datetime expression expr as a datetime value if there is only one parameter;", + "- Return the result of the date or date time expression 'datetime_expr1' plus the time expression 'datetime_expr2' if there are two parameters." + }, examples = { + "timestamp('2003-12-31 12:00:00.600000','12:00:00') = \"2004-01-01 00:00:00.600000\"" + }) public class TimestampFunction implements ValueParser { private ValueParser dateTimeExprParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ToDateFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ToDateFunction.java index 9247672969f..9fd6d0c59b7 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ToDateFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ToDateFunction.java @@ -33,10 +33,17 @@ import java.util.concurrent.ConcurrentHashMap; /** - * ToDateFunction - * description: to_date(string1[, string2])--converts a date string string1 with format string2 (by default ‘yyyy-MM-dd’) to a date + * ToDateFunction -> to_date(str[, format]) + * description: + * - Return NULL if 'str' is NULL; + * - Return the result of converting the date string 'str' to a date in the format 'format'(default is 'yyyy-MM-dd') . */ -@TransformFunction(names = {"to_date"}) +@TransformFunction(names = {"to_date"}, parameter = "(String str [,String format])", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the result of converting the date string 'str' to a date in the format 'format'(default is 'yyyy-MM-dd')." +}, examples = { + "to_date('20240815', 'yyyyMMdd') = \"2024-08-15\"" +}) public class ToDateFunction implements ValueParser { private ValueParser stringParser1; @@ -44,11 +51,6 @@ public class ToDateFunction implements ValueParser { private static final Map INPUT_FORMATTERS = new ConcurrentHashMap<>(); private static final DateTimeFormatter OUTPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - /** - * Constructor - * - * @param expr - */ public ToDateFunction(Function expr) { List expressions = expr.getParameters().getExpressions(); // Determine the number of arguments and build parser @@ -58,13 +60,6 @@ public ToDateFunction(Function expr) { } } - /** - * parse - * - * @param sourceData - * @param rowIndex - * @return - */ @Override public Object parse(SourceData sourceData, int rowIndex, Context context) { Object stringObj1 = stringParser1.parse(sourceData, rowIndex, context); @@ -78,12 +73,6 @@ public Object parse(SourceData sourceData, int rowIndex, Context context) { return date.format(OUTPUT_FORMATTER); } - /** - * getDateTimeFormatter - * - * @param pattern - * @return - */ private DateTimeFormatter getDateTimeFormatter(String pattern) { DateTimeFormatter formatter = INPUT_FORMATTERS.get(pattern); if (formatter == null) { diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ToTimestampFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ToTimestampFunction.java index 30d24b2a7c7..ec17435faf1 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ToTimestampFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/ToTimestampFunction.java @@ -37,12 +37,19 @@ import java.util.List; /** - * ToTimestampFunction + * ToTimestampFunction -> to_timestamp(str[, format]) * description: - * to_timestamp(string1[, string2])--converts date time string string1 in format string2 - * (by default: yyyy-MM-dd HH:mm:ss if not specified) under the ‘UTC+0’ time zone to a timestamp + * - Return NULL if 'str' is NULL; + * - Return the result of converting the date and time string 'str' to the 'format' + * (by default: yyyy-MM-dd HH:mm:ss if not specified) under the ‘UTC+0’ time zone to a timestamp. */ -@TransformFunction(names = {"to_timestamp"}) +@TransformFunction(names = {"to_timestamp"}, parameter = "(String str [,String format])", descriptions = { + "- Return \"\" if 'str' is NULL;", + "- Return the result of converting the date and time string 'str' to the 'format' " + + "(by default: yyyy-MM-dd HH:mm:ss if not specified) under the 'UTC+0' time zone to a timestamp." +}, examples = { + "to_timestamp('1970/01/01 00:00:44', 'yyyy/MM/dd HH:mm:ss') = \"1970-01-01 00:00:44.0\"" +}) public class ToTimestampFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/UnixTimestampFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/UnixTimestampFunction.java index ca7c43edbb0..e12a03c939b 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/UnixTimestampFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/temporal/UnixTimestampFunction.java @@ -33,13 +33,21 @@ import java.util.List; /** - * UnixTimestampFunction + * UnixTimestampFunction -> unix_timestamp([dateStr[, format]]) * description: - * unix_timestamp(): returns current Unix timestamp in seconds - * unix_timestamp(string1[, string2]): converts date time string string1 in format string2 - * (by default: yyyy-MM-dd HH:mm:ss if not specified) to Unix timestamp (in seconds) + * - Return current Unix timestamp in seconds if no parameter is specified; + * - Return the result of converting the date and time string 'dateStr' to the format 'format' + * (by default: yyyy-MM-dd HH:mm:ss if not specified) to Unix timestamp (in seconds) + * if there is a parameter specified */ -@TransformFunction(names = {"unix_timestamp"}) +@TransformFunction(names = {"unix_timestamp"}, parameter = "([String dateStr [, String format]])", descriptions = { + "- Return current Unix timestamp in seconds if no parameter is specified;", + "- Return the result of converting the date and time string 'dateStr' to the format 'format' " + + "(by default: yyyy-MM-dd HH:mm:ss if not specified) to Unix timestamp (in seconds) " + + "if there is a parameter specified" +}, examples = { + "unix_timestamp('1970/01/01 08:00:44', 'yyyy/MM/dd HH:mm:ss') = \"1970/01/01 08:00:44\"" +}) public class UnixTimestampFunction implements ValueParser { private ValueParser stringParser; diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/pojo/FunctionInfo.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/pojo/FunctionInfo.java new file mode 100644 index 00000000000..34d26ec6395 --- /dev/null +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/pojo/FunctionInfo.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.inlong.sdk.transform.process.pojo; + +import lombok.Data; + +@Data +public class FunctionInfo { + + String functionName; + String explanation; + String example; + + public FunctionInfo() { + } + + public FunctionInfo(String functionName, String explanation, String example) { + this.functionName = functionName; + this.explanation = explanation; + this.example = example; + } +} diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/TestFunctionDoc.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/TestFunctionDoc.java new file mode 100644 index 00000000000..57c25d56a78 --- /dev/null +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/TestFunctionDoc.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.inlong.sdk.transform.process.function; + +import org.apache.inlong.sdk.transform.process.function.string.AbstractFunctionStringTestBase; + +import com.google.gson.Gson; +import org.junit.Test; + +public class TestFunctionDoc extends AbstractFunctionStringTestBase { + + @Test + public void TestFunctionDoc() throws Exception { + System.out.println(new Gson().toJson(FunctionTools.getFunctionDoc())); + } +} diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexExtractFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexpExtractFunction.java similarity index 98% rename from inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexExtractFunction.java rename to inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexpExtractFunction.java index 4749cd3959b..0f35c6d45ae 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexExtractFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestRegexpExtractFunction.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -public class TestRegexExtractFunction extends AbstractFunctionStringTestBase { +public class TestRegexpExtractFunction extends AbstractFunctionStringTestBase { @Test public void testRegexpExtractFunction() throws Exception {