Merge pull request #15 from taosdata/ftr/TD-10786

[TD-10786]<feature>: tdenginereader implementation
This commit is contained in:
Shuduo Sang 2021-12-16 15:14:13 +08:00 committed by GitHub
commit a5012fe1af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 15 deletions

View File

@ -3,7 +3,7 @@
"class": "com.alibaba.datax.plugin.reader.TDengineReader",
"description": {
"useScene": "data migration from tdengine",
"mechanism": "use JNI to read data from tdengine."
"mechanism": "use JDBC to read data from tdengine."
},
"developer": "zyyang-taosdata"
}

View File

@ -1,14 +1,21 @@
{
"name": "tdenginereader",
"parameter": {
"host": "127.0.0.1",
"port": 6030,
"db": "test",
"user": "root",
"password": "taosdata",
"sql": "select * from weather",
"beginDateTime": "2021-01-01 00:00:00",
"endDateTime": "2021-01-02 00:00:00",
"splitInterval": "1h"
"user": "",
"password": "",
"connection": [
{
"table": [
""
],
"jdbcUrl": ""
}
],
"column": [
""
],
"beginDateTime": "",
"endDateTime": "",
"splitInterval": ""
}
}

View File

@ -5,8 +5,9 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.IntStream;
public class TDengineReaderTest {
@ -19,20 +20,36 @@ public class TDengineReaderTest {
"\"user\": \"root\"," +
"\"password\": \"taosdata\"," +
"\"connection\": [{\"table\":[\"weather\"],\"jdbcUrl\":\"jdbc:TAOS-RS://master:6041/test\"}]," +
"\"column\": [\"ts\",\"current\",\"voltage\",\"phase\"]," +
"\"beginDateTime\": \"2021-01-01 00:00:00\"," +
"\"endDateTime\": \"2021-01-01 10:00:00\"," +
"\"endDateTime\": \"2021-01-01 12:00:00\"," +
"\"splitInterval\": \"1h\"" +
"}");
job.setPluginJobConf(configuration);
}
@Test
public void jobInit() {
public void jobInit() throws ParseException {
// when
job.init();
// assert
Configuration conf = job.getPluginJobConf();
Assert.assertEquals("select * from weather", conf.getString("sql"));
Assert.assertEquals("root", conf.getString("user"));
Assert.assertEquals("taosdata", conf.getString("password"));
Assert.assertEquals("weather", conf.getString("connection[0].table[0]"));
Assert.assertEquals("jdbc:TAOS-RS://master:6041/test", conf.getString("connection[0].jdbcUrl"));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Long start = sdf.parse("2021-01-01 00:00:00").getTime();
Assert.assertEquals(start, conf.getLong("beginDateTime"));
Long end = sdf.parse("2021-01-01 12:00:00").getTime();
Assert.assertEquals(end, conf.getLong("endDateTime"));
Assert.assertEquals(new Long(3600 * 1000), conf.getLong("splitInterval"));
}
@Test
@ -41,7 +58,15 @@ public class TDengineReaderTest {
job.init();
List<Configuration> configurationList = job.split(1);
// IntStream.range(0, configurationList.size()).forEach(i -> System.out.println(i + ": " + configurationList.get(i)));
// assert
Assert.assertEquals(12, configurationList.size());
for (int i = 0; i < configurationList.size(); i++) {
Configuration conf = configurationList.get(i);
Assert.assertEquals("root", conf.getString("user"));
Assert.assertEquals("taosdata", conf.getString("password"));
Assert.assertEquals("weather", conf.getString("table[0]"));
Assert.assertEquals("jdbc:TAOS-RS://master:6041/test", conf.getString("jdbcUrl"));
}
}
}