From bfd787794b849ee4e64667f5a237405902f28540 Mon Sep 17 00:00:00 2001 From: Moon <2267016840@qq.com> Date: Thu, 10 Oct 2024 09:12:48 +0800 Subject: [PATCH] [INLONG-11029][SDK] Transform SQL support StartsWith & EndsWith functions --- .../process/function/EndsWithFunction.java | 21 +++++++++++++--- .../process/function/StartsWithFunction.java | 21 +++++++++++++--- .../function/string/TestEndsWithFunction.java | 18 ++++++++++++++ .../string/TestStartsWithFunction.java | 24 +++++++++++++++---- 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/EndsWithFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/EndsWithFunction.java index fe8d4ebb63..3a78a17ac5 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/EndsWithFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/EndsWithFunction.java @@ -1,3 +1,20 @@ +/* + * 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.decode.SourceData; @@ -12,8 +29,7 @@ /** * EndsWithFunction - * description: endswith(expr, endExpr) - * Returns whether expr ends with endExpr. + * description: Returns whether expr ends with endExpr. */ @TransformFunction(names = {"endswith"}) public class EndsWithFunction implements ValueParser { @@ -66,4 +82,3 @@ private boolean isSameType(Object a, Object b) { return (a instanceof String && b instanceof String) || (a instanceof byte[] && b instanceof byte[]); } } - diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/StartsWithFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/StartsWithFunction.java index 18513a8782..ae7937eb88 100644 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/StartsWithFunction.java +++ b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/StartsWithFunction.java @@ -1,8 +1,24 @@ +/* + * 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.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; @@ -13,8 +29,7 @@ /** * StartsWithFunction - * description: startswith(expr, startExpr) - * Returns whether expr starts with startExpr. + * description: Returns whether expr starts with startExpr. */ @TransformFunction(names = {"startswith"}) public class StartsWithFunction implements ValueParser { diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestEndsWithFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestEndsWithFunction.java index 083273f146..12a97c3b85 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestEndsWithFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestEndsWithFunction.java @@ -1,9 +1,27 @@ +/* + * 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.string; import org.apache.inlong.sdk.transform.decode.SourceDecoderFactory; import org.apache.inlong.sdk.transform.encode.SinkEncoderFactory; import org.apache.inlong.sdk.transform.pojo.TransformConfig; import org.apache.inlong.sdk.transform.process.TransformProcessor; + import org.junit.Assert; import org.junit.Test; diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestStartsWithFunction.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestStartsWithFunction.java index ba640cbcda..c5a1e5f842 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestStartsWithFunction.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/string/TestStartsWithFunction.java @@ -1,15 +1,30 @@ +/* + * 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.string; + import org.apache.inlong.sdk.transform.decode.SourceDecoderFactory; import org.apache.inlong.sdk.transform.encode.SinkEncoderFactory; import org.apache.inlong.sdk.transform.pojo.TransformConfig; -import org.apache.inlong.sdk.transform.process.Context; -import org.apache.inlong.sdk.transform.decode.SourceData; import org.apache.inlong.sdk.transform.process.TransformProcessor; -import org.apache.inlong.sdk.transform.process.function.StartsWithFunction; + import org.junit.Assert; import org.junit.Test; -import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; @@ -86,4 +101,3 @@ public void testStartsWithFunction() throws Exception { Assert.assertEquals(output9.get(0), "result=true"); } } -