This is an automated email from the ASF dual-hosted git repository.
luchunliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new c08549eff5 [INLONG-10984][SDK] Transform support RADIANS(x) function
(#10987)
c08549eff5 is described below
commit c08549eff5113d23b03f4436ca02a77949f4a49d
Author: emptyOVO <[email protected]>
AuthorDate: Tue Sep 3 10:23:03 2024 +0800
[INLONG-10984][SDK] Transform support RADIANS(x) function (#10987)
* [INLONG-10984][SDK] Transform support RADIANS(x) function
* fix: add description
---
.../process/function/RadiansFunction.java | 49 ++++++++++++++++++++++
.../TestTransformArithmeticFunctionsProcessor.java | 17 ++++++++
2 files changed, 66 insertions(+)
diff --git
a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/RadiansFunction.java
b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/RadiansFunction.java
new file mode 100644
index 0000000000..635d18b9b8
--- /dev/null
+++
b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/RadiansFunction.java
@@ -0,0 +1,49 @@
+/*
+ * 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.operator.OperatorTools;
+import org.apache.inlong.sdk.transform.process.parser.ValueParser;
+
+import net.sf.jsqlparser.expression.Function;
+
+/**
+ * RadiansFunction
+ * description:
+ * - RADIANS(x)--returns radians of x, Convert degrees to radians
+ */
+@TransformFunction(names = {"radians"})
+public class RadiansFunction implements ValueParser {
+
+ private ValueParser degreeParser;
+
+ public RadiansFunction(Function expr) {
+ degreeParser =
OperatorTools.buildParser(expr.getParameters().getExpressions().get(0));
+ }
+
+ @Override
+ public Object parse(SourceData sourceData, int rowIndex, Context context) {
+ Object degreeObj = degreeParser.parse(sourceData, rowIndex, context);
+ if (degreeObj == null) {
+ return null;
+ }
+ return
Math.toRadians(OperatorTools.parseBigDecimal(degreeObj).doubleValue());
+ }
+}
diff --git
a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformArithmeticFunctionsProcessor.java
b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformArithmeticFunctionsProcessor.java
index 1e0f14025f..c36835e579 100644
---
a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformArithmeticFunctionsProcessor.java
+++
b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformArithmeticFunctionsProcessor.java
@@ -422,6 +422,23 @@ public class TestTransformArithmeticFunctionsProcessor {
Assert.assertEquals(output2.get(0), "result=2.302585092994046");
}
+ @Test
+ public void testRadiansFunction() throws Exception {
+ String transformSql = "select radians(numeric1) from source";
+ TransformConfig config = new TransformConfig(transformSql);
+ TransformProcessor<String, String> processor = TransformProcessor
+ .create(config,
SourceDecoderFactory.createCsvDecoder(csvSource),
+ SinkEncoderFactory.createKvEncoder(kvSink));
+ // case1: radians(10)
+ List<String> output1 = processor.transform("10|4|6|8", new
HashMap<>());
+ Assert.assertEquals(1, output1.size());
+ Assert.assertEquals(output1.get(0), "result=0.17453292519943295");
+ // case2: radians(18.97)
+ List<String> output2 = processor.transform("18.97|4|6|8", new
HashMap<>());
+ Assert.assertEquals(1, output2.size());
+ Assert.assertEquals(output2.get(0), "result=0.33108895910332425");
+ }
+
@Test
public void testLog10Function() throws Exception {
String transformSql = "select log10(numeric1) from source";