From 88c92ae1b195ea7a54656d3de45b8540d8d22cb9 Mon Sep 17 00:00:00 2001 From: Jast Date: Thu, 2 Jan 2025 00:44:31 +0800 Subject: [PATCH] [Fix][Connector][TDEngine] TDEngine support NCHAR type (#8411) --- .../typemapper/TDengineTypeMapper.java | 2 ++ .../e2e/connector/tdengine/TDengineIT.java | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/typemapper/TDengineTypeMapper.java b/seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/typemapper/TDengineTypeMapper.java index 5099c4f3544..e48f200cfc8 100644 --- a/seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/typemapper/TDengineTypeMapper.java +++ b/seatunnel-connectors-v2/connector-tdengine/src/main/java/org/apache/seatunnel/connectors/seatunnel/tdengine/typemapper/TDengineTypeMapper.java @@ -58,6 +58,7 @@ public class TDengineTypeMapper { // -------------------------string---------------------------- private static final String TDENGINE_CHAR = "CHAR"; + private static final String TDENGINE_NCHAR = "NCHAR"; private static final String TDENGINE_VARCHAR = "VARCHAR"; private static final String TDENGINE_TINYTEXT = "TINYTEXT"; private static final String TDENGINE_MEDIUMTEXT = "MEDIUMTEXT"; @@ -118,6 +119,7 @@ public static SeaTunnelDataType mapping(String tdengineType) { log.warn("{} will probably cause value overflow.", TDENGINE_DOUBLE_UNSIGNED); return BasicType.DOUBLE_TYPE; case TDENGINE_CHAR: + case TDENGINE_NCHAR: case TDENGINE_TINYTEXT: case TDENGINE_MEDIUMTEXT: case TDENGINE_TEXT: diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-tdengine-e2e/src/test/java/org/apache/seatunnel/e2e/connector/tdengine/TDengineIT.java b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-tdengine-e2e/src/test/java/org/apache/seatunnel/e2e/connector/tdengine/TDengineIT.java index a96d34bd0c3..7d91e32f54a 100644 --- a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-tdengine-e2e/src/test/java/org/apache/seatunnel/e2e/connector/tdengine/TDengineIT.java +++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-tdengine-e2e/src/test/java/org/apache/seatunnel/e2e/connector/tdengine/TDengineIT.java @@ -109,7 +109,7 @@ private int generateTestDataSet() { try (Statement stmt = connection1.createStatement()) { stmt.execute("CREATE DATABASE power KEEP 3650"); stmt.execute( - "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT, off BOOL) " + "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT, off BOOL, nc NCHAR(10)) " + "TAGS (location BINARY(64), groupId INT)"); String sql = getSQL(); rowCount = stmt.executeUpdate(sql); @@ -117,7 +117,7 @@ private int generateTestDataSet() { try (Statement stmt = connection2.createStatement()) { stmt.execute("CREATE DATABASE power2 KEEP 3650"); stmt.execute( - "CREATE STABLE power2.meters2 (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT, off BOOL) " + "CREATE STABLE power2.meters2 (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT, off BOOL, nc NCHAR(10)) " + "TAGS (location BINARY(64), groupId INT)"); } return rowCount; @@ -210,6 +210,8 @@ private static String getSQL() { .append(ps[4]) .append(",") // off .append(ps[7]) + .append(",") // nc + .append(ps[8]) .append(") "); // phase } return sb.toString(); @@ -217,13 +219,13 @@ private static String getSQL() { private static List getRawData() { return Arrays.asList( - "d1001,2018-10-03 14:38:05.000,10.30000,219,0.31000,'California.SanFrancisco',2,true", - "d1001,2018-10-03 14:38:15.000,12.60000,218,0.33000,'California.SanFrancisco',2,false", - "d1001,2018-10-03 14:38:16.800,12.30000,221,0.31000,'California.SanFrancisco',2,true", - "d1002,2018-10-03 14:38:16.650,10.30000,218,0.25000,'California.SanFrancisco',3,true", - "d1003,2018-10-03 14:38:05.500,11.80000,221,0.28000,'California.LosAngeles',2,true", - "d1003,2018-10-03 14:38:16.600,13.40000,223,0.29000,'California.LosAngeles',2,true", - "d1004,2018-10-03 14:38:05.000,10.80000,223,0.29000,'California.LosAngeles',3,true", - "d1004,2018-10-03 14:38:06.500,11.50000,221,0.35000,'California.LosAngeles',3,false"); + "d1001,2018-10-03 14:38:05.000,10.30000,219,0.31000,'California.SanFrancisco',2,true,'nc'", + "d1001,2018-10-03 14:38:15.000,12.60000,218,0.33000,'California.SanFrancisco',2,false,'nc'", + "d1001,2018-10-03 14:38:16.800,12.30000,221,0.31000,'California.SanFrancisco',2,true,'nc'", + "d1002,2018-10-03 14:38:16.650,10.30000,218,0.25000,'California.SanFrancisco',3,true,'nc'", + "d1003,2018-10-03 14:38:05.500,11.80000,221,0.28000,'California.LosAngeles',2,true,'nc'", + "d1003,2018-10-03 14:38:16.600,13.40000,223,0.29000,'California.LosAngeles',2,true,'nc'", + "d1004,2018-10-03 14:38:05.000,10.80000,223,0.29000,'California.LosAngeles',3,true,'nc'", + "d1004,2018-10-03 14:38:06.500,11.50000,221,0.35000,'California.LosAngeles',3,false,'nc'"); } }