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-10881][SDK] Transform SQL support Concat_ws function
- add distinct UT to avoid conflict - add description of concat_ws function
- Loading branch information
1 parent
0c83357
commit af2bcc4
Showing
3 changed files
with
118 additions
and
54 deletions.
There are no files selected for viewing
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
111 changes: 111 additions & 0 deletions
111
.../java/org/apache/inlong/sdk/transform/process/TestTransformConcatWsFunctionProcessor.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,111 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* TestTransformConcatWsFunctionProcessor | ||
* description: test the concat_ws function in transform processor | ||
*/ | ||
public class TestTransformConcatWsFunctionProcessor { | ||
|
||
private static final List<FieldInfo> srcFields = new ArrayList<>(); | ||
private static final List<FieldInfo> 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("string" + 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 testConcatWsFunction() throws Exception { | ||
// case 1: concat_ws('-', 'apple', 'banana', 'cloud') | ||
String transformSql1 = "select concat_ws('-', string1, string2, string3) from source"; | ||
TransformConfig config1 = new TransformConfig(transformSql1); | ||
TransformProcessor<String, String> processor1 = TransformProcessor | ||
.create(config1, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
List<String> output1 = processor1.transform("apple|banana|cloud|extra", new HashMap<>()); | ||
Assert.assertEquals(1, output1.size()); | ||
Assert.assertEquals(output1.get(0), "result=apple-banana-cloud"); | ||
|
||
// case 2: concat_ws('-', 'apple', '', 'cloud') | ||
String transformSql2 = "select concat_ws('-', string1, string2, string3) from source"; | ||
TransformConfig config2 = new TransformConfig(transformSql2); | ||
TransformProcessor<String, String> processor2 = TransformProcessor | ||
.create(config2, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
List<String> output2 = processor2.transform("apple||cloud|extra", new HashMap<>()); | ||
Assert.assertEquals(1, output2.size()); | ||
Assert.assertEquals(output2.get(0), "result=apple--cloud"); | ||
|
||
// case 3: concat_ws('-', 'apple', null, 'cloud') | ||
String transformSql3 = "select concat_ws('-', string1, stringX, string3) from source"; | ||
TransformConfig config3 = new TransformConfig(transformSql3); | ||
TransformProcessor<String, String> processor3 = TransformProcessor | ||
.create(config3, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
List<String> output3 = processor3.transform("apple|banana|cloud|extra", new HashMap<>()); | ||
Assert.assertEquals(1, output3.size()); | ||
Assert.assertEquals(output3.get(0), "result=apple-cloud"); | ||
|
||
// case 4: concat_ws(null, 'apple', 'banana', 'cloud') | ||
String transformSql4 = "select concat_ws(null, string1, string2, string3) from source"; | ||
TransformConfig config4 = new TransformConfig(transformSql4); | ||
TransformProcessor<String, String> processor4 = TransformProcessor | ||
.create(config4, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
List<String> output4 = processor4.transform("apple|null|cloud|extra", new HashMap<>()); | ||
Assert.assertEquals(1, output4.size()); | ||
Assert.assertEquals(output4.get(0), "result=null"); | ||
|
||
// case 5: concat_ws('-', '', '', '') | ||
String transformSql5 = "select concat_ws('-', string1, string2, string3) from source"; | ||
TransformConfig config5 = new TransformConfig(transformSql5); | ||
TransformProcessor<String, String> processor5 = TransformProcessor | ||
.create(config5, SourceDecoderFactory.createCsvDecoder(csvSource), | ||
SinkEncoderFactory.createKvEncoder(kvSink)); | ||
List<String> output5 = processor5.transform("|||", new HashMap<>()); | ||
Assert.assertEquals(1, output5.size()); | ||
Assert.assertEquals(output5.get(0), "result=--"); | ||
} | ||
|
||
} |
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