diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/ChrFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/ChrFunction.java deleted file mode 100644 index 14de13d403..0000000000 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/ChrFunction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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; - -import java.math.BigDecimal; - -/** - * ChrFunction - * description: chr(numeric)--returns the ASCII character having the binary equivalent to integer -**/ -@TransformFunction(names = {"chr"}) -public class ChrFunction implements ValueParser { - - private ValueParser numberParser; - private final int chrSum = 256; - - public ChrFunction(Function expr) { - numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); - } - - @Override - public Object parse(SourceData sourceData, int rowIndex, Context context) { - if (numberParser == null) { - return null; - } - Object numberObj = numberParser.parse(sourceData, rowIndex, context); - if (numberObj == null) { - return null; - } - BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); - - BigDecimal temp = numberValue.remainder(new BigDecimal(chrSum)); - BigDecimal res = (temp.compareTo(BigDecimal.ZERO) >= 0) ? temp : temp.add(new BigDecimal(chrSum)); - - return String.valueOf((char) res.intValue()); - } -} diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/LtrimFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/LtrimFunction.java deleted file mode 100644 index fe1df3aa33..0000000000 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/LtrimFunction.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - -/** - * TrimFunction - * description: ltrim(string) - * - Return NULL if str is NULL. - * - Return the string str without leading spaces - */ -@TransformFunction(names = {"ltrim"}) -public class LtrimFunction implements ValueParser { - - private ValueParser stringParser; - - public LtrimFunction(Function expr) { - stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); - } - - @Override - public Object parse(SourceData sourceData, int rowIndex, Context context) { - Object stringObj = stringParser.parse(sourceData, rowIndex, context); - if (stringObj == null) { - return null; - } - String str = OperatorTools.parseString(stringObj); - int len = str.length(); - for (int i = 0; i < len; i++) { - if (str.charAt(i) != ' ') { - return str.substring(i); - } - } - return ""; - } -} diff --git a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/RtrimFunction.java b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/RtrimFunction.java deleted file mode 100644 index 315f018169..0000000000 --- a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/RtrimFunction.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - -/** - * TrimFunction - * description: rtrim(string) - * - Return NULL if str is NULL. - * - Return the string str with trailing space characters removed. - */ -@TransformFunction(names = {"rtrim"}) -public class RtrimFunction implements ValueParser { - - private ValueParser stringParser; - - public RtrimFunction(Function expr) { - stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); - } - - @Override - public Object parse(SourceData sourceData, int rowIndex, Context context) { - Object stringObj = stringParser.parse(sourceData, rowIndex, context); - if (stringObj == null) { - return null; - } - String str = OperatorTools.parseString(stringObj); - int len = str.length(); - for (int i = len - 1; i >= 0; i--) { - if (str.charAt(i) != ' ') { - return str.substring(0, i + 1); - } - } - return ""; - } -} diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestBetweenAndOperator.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestBetweenAndOperator.java deleted file mode 100644 index 23b9693bca..0000000000 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestBetweenAndOperator.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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; - -import org.apache.inlong.sdk.transform.decode.SourceDecoderFactory; -import org.apache.inlong.sdk.transform.encode.SinkEncoderFactory; -import org.apache.inlong.sdk.transform.pojo.CsvSourceInfo; -import org.apache.inlong.sdk.transform.pojo.FieldInfo; -import org.apache.inlong.sdk.transform.pojo.KvSinkInfo; -import org.apache.inlong.sdk.transform.pojo.TransformConfig; -import org.apache.inlong.sdk.transform.process.converter.DoubleConverter; -import org.apache.inlong.sdk.transform.process.converter.LongConverter; -import org.apache.inlong.sdk.transform.process.converter.TypeConverter; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -public class TestBetweenAndOperator { - - private static final List srcFields = new ArrayList<>(); - private static final List dstFields = new ArrayList<>(); - private static final CsvSourceInfo csvSource; - private static final KvSinkInfo kvSink; - - static { - srcFields.add(new FieldInfo("numeric1", new DoubleConverter())); - srcFields.add(new FieldInfo("string2", TypeConverter.DefaultTypeConverter())); - srcFields.add(new FieldInfo("numeric3", new DoubleConverter())); - srcFields.add(new FieldInfo("numeric4", new LongConverter())); - - FieldInfo field = new FieldInfo(); - field.setName("result"); - dstFields.add(field); - csvSource = new CsvSourceInfo("UTF-8", '|', '\\', srcFields); - kvSink = new KvSinkInfo("UTF-8", dstFields); - } - - @Test - public void testBetweenAndOperator() throws Exception { - String transformSql = "select if(string2 between 3 and 5,1,0) from source"; - TransformConfig config = new TransformConfig(transformSql); - // case1: '3a' between '3' and '5' -> 1 - TransformProcessor processor = TransformProcessor - .create(config, SourceDecoderFactory.createCsvDecoder(csvSource), - SinkEncoderFactory.createKvEncoder(kvSink)); - List output1 = processor.transform("3.14159265358979323846|3a|4|8"); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output1.get(0), "result=1"); - // case2: '4a' between '3' and '5' -> 1 - List output2 = processor.transform("3.14159265358979323846|4a|4|8"); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output2.get(0), "result=1"); - // case3: '6' between '3' and '5' -> 0 - List output3 = processor.transform("3.14159265358979323846|6|4|8"); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output3.get(0), "result=0"); - // case4: '3e2' between '3' and '5' -> 0 - List output4 = processor.transform("3.14159265358979323846|3e2|4|8"); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output4.get(0), "result=0"); - - transformSql = "select if(numeric3 between 3 and 5,1,0) from source"; - config = new TransformConfig(transformSql); - // case5: 4 between 3 and 5 -> 1 - processor = TransformProcessor - .create(config, SourceDecoderFactory.createCsvDecoder(csvSource), - SinkEncoderFactory.createKvEncoder(kvSink)); - List output5 = processor.transform("3.14159265358979323846|4|4|8"); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output5.get(0), "result=1"); - // case6: 3 between 3 and 5 -> 1 - List output6 = processor.transform("3.14159265358979323846|4|3|8"); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output6.get(0), "result=1"); - // case7: 5 between 3 and 5 -> 1 - List output7 = processor.transform("3.14159265358979323846|4|5|8"); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output7.get(0), "result=1"); - // case8: 3e2 between 3 and 5 -> 0 - List output8 = processor.transform("3.14159265358979323846|4|3e2|8"); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output8.get(0), "result=0"); - } -} \ No newline at end of file diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformChrFunctionProcessor.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformChrFunctionProcessor.java deleted file mode 100644 index f89ef4c3b2..0000000000 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformChrFunctionProcessor.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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; - -import org.apache.inlong.sdk.transform.decode.SourceDecoderFactory; -import org.apache.inlong.sdk.transform.encode.SinkEncoderFactory; -import org.apache.inlong.sdk.transform.pojo.CsvSourceInfo; -import org.apache.inlong.sdk.transform.pojo.FieldInfo; -import org.apache.inlong.sdk.transform.pojo.KvSinkInfo; -import org.apache.inlong.sdk.transform.pojo.TransformConfig; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -/** - * TestTransformChrFunctionProcessor - * description: test chr functions in transform processor - */ -public class TestTransformChrFunctionProcessor { - - private static final List srcFields = new ArrayList<>(); - private static final List dstFields = new ArrayList<>(); - private static final CsvSourceInfo csvSource; - private static final KvSinkInfo kvSink; - - static { - for (int i = 1; i < 4; i++) { - FieldInfo field = new FieldInfo(); - field.setName("numeric" + i); - srcFields.add(field); - } - FieldInfo field = new FieldInfo(); - field.setName("result"); - dstFields.add(field); - csvSource = new CsvSourceInfo("UTF-8", '|', '\\', srcFields); - kvSink = new KvSinkInfo("UTF-8", dstFields); - } - - @Test - public void testChrFunction() throws Exception { - String transformSql1 = "select chr(numeric1) from source"; - TransformConfig config1 = new TransformConfig(transformSql1); - TransformProcessor processor1 = TransformProcessor - .create(config1, SourceDecoderFactory.createCsvDecoder(csvSource), - SinkEncoderFactory.createKvEncoder(kvSink)); - // case1: chr(97) - List output1 = processor1.transform("97|5|6|8|1|3", new HashMap<>()); - Assert.assertEquals(1, output1.size()); - Assert.assertEquals(output1.get(0), "result=a"); - - // case2: chr(353) - List output2 = processor1.transform("353|5|6|8|1|3", new HashMap<>()); - Assert.assertEquals(1, output2.size()); - Assert.assertEquals(output2.get(0), "result=a"); - - String transformSql2 = "select chr(numericx) from source"; - TransformConfig config2 = new TransformConfig(transformSql2); - TransformProcessor processor2 = TransformProcessor - .create(config2, SourceDecoderFactory.createCsvDecoder(csvSource), - SinkEncoderFactory.createKvEncoder(kvSink)); - // case3: chr(null) - List output3 = processor2.transform("|5|6|8|1|9", new HashMap<>()); - Assert.assertEquals(1, output3.size()); - Assert.assertEquals(output3.get(0), "result=null"); - } -} diff --git a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestTransformChrFunctionProcessor.java b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestChrFunction.java similarity index 96% rename from inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestTransformChrFunctionProcessor.java rename to inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestChrFunction.java index 2b40666116..4402b61c93 100644 --- a/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestTransformChrFunctionProcessor.java +++ b/inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestChrFunction.java @@ -32,7 +32,7 @@ * TestTransformChrFunctionProcessor * description: test chr functions in transform processor */ -public class TestTransformChrFunctionProcessor extends AbstractFunctionArithmeticTestBase { +public class TestChrFunction extends AbstractFunctionArithmeticTestBase { @Test public void testChrFunction() throws Exception {