diff --git a/core/pom.xml b/core/pom.xml
index 174a18d3..3981cfcc 100755
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -97,6 +97,18 @@
groovy-all
2.1.9
+
+ mysql
+ mysql-connector-java
+ ${mysql.driver.version}
+ test
+
+
+ com.taosdata.jdbc
+ taos-jdbcdriver
+ 2.0.34
+ test
+
diff --git a/core/src/main/job/mysql2tdengine.json b/core/src/main/job/mysql2tdengine.json
index 7978fbf5..c936aa36 100644
--- a/core/src/main/job/mysql2tdengine.json
+++ b/core/src/main/job/mysql2tdengine.json
@@ -6,18 +6,18 @@
"name": "mysqlreader",
"parameter": {
"username": "root",
- "password": "123456",
+ "password": "passw0rd",
"column": [
"*"
],
- "splitPk": "f1",
+ "splitPk": "station",
"connection": [
{
"table": [
"weather"
],
"jdbcUrl": [
- "jdbc:mysql://192.168.56.105:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf8"
+ "jdbc:mysql://127.0.0.1:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf8"
]
}
]
@@ -26,13 +26,25 @@
"writer": {
"name": "tdenginewriter",
"parameter": {
- "host": "192.168.56.105",
+ "host": "127.0.0.1",
"port": 6030,
"dbname": "test",
"user": "root",
"password": "taosdata",
- "table": "weather",
- "batchSize": 1000
+ "batchSize": 1000,
+ "stable": "weather",
+ "tagColumn": {
+ "station": 0
+ },
+ "fieldColumn": {
+ "latitude": 1,
+ "longtitude": 2,
+ "tmax": 4,
+ "tmin": 5
+ },
+ "timestampColumn":{
+ "date": 3
+ }
}
}
}
diff --git a/core/src/test/java/com/alibaba/datax/core/TestMysql2TDengine.java b/core/src/test/java/com/alibaba/datax/core/TestMysql2TDengine.java
index aeb05071..6edc185c 100644
--- a/core/src/test/java/com/alibaba/datax/core/TestMysql2TDengine.java
+++ b/core/src/test/java/com/alibaba/datax/core/TestMysql2TDengine.java
@@ -1,10 +1,105 @@
package com.alibaba.datax.core;
-
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import java.sql.*;
+import java.util.*;
+import java.util.Date;
+
+/**
+ * 测试从mysql到TD
+ */
public class TestMysql2TDengine {
+ @Test
+ public void genTestData() throws ClassNotFoundException, SQLException {
+ Class.forName("com.mysql.jdbc.Driver");
+
+ Connection conn = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+ PreparedStatement pstmt = null;
+
+ try {
+ conn = DriverManager.getConnection("jdbc:mysql://localhost/mysql?" +
+ "user=root&password=passw0rd");
+ stmt = conn.createStatement();
+ stmt.execute("create database if not exists test");
+ stmt.execute("use test");
+ stmt.execute("drop table weather");
+ stmt.execute("CREATE TABLE IF NOT EXISTS weather(station varchar(100), latitude DOUBLE, longtitude DOUBLE, `date` DATETIME, tmax INT, tmin INT)");
+ pstmt = conn.prepareStatement("insert into weather(station, latitude, longtitude, `date`, tmax, tmin) values (?, ?, ?, ?, ?, ?)");
+ genRandomData(pstmt);
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException sqlEx) {
+ } // ignore
+
+ rs = null;
+ }
+
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException sqlEx) {
+ } // ignore
+
+ stmt = null;
+ }
+
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ }
+
+ }
+
+ private void genRandomData(PreparedStatement psmt) throws SQLException {
+ Random random = new Random();
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(1990, 0, 1, 1, 0, 0);
+ List stations = Arrays.asList("STA", "STB", "STC");
+ for (int i = 0; i < (10 * 100 * 24); i++) {
+ for (int j = 0; j < 3; j++) {
+ psmt.setString(1, stations.get(j));
+ psmt.setDouble(2, random.nextDouble() * 1000);
+ psmt.setDouble(3, random.nextDouble() * 1000);
+ psmt.setTimestamp(4, new java.sql.Timestamp(calendar.getTime().getTime()));
+ psmt.setInt(5, random.nextInt(100));
+ psmt.setInt(6, random.nextInt(100));
+ psmt.addBatch();
+ }
+ calendar.add(Calendar.MINUTE, 60);
+ if (i % 1000 == 0) {
+ psmt.executeBatch();
+ }
+ }
+ psmt.executeBatch();
+ }
+
+ @Test
+ public void prepareTDengine() throws ClassNotFoundException, SQLException {
+ Class.forName("com.mysql.jdbc.Driver");
+
+ Connection conn = null;
+ Statement stmt = null;
+
+ try {
+ conn = DriverManager.getConnection("jdbc:TAOS://127.0.0.1:6030/log?user=root&password=taosdata");
+ stmt = conn.createStatement();
+ stmt.execute("create database if not exists test");
+ stmt.execute("drop stable if exists test.weather");
+ } finally {
+ if (stmt != null) {
+ stmt.close();
+ }
+ }
+ }
+
@Test
public void test() {
System.out.println(System.getProperty("java.library.path"));
@@ -17,4 +112,6 @@ public class TestMysql2TDengine {
}
}
+
+
}
\ No newline at end of file