fix(tdengine): support table row editing
This commit is contained in:
10 files changed
+732
-17
No files matched your search
@@ -51,6 +51,8 @@ public final class TDengineAgent extends BaseDatabaseAgent {
|
||||
Pattern.compile("(?i)^(decimal|numeric)\\(\\d+,\\s*(\\d+)\\)");
|
||||
private static final Pattern CHARACTER_LENGTH_PATTERN =
|
||||
Pattern.compile("(?i)^(binary|nchar|varchar|varbinary)\\((\\d+)\\)");
|
||||
private static final Pattern COMPOSITE_KEY_PATTERN =
|
||||
Pattern.compile("(?i)\\bCOMPOSITE\\s+KEY\\b");
|
||||
|
||||
private Connection connection;
|
||||
|
||||
@@ -355,7 +357,7 @@ public final class TDengineAgent extends BaseDatabaseAgent {
|
||||
return groupName.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static List<ColumnInfo> readDescribeColumns(ResultSet rs) throws Exception {
|
||||
static List<ColumnInfo> readDescribeColumns(ResultSet rs) throws Exception {
|
||||
List<ColumnInfo> result = new ArrayList<>();
|
||||
int ordinal = 0;
|
||||
while (rs.next()) {
|
||||
@@ -364,12 +366,13 @@ public final class TDengineAgent extends BaseDatabaseAgent {
|
||||
String dataType = coalesce(rs.getString(2));
|
||||
String note = optionalString(rs, 4);
|
||||
boolean isTag = note != null && note.toUpperCase(Locale.ROOT).contains("TAG");
|
||||
boolean isPrimaryKey = !isTag && (ordinal == 1 || (note != null && COMPOSITE_KEY_PATTERN.matcher(note).find()));
|
||||
result.add(new ColumnInfo(
|
||||
name,
|
||||
dataType,
|
||||
ordinal != 1,
|
||||
!isPrimaryKey,
|
||||
null,
|
||||
ordinal == 1 && !isTag,
|
||||
isPrimaryKey,
|
||||
note,
|
||||
isTag ? "TAG" : null,
|
||||
parseNumericPrecision(dataType),
|
||||
|
||||
+43
-1
@@ -1,6 +1,6 @@
|
||||
package com.dbx.agent.tdengine;
|
||||
|
||||
import com.dbx.agent.test.TestSupport;
|
||||
import com.dbx.agent.ColumnInfo;
|
||||
import com.dbx.agent.ConnectParams;
|
||||
import com.dbx.agent.DatabaseAgent;
|
||||
import com.dbx.agent.ExecuteQueryOptions;
|
||||
@@ -9,6 +9,7 @@ import com.dbx.agent.TableInfo;
|
||||
import com.dbx.agent.test.JdbcAgentFake;
|
||||
import com.dbx.agent.test.JdbcFakeExecutionBehaviorTest;
|
||||
import com.dbx.agent.test.JdbcMetadataSqlFake;
|
||||
import com.dbx.agent.test.TestSupport;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -165,6 +166,26 @@ class TDengineAgentMetadataTest {
|
||||
Assertions.assertEquals("meters", tables.get(1).getParent_name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void marksTimestampAndCompositeKeyDescribeColumnsAsPrimaryKeys() throws Exception {
|
||||
ResultSet resultSet = describeResultSet(new String[][] {
|
||||
{"ts", "TIMESTAMP", "8", ""},
|
||||
{"seq", "INT", "4", "COMPOSITE KEY"},
|
||||
{"voltage", "FLOAT", "4", ""},
|
||||
{"site", "VARCHAR(32)", "32", "TAG"}
|
||||
});
|
||||
|
||||
List<ColumnInfo> columns = TDengineAgent.readDescribeColumns(resultSet);
|
||||
|
||||
Assertions.assertTrue(columns.get(0).getIs_primary_key());
|
||||
Assertions.assertFalse(columns.get(0).getIs_nullable());
|
||||
Assertions.assertTrue(columns.get(1).getIs_primary_key());
|
||||
Assertions.assertFalse(columns.get(1).getIs_nullable());
|
||||
Assertions.assertFalse(columns.get(2).getIs_primary_key());
|
||||
Assertions.assertFalse(columns.get(3).getIs_primary_key());
|
||||
Assertions.assertEquals("TAG", columns.get(3).getExtra());
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotExposeDatabasesAsSchemas() {
|
||||
TDengineAgent agent = new TDengineAgent();
|
||||
@@ -302,4 +323,25 @@ class TDengineAgentMetadataTest {
|
||||
|
||||
Assertions.assertEquals("jdbc:TAOS-RS://127.0.0.1:6041/db?timezone=UTC#anchor", sanitized);
|
||||
}
|
||||
|
||||
private static ResultSet describeResultSet(String[][] rows) {
|
||||
int[] rowIndex = {-1};
|
||||
return (ResultSet) Proxy.newProxyInstance(
|
||||
ResultSet.class.getClassLoader(),
|
||||
new Class<?>[] {ResultSet.class},
|
||||
(proxy, method, args) -> {
|
||||
if ("next".equals(method.getName())) {
|
||||
rowIndex[0] += 1;
|
||||
return rowIndex[0] < rows.length;
|
||||
}
|
||||
if ("getString".equals(method.getName())) {
|
||||
return rows[rowIndex[0]][((Integer) args[0]) - 1];
|
||||
}
|
||||
if ("close".equals(method.getName())) {
|
||||
return null;
|
||||
}
|
||||
throw new UnsupportedOperationException(method.getName());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user