提交 4c6ccf5f 编写于 作者: H huolibo

[TD-10424]<feat>:jniConnector support opentsdb migration

上级 9ef3fce1
...@@ -368,5 +368,44 @@ public class TSDBJNIConnector { ...@@ -368,5 +368,44 @@ public class TSDBJNIConnector {
private native int insertLinesImp(String[] lines, long conn); private native int insertLinesImp(String[] lines, long conn);
/**
* insert openTSDB data with telnet api format
* e.g. sys.if.bytes.out 1479496100 1.3E3 host=web01 interface=eth0 ID=tablename_1
*
* @param lines data array
* @throws SQLException execute insert error
*/
public void insertTelnetLines(String[] lines) throws SQLException {
int code = insertTelnetLinesImp(lines, lines.length, this.taos);
if (TSDBConstants.JNI_SUCCESS != code) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to insertTelnetLines");
}
}
private native int insertTelnetLinesImp(String[] lines, int numOfRows, long conn);
/**
* insert openTSDB data with json format
* e.g.,
* {
* "metric": "sys.cpu.nice",
* "timestamp": 1346846400,
* "value": 18,
* "tags": {
* "host": "web01",
* "dc": "lga"
* }
* }
*
* @param payload json format string
* @throws SQLException execute insert error
*/
public void insertJsonPayload(String payload) throws SQLException {
int code = insertJsonPayloadImp(payload, this.taos);
if (TSDBConstants.JNI_SUCCESS != code) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to insertJsonPayload");
}
}
private native int insertJsonPayloadImp(String payload, long conn);
} }
package com.taosdata.jdbc;
import org.junit.*;
import java.sql.*;
import java.util.Random;
public class OpenTSDBMigrateTest {
private static final String host = "127.0.0.1";
private static final String dbname = "opentsdb_migrate_test";
private static final Random random = new Random(System.currentTimeMillis());
private static TSDBConnection conn;
@Test
public void telnetPut() {
System.out.println("test");
try {
// given
String[] lines = new String[]{"stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
"stb0_1 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
"stb0_2 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\""};
// // when
conn.getConnector().insertTelnetLines(lines);
// then
// long actual = rs.getLong(1);
// Assert.assertEquals(ms, actual);
// actual = rs.getLong("ts");
// Assert.assertEquals(ms, actual);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Before
public void before() {
}
@BeforeClass
public static void beforeClass() {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
try {
conn = (TSDBConnection) DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname + " precision 'ns'");
stmt.execute("use " + dbname);
} catch (SQLException e) {
e.printStackTrace();
}
}
@AfterClass
public static void afterClass() {
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册