forked from apache/inlong
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-11010][SDK] Transform refactor unit test structure
- Loading branch information
Showing
94 changed files
with
5,728 additions
and
3,069 deletions.
There are no files selected for viewing
997 changes: 0 additions & 997 deletions
997
...va/org/apache/inlong/sdk/transform/process/TestTransformArithmeticFunctionsProcessor.java
This file was deleted.
Oops, something went wrong.
354 changes: 0 additions & 354 deletions
354
...va/org/apache/inlong/sdk/transform/process/TestTransformExpressionOperatorsProcessor.java
This file was deleted.
Oops, something went wrong.
429 changes: 0 additions & 429 deletions
429
...orm-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformProcessor.java
This file was deleted.
Oops, something went wrong.
727 changes: 0 additions & 727 deletions
727
...t/java/org/apache/inlong/sdk/transform/process/TestTransformStringFunctionsProcessor.java
This file was deleted.
Oops, something went wrong.
562 changes: 0 additions & 562 deletions
562
...java/org/apache/inlong/sdk/transform/process/TestTransformTemporalFunctionsProcessor.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
.../inlong/sdk/transform/process/function/arithmetic/AbstractFunctionArithmeticTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.arithmetic; | ||
|
||
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 java.util.ArrayList; | ||
import java.util.List; | ||
/** | ||
* AbstractArithmeticFunctionTestSetup | ||
* description: define static parameters for ArithmeticFunction tests | ||
*/ | ||
public abstract class AbstractFunctionArithmeticTestBase { | ||
|
||
protected static final List<FieldInfo> srcFields = new ArrayList<>(); | ||
protected static final List<FieldInfo> dstFields = new ArrayList<>(); | ||
protected static final CsvSourceInfo csvSource; | ||
protected static final KvSinkInfo kvSink; | ||
|
||
static { | ||
for (int i = 1; i < 5; 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); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...est/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestAbsFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.arithmetic; | ||
|
||
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; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class TestAbsFunction extends AbstractFunctionArithmeticTestBase { | ||
|
||
@Test | ||
public void testAbsFunction() throws Exception { | ||
String transformSql = "select abs(numeric1) from source"; | ||
TransformConfig config = new TransformConfig(transformSql); | ||
// case1: |2| | ||
TransformProcessor<String, String> processor = TransformProcessor | ||
.create(config, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
List<String> output1 = processor.transform("2|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output1.size()); | ||
Assert.assertEquals(output1.get(0), "result=2"); | ||
// case2: |-4.25| | ||
List<String> output2 = processor.transform("-4.25|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output2.size()); | ||
Assert.assertEquals(output2.get(0), "result=4.25"); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...st/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestAcosFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.arithmetic; | ||
|
||
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; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
public class TestAcosFunction extends AbstractFunctionArithmeticTestBase { | ||
|
||
@Test | ||
public void testAcosFunction() throws Exception { | ||
String transformSql = "select acos(numeric1) from source"; | ||
TransformConfig config = new TransformConfig(transformSql); | ||
TransformProcessor<String, String> processor = TransformProcessor | ||
.create(config, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
// case1: acos(1) | ||
List<String> output1 = processor.transform("1|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output1.size()); | ||
Assert.assertEquals(output1.get(0), "result=0.0"); | ||
// case2: acos(0) | ||
List<String> output2 = processor.transform("0|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output2.size()); | ||
Assert.assertEquals(output2.get(0), "result=1.5707963267948966"); | ||
// case3: acos(-1) | ||
List<String> output3 = processor.transform("-1|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output3.size()); | ||
Assert.assertEquals(output3.get(0), "result=3.141592653589793"); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...he/inlong/sdk/transform/process/function/arithmetic/TestArithmeticFunctionsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.function.arithmetic; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Suite; | ||
/** | ||
* TestArithmeticFunctionProcessor | ||
* description: test all the arithmetic functions in transform processor | ||
*/ | ||
@RunWith(Suite.class) | ||
@Suite.SuiteClasses({ | ||
TestAbsFunction.class, TestAcosFunction.class, TestBinFunction.class, TestBinFunction.class, | ||
TestCeilFunction.class, TestCosFunction.class, TestExpFunction.class, TestFloorFunction.class, | ||
TestHexFunction.class, TestIfNullFunction.class, TestLnFunction.class, TestLog2Function.class, | ||
TestLogFunction.class, TestLog10Function.class, TestMd5Function.class, TestModuloFunction.class, | ||
TestPiFunction.class, TestPowerFunction.class, TestRadiansFunction.class, TestRandFunction.class, | ||
TestRoundFunction.class, TestSha2Function.class, TestShaFunction.class, TestSignFunction.class, | ||
TestSinFunction.class, TestSinhFunction.class, TestSqrtFunction.class, TestTanFunction.class | ||
}) | ||
public class TestArithmeticFunctionsProcessor { | ||
} |
53 changes: 53 additions & 0 deletions
53
...est/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestBinFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.arithmetic; | ||
|
||
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; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
public class TestBinFunction extends AbstractFunctionArithmeticTestBase { | ||
|
||
@Test | ||
public void testBinFunction() throws Exception { | ||
String transformSql1 = "select bin(numeric1) from source"; | ||
TransformConfig config1 = new TransformConfig(transformSql1); | ||
TransformProcessor<String, String> processor1 = TransformProcessor | ||
.create(config1, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
// case: bin(4) | ||
List<String> output1 = processor1.transform("4|5|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output1.size()); | ||
Assert.assertEquals(output1.get(0), "result=100"); | ||
String transformSql2 = "select bin() from source"; | ||
TransformConfig config2 = new TransformConfig(transformSql2); | ||
TransformProcessor<String, String> processor2 = TransformProcessor | ||
.create(config2, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
// case: bin() | ||
List<String> output2 = processor2.transform("1|2|3|4", new HashMap<>()); | ||
Assert.assertEquals(1, output1.size()); | ||
Assert.assertEquals(output2.get(0), "result=null"); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...st/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestCeilFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.arithmetic; | ||
|
||
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; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class TestCeilFunction extends AbstractFunctionArithmeticTestBase { | ||
|
||
@Test | ||
public void testCeilFunction() throws Exception { | ||
String transformSql = "select ceil(numeric1) from source"; | ||
TransformConfig config = new TransformConfig(transformSql); | ||
// case1: ceil(1.23) | ||
TransformProcessor<String, String> processor = TransformProcessor | ||
.create(config, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
List<String> output1 = processor.transform("1.23|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output1.size()); | ||
Assert.assertEquals(output1.get(0), "result=2.0"); | ||
// case2: ceil(3) | ||
List<String> output2 = processor.transform("3|-2|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output2.size()); | ||
Assert.assertEquals(output2.get(0), "result=3.0"); | ||
// case3: ceil(-5.67) | ||
List<String> output3 = processor.transform("-5.67|0.5|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output3.size()); | ||
Assert.assertEquals(output3.get(0), "result=-5.0"); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...est/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestCosFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.arithmetic; | ||
|
||
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; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
public class TestCosFunction extends AbstractFunctionArithmeticTestBase { | ||
|
||
@Test | ||
public void testCosFunction() throws Exception { | ||
String transformSql = "select cos(numeric1) from source"; | ||
TransformConfig config = new TransformConfig(transformSql); | ||
TransformProcessor<String, String> processor = TransformProcessor | ||
.create(config, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
// case: cos(0) | ||
List<String> output1 = processor.transform("0|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output1.size()); | ||
Assert.assertEquals(output1.get(0), "result=1.0"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...est/java/org/apache/inlong/sdk/transform/process/function/arithmetic/TestExpFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.arithmetic; | ||
|
||
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; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class TestExpFunction extends AbstractFunctionArithmeticTestBase { | ||
|
||
@Test | ||
public void testExpFunction() throws Exception { | ||
String transformSql = "select exp(numeric1) from source"; | ||
TransformConfig config = new TransformConfig(transformSql); | ||
// case1: e^0 | ||
TransformProcessor<String, String> processor = TransformProcessor | ||
.create(config, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
List<String> output1 = processor.transform("0|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output1.size()); | ||
Assert.assertEquals(output1.get(0), "result=1.0"); | ||
// case2: e^2 | ||
List<String> output2 = processor.transform("2|4|6|8", new HashMap<>()); | ||
Assert.assertEquals(1, output2.size()); | ||
Assert.assertEquals(output2.get(0), "result=7.38905609893065"); | ||
} | ||
} |
Oops, something went wrong.