forked from apache/doris
-
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.
[improve](extension) improve kettle plugin and add some testcase (apa…
…che#44324) ### What problem does this PR solve? improve kettle plugin and add some testcase
- Loading branch information
Showing
8 changed files
with
623 additions
and
4 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
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
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
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
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
82 changes: 82 additions & 0 deletions
82
...src/test/java/org/pentaho/di/trans/steps/dorisstreamloader/DorisRecordSerializerTest.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,82 @@ | ||
// 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.pentaho.di.trans.steps.dorisstreamloader; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.pentaho.di.core.logging.LogChannel; | ||
import org.pentaho.di.core.row.ValueMetaInterface; | ||
import org.pentaho.di.core.row.value.ValueMetaBigNumber; | ||
import org.pentaho.di.core.row.value.ValueMetaBinary; | ||
import org.pentaho.di.core.row.value.ValueMetaBoolean; | ||
import org.pentaho.di.core.row.value.ValueMetaDate; | ||
import org.pentaho.di.core.row.value.ValueMetaInteger; | ||
import org.pentaho.di.core.row.value.ValueMetaInternetAddress; | ||
import org.pentaho.di.core.row.value.ValueMetaNumber; | ||
import org.pentaho.di.core.row.value.ValueMetaString; | ||
import org.pentaho.di.core.row.value.ValueMetaTimestamp; | ||
import org.pentaho.di.trans.steps.dorisstreamloader.serializer.DorisRecordSerializer; | ||
|
||
import java.math.BigDecimal; | ||
import java.sql.Timestamp; | ||
import java.text.SimpleDateFormat; | ||
import javax.mail.internet.InternetAddress; | ||
|
||
import static org.pentaho.di.trans.steps.dorisstreamloader.load.LoadConstants.CSV; | ||
|
||
public class DorisRecordSerializerTest { | ||
|
||
@Test | ||
public void testSerialize() throws Exception { | ||
ValueMetaInterface[] formatMeta = new ValueMetaInterface[]{ | ||
new ValueMetaBoolean("boolean"), | ||
new ValueMetaInteger("integer"), | ||
new ValueMetaNumber("number"), | ||
new ValueMetaBigNumber("bignumber"), | ||
new ValueMetaDate("date"), | ||
new ValueMetaTimestamp("timestamp"), | ||
new ValueMetaBinary("binary"), | ||
new ValueMetaString("string"), | ||
new ValueMetaInternetAddress("address"), | ||
}; | ||
|
||
DorisRecordSerializer serializer = DorisRecordSerializer.builder() | ||
.setType(CSV) | ||
.setFieldNames(new String[]{"c_boolean", "c_integer", "c_number", "c_bignumber", "c_date", "c_timestamp", "c_binary", "c_string", "c_internetAddress"}) | ||
.setFormatMeta(formatMeta) | ||
.setFieldDelimiter(",") | ||
.setLogChannelInterface(new LogChannel()) | ||
.setDeletable(false) | ||
.build(); | ||
|
||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
Object[] data = new Object[]{ | ||
true, | ||
10L, | ||
123.23, | ||
new BigDecimal("123456789.1234"), | ||
dateFormat.parse("2024-01-01"), | ||
Timestamp.valueOf("2024-01-01 10:11:22.123"), | ||
"binary", | ||
"string", | ||
new InternetAddress("127.0.0.1")}; | ||
String actual = serializer.buildCSVString(data, formatMeta.length); | ||
String except = "true,10,123.23,123456789.1234,2024-01-01,2024-01-01 10:11:22.123,binary,string,127.0.0.1"; | ||
Assert.assertEquals(except, actual); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
...src/test/java/org/pentaho/di/trans/steps/dorisstreamloader/DorisStreamLoaderMetaTest.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,114 @@ | ||
// 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.pentaho.di.trans.steps.dorisstreamloader; | ||
|
||
import org.junit.Assert; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.pentaho.di.core.exception.KettleException; | ||
import org.pentaho.di.junit.rules.RestorePDIEngineEnvironment; | ||
import org.pentaho.di.trans.steps.loadsave.LoadSaveTester; | ||
import org.pentaho.di.trans.steps.loadsave.validator.ArrayLoadSaveValidator; | ||
import org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator; | ||
import org.pentaho.di.trans.steps.loadsave.validator.IntLoadSaveValidator; | ||
import org.pentaho.di.trans.steps.loadsave.validator.LongLoadSaveValidator; | ||
import org.pentaho.di.trans.steps.loadsave.validator.StringLoadSaveValidator; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class DorisStreamLoaderMetaTest { | ||
|
||
@ClassRule | ||
public static RestorePDIEngineEnvironment env = new RestorePDIEngineEnvironment(); | ||
|
||
@Test | ||
public void testRoundTrip() throws KettleException { | ||
List<String> attributes = | ||
Arrays.asList( "fenodes", "database", "table", "username", "password", | ||
"streamLoadProp", "bufferFlushMaxRows", "bufferFlushMaxBytes", "maxRetries", | ||
"deletable", "stream_name", "field_name"); | ||
|
||
Map<String, String> getterMap = new HashMap<>(); | ||
getterMap.put( "fenodes", "getFenodes" ); | ||
getterMap.put( "database", "getDatabase" ); | ||
getterMap.put( "table", "getTable" ); | ||
getterMap.put( "username", "getUsername" ); | ||
getterMap.put( "password", "getPassword" ); | ||
getterMap.put( "streamLoadProp", "getStreamLoadProp" ); | ||
getterMap.put( "bufferFlushMaxRows", "getBufferFlushMaxRows" ); | ||
getterMap.put( "bufferFlushMaxBytes", "getBufferFlushMaxBytes" ); | ||
getterMap.put( "maxRetries", "getMaxRetries" ); | ||
getterMap.put( "deletable", "isDeletable" ); | ||
getterMap.put( "stream_name", "getFieldTable" ); | ||
getterMap.put( "field_name", "getFieldStream" ); | ||
|
||
Map<String, String> setterMap = new HashMap<>(); | ||
setterMap.put( "fenodes", "setFenodes" ); | ||
setterMap.put( "database", "setDatabase" ); | ||
setterMap.put( "table", "setTable" ); | ||
setterMap.put( "username", "setUsername" ); | ||
setterMap.put( "password", "setPassword" ); | ||
setterMap.put( "streamLoadProp", "setStreamLoadProp" ); | ||
setterMap.put( "bufferFlushMaxRows", "setBufferFlushMaxRows" ); | ||
setterMap.put( "bufferFlushMaxBytes", "setBufferFlushMaxBytes" ); | ||
setterMap.put( "maxRetries", "setMaxRetries" ); | ||
setterMap.put( "deletable", "setDeletable" ); | ||
setterMap.put( "stream_name", "setFieldTable" ); | ||
setterMap.put( "field_name", "setFieldStream" ); | ||
|
||
Map<String, FieldLoadSaveValidator<?>> fieldLoadSaveValidatorAttributeMap = new HashMap<>(); | ||
FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator = new ArrayLoadSaveValidator<>( new StringLoadSaveValidator(), 25 ); | ||
|
||
fieldLoadSaveValidatorAttributeMap.put("maxRetries", new IntLoadSaveValidator( Integer.MAX_VALUE )); | ||
fieldLoadSaveValidatorAttributeMap.put("bufferFlushMaxRows", new LongLoadSaveValidator()); | ||
fieldLoadSaveValidatorAttributeMap.put("bufferFlushMaxBytes", new LongLoadSaveValidator()); | ||
fieldLoadSaveValidatorAttributeMap.put("streamLoadProp", new StringLoadSaveValidator()); | ||
fieldLoadSaveValidatorAttributeMap.put("stream_name", stringArrayLoadSaveValidator ); | ||
fieldLoadSaveValidatorAttributeMap.put("field_name", stringArrayLoadSaveValidator ); | ||
|
||
LoadSaveTester loadSaveTester = | ||
new LoadSaveTester( DorisStreamLoaderMeta.class, attributes, getterMap, setterMap, | ||
fieldLoadSaveValidatorAttributeMap, new HashMap<String, FieldLoadSaveValidator<?>>() ); | ||
|
||
loadSaveTester.testSerialization(); | ||
} | ||
|
||
@Test | ||
public void testPDI16559() throws Exception { | ||
DorisStreamLoaderMeta streamLoader = new DorisStreamLoaderMeta(); | ||
streamLoader.setFieldTable( new String[] { "table1", "table2", "table3" } ); | ||
streamLoader.setFieldStream( new String[] { "stream1" } ); | ||
streamLoader.setTable( "test_table" ); | ||
|
||
try { | ||
String badXml = streamLoader.getXML(); | ||
Assert.fail( "Before calling afterInjectionSynchronization, should have thrown an ArrayIndexOOB" ); | ||
} catch ( Exception expected ) { | ||
// Do Nothing | ||
} | ||
streamLoader.afterInjectionSynchronization(); | ||
//run without a exception | ||
String ktrXml = streamLoader.getXML(); | ||
|
||
int targetSz = streamLoader.getFieldTable().length; | ||
Assert.assertEquals( targetSz, streamLoader.getFieldStream().length ); | ||
} | ||
} |
Oops, something went wrong.