Skip to content

Commit

Permalink
[INLONG-11105][SDK] Fix the empty string is converted to a "null" (ap…
Browse files Browse the repository at this point in the history
…ache#11106)

* [INLONG-11105][SDK] Fix the empty string is converted into a "null"

* fix ut

* fix
  • Loading branch information
vernedeng committed Sep 15, 2024
1 parent 807717a commit 6203004
Show file tree
Hide file tree
Showing 31 changed files with 57 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ public List<O> transform(I input, Map<String, Object> extParams) {
}
try {
Object fieldValue = parser.parse(sourceData, i, context);
sinkData.addField(fieldName, String.valueOf(fieldValue));
if (fieldValue == null) {
sinkData.addField(fieldName, "");
} else {
sinkData.addField(fieldName, fieldValue.toString());
}
} catch (Throwable t) {
sinkData.addField(fieldName, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void testParseUrlFunction() throws Exception {
List<String> output5 = processor5.transform("http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1|QUERY|k1|cloud|1",
new HashMap<>());
Assert.assertEquals(1, output5.size());
Assert.assertEquals(output5.get(0), "result=null");
Assert.assertEquals(output5.get(0), "result=");

String transformSql6 = "select parse_url(string1, string2, stringX) from source";
TransformConfig config6 = new TransformConfig(transformSql6);
Expand All @@ -122,7 +122,7 @@ public void testParseUrlFunction() throws Exception {
List<String> output6 = processor6.transform("http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1|QUERY|k1|cloud|1",
new HashMap<>());
Assert.assertEquals(1, output6.size());
Assert.assertEquals(output6.get(0), "result=null");
Assert.assertEquals(output6.get(0), "result=");
Assert.assertEquals(output3.get(0), "result=v1");

String transformSql7 = "select parse_url(string1, string2) from source";
Expand All @@ -145,7 +145,7 @@ public void testParseUrlFunction() throws Exception {
List<String> output8 = processor8
.transform("http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1|USERINFO|k1|cloud|1", new HashMap<>());
Assert.assertEquals(1, output8.size());
Assert.assertEquals(output8.get(0), "result=null");
Assert.assertEquals(output8.get(0), "result=");

String transformSql9 = "select parse_url(string1, string2) from source";
TransformConfig config9 = new TransformConfig(transformSql9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public void testChrFunction() throws Exception {
// case3: chr(null)
List<String> output3 = processor2.transform("|5|6|8|1|9", new HashMap<>());
Assert.assertEquals(1, output3.size());
Assert.assertEquals(output3.get(0), "result=null");
Assert.assertEquals(output3.get(0), "result=");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testConcatWsFunction() throws Exception {
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");
Assert.assertEquals(output4.get(0), "result=");

// case 5: concat_ws('-', '', '', '')
String transformSql5 = "select concat_ws('-', string1, string2, string3) from source";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public void testBinFunction() throws Exception {
// 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");
Assert.assertEquals(output2.get(0), "result=");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public void testIfNullFunction() throws Exception {
data = "6|0|3|5";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public void testMd5Function() throws Exception {
SinkEncoderFactory.createKvEncoder(kvSink));
List<String> output4 = processor.transform("1|4|6|8");
Assert.assertEquals(1, output4.size());
Assert.assertEquals("result=null", output4.get(0));
Assert.assertEquals("result=", output4.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testSha2Function() throws Exception {
data = "|3|3|5";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case2: sha2("5",224)
data = "5|224|3|5";
Expand All @@ -69,6 +69,6 @@ public void testSha2Function() throws Exception {
data = "3|224|3|5";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public void testShaFunction() throws Exception {
data = "3|3|3|5";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testNullIfFunction() throws Exception {
data = "5|5|3|5";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case3: nullif(null,3)
transformSql = "select nullif(xxd,numeric2) from source";
Expand All @@ -64,6 +64,6 @@ public void testNullIfFunction() throws Exception {
data = "5|3|3|5";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public void testAsciiFunction() throws Exception {
// case3: ascii(null) -> null
List<String> output2 = processor2.transform("A|el|EL|2|1|3", new HashMap<>());
Assert.assertEquals(1, output2.size());
Assert.assertEquals(output2.get(0), "result=null");
Assert.assertEquals(output2.get(0), "result=");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testBitLengthFunction() throws Exception {
// case3: bit_length(null)
output1 = processor1.transform("hello world|apple|cloud|2|1|3", new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals("result=null", output1.get(0));
Assert.assertEquals("result=", output1.get(0));

transformSql = "select bit_length(string1,string2) from source";
config = new TransformConfig(transformSql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testCompressFunction() throws Exception {
// case3: length(compress(null))
output1 = processor1.transform("hello world|apple|cloud|2|1|3", new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals("result=null", output1.get(0));
Assert.assertEquals("result=", output1.get(0));

transformSql = "select length(compress(string1,string2)) from source";
config = new TransformConfig(transformSql);
Expand All @@ -80,6 +80,6 @@ public void testCompressFunction() throws Exception {
// case5: length(compress('hello world','undefinedType'))
output1 = processor1.transform("hello world|undefinedType|cloud|2|1|3", new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals("result=null", output1.get(0));
Assert.assertEquals("result=", output1.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testFromBase64Function() throws Exception {
// case2: from_base64(null) -> null
List<String> output2 = processor2.transform("|apple|banana|cloud|1", new HashMap<>());
Assert.assertEquals(1, output2.size());
Assert.assertEquals(output2.get(0), "result=null");
Assert.assertEquals(output2.get(0), "result=");

// case3: from_base64('QXBhY2hlIEluTG9uZw==') -> 'Apache InLong'
List<String> output3 = processor.transform("QXBhY2hlIEluTG9uZw==|apple|banana|cloud|1", new HashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public void testLcaseFunction() throws Exception {
SinkEncoderFactory.createKvEncoder(kvSink));
List<String> output3 = processor2.transform("ApPlE|", new HashMap<>());
Assert.assertEquals(1, output3.size());
Assert.assertEquals(output3.get(0), "result=null");
Assert.assertEquals(output3.get(0), "result=");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testLeftFunction() throws Exception {
data = "hello world|banana|cloud|5|3|3";
output1 = processor1.transform(data, new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals("result=null", output1.get(0));
Assert.assertEquals("result=", output1.get(0));

// case5: left('hello world',null)
transformSql = "select left(string1,xxd) from source";
Expand All @@ -75,6 +75,6 @@ public void testLeftFunction() throws Exception {
data = "hello world|banana|cloud|5|3|3";
output1 = processor1.transform(data, new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals("result=null", output1.get(0));
Assert.assertEquals("result=", output1.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public void testLengthFunction() throws Exception {
// case2: length(null)
output1 = processor1.transform("hello world|apple|cloud|2|1|3", new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals("result=null", output1.get(0));
Assert.assertEquals("result=", output1.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public void testLocateFunction() throws Exception {
// case5: locate('app', null)
List<String> output5 = processor1.transform("app", new HashMap<>());
Assert.assertEquals(1, output5.size());
Assert.assertEquals(output5.get(0), "result=null");
Assert.assertEquals(output5.get(0), "result=");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public void testLowerFunction() throws Exception {
SinkEncoderFactory.createKvEncoder(kvSink));
List<String> output3 = processor2.transform("ApPlE|banana|cloud|2|1|3", new HashMap<>());
Assert.assertEquals(1, output3.size());
Assert.assertEquals(output3.get(0), "result=null");
Assert.assertEquals(output3.get(0), "result=");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testLpadFunction() throws Exception {
data = "he|xxd|cloud|-1|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case5: lpad(null,5,'xxd')
transformSql = "select lpad(xxd,numeric1,string2) from source";
Expand All @@ -75,7 +75,7 @@ public void testLpadFunction() throws Exception {
data = "he|xxd|cloud|5|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case6: lpad('he',null,'xxd')
transformSql = "select lpad(string1,xxd,string2) from source";
Expand All @@ -86,7 +86,7 @@ public void testLpadFunction() throws Exception {
data = "he|xxd|cloud|5|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case7: lpad('he',5,null)
transformSql = "select lpad(string1,numeric1,xxd) from source";
Expand All @@ -97,6 +97,6 @@ public void testLpadFunction() throws Exception {
data = "he|xxd|cloud|5|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public void testTrimFunction() throws Exception {
data = " in long|xxd|cloud|7|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testRightFunction() throws Exception {
data = "hello world|banana|cloud|5|3|3";
output1 = processor1.transform(data, new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals("result=null", output1.get(0));
Assert.assertEquals("result=", output1.get(0));

// case5: right('hello world',null)
transformSql = "select right(string1,xxd) from source";
Expand All @@ -75,6 +75,6 @@ public void testRightFunction() throws Exception {
data = "hello world|banana|cloud|5|3|3";
output1 = processor1.transform(data, new HashMap<>());
Assert.assertEquals(1, output1.size());
Assert.assertEquals("result=null", output1.get(0));
Assert.assertEquals("result=", output1.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testRpadFunction() throws Exception {
data = "he|xxd|cloud|-1|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case5: rpad(null,5,'xxd')
transformSql = "select rpad(xxd,numeric1,string2) from source";
Expand All @@ -75,7 +75,7 @@ public void testRpadFunction() throws Exception {
data = "he|xxd|cloud|5|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case6: rpad('he',null,'xxd')
transformSql = "select rpad(string1,xxd,string2) from source";
Expand All @@ -86,7 +86,7 @@ public void testRpadFunction() throws Exception {
data = "he|xxd|cloud|5|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case7: rpad('he',5,null)
transformSql = "select rpad(string1,numeric1,xxd) from source";
Expand All @@ -97,6 +97,6 @@ public void testRpadFunction() throws Exception {
data = "he|xxd|cloud|5|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public void testTrimFunction() throws Exception {
data = " in long|xxd|cloud|7|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testSpaceFunction() throws Exception {
data = "hello world|banana|cloud|5|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public void testSplitIndexFunction() throws Exception {
data = "a,b,c|,|cloud|-1|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case3: split_index('a,b,c', ',', 3)
data = "a,b,c|,|cloud|3|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case4: split_index(null, ',', 1)
transformSql = "select split_index(xxd, string2, numeric1) from source";
Expand All @@ -65,7 +65,7 @@ public void testSplitIndexFunction() throws Exception {
data = "abc|,|cloud|1|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case5: split_index('a,b,c', null, 1)
transformSql = "select split_index(string1, xxd, numeric1) from source";
Expand All @@ -76,7 +76,7 @@ public void testSplitIndexFunction() throws Exception {
data = "a,b,c|xxd|cloud|1|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case6: split_index('a,b,c', ',', null)
transformSql = "select split_index(string1, string2, xxd) from source";
Expand All @@ -87,7 +87,7 @@ public void testSplitIndexFunction() throws Exception {
data = "a,b,c|,|cloud|xxd|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));

// case7: split_index('', ',', 0)
transformSql = "select split_index(string1, string2, numeric1) from source";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public void testStrcmpFunction() throws Exception {
data = "hello world|zzzzz|cloud|5|3|3";
output = processor.transform(data, new HashMap<>());
Assert.assertEquals(1, output.size());
Assert.assertEquals("result=null", output.get(0));
Assert.assertEquals("result=", output.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public void testUcaseFunction() throws Exception {
SinkEncoderFactory.createKvEncoder(kvSink));
List<String> output3 = processor2.transform("ApPlE", new HashMap<>());
Assert.assertEquals(1, output3.size());
Assert.assertEquals(output3.get(0), "result=null");
Assert.assertEquals(output3.get(0), "result=");
}
}
Loading

0 comments on commit 6203004

Please sign in to comment.