fix: drop history export and tolerate empty tdengine tables
This commit is contained in:
@@ -63,6 +63,9 @@ public final class TdengineJdbcHistoryReader implements TdengineHistoryReader {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
if (isTableMissing(e)) {
|
||||
return new TdenginePage<>(List.of(), Optional.empty());
|
||||
}
|
||||
throw new IOException("tdengine history query failed", e);
|
||||
}
|
||||
boolean hasMore = rows.size() > pageSize;
|
||||
@@ -73,6 +76,21 @@ public final class TdengineJdbcHistoryReader implements TdengineHistoryReader {
|
||||
return new TdenginePage<>(items, next);
|
||||
}
|
||||
|
||||
private static boolean isTableMissing(SQLException e) {
|
||||
for (Throwable current = e; current != null; current = current.getCause()) {
|
||||
String message = current.getMessage();
|
||||
if (message != null) {
|
||||
String normalized = message.toLowerCase();
|
||||
if (normalized.contains("table does not exist")
|
||||
|| normalized.contains("0x2603")
|
||||
|| normalized.contains("table not exist")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void bind(PreparedStatement prepared, List<Object> values) throws SQLException {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
Object value = values.get(i);
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.lang.reflect.Proxy;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
@@ -95,6 +96,48 @@ class TdengineJdbcHistoryReaderTest {
|
||||
.contains(new TdenginePageCursor(Instant.parse("2026-06-29T05:00:01Z"), "evt-1#0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsEmptyPageWhenTdengineChildTableDoesNotExist() throws Exception {
|
||||
RecordingQueryJdbc jdbc = new RecordingQueryJdbc();
|
||||
jdbc.executeQueryFailure = new SQLException("(0x2603):Fail to get table info, error: Table does not exist");
|
||||
TdengineJdbcHistoryReader reader = new TdengineJdbcHistoryReader(
|
||||
jdbc.dataSource(), new TdengineHistorySchema("vehicle_history"));
|
||||
|
||||
TdenginePage<TdengineTelemetryFieldRow> page = reader.queryTelemetryFields(new TdengineTelemetryFieldQuery(
|
||||
"JT808",
|
||||
"jt808:g7gps",
|
||||
"location.speed_kmh",
|
||||
Instant.parse("2026-06-29T00:00:00Z"),
|
||||
Instant.parse("2026-06-30T00:00:00Z"),
|
||||
TdengineQueryOrder.ASC,
|
||||
10,
|
||||
null));
|
||||
|
||||
assertThat(page.items()).isEmpty();
|
||||
assertThat(page.nextCursor()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsEmptyPageWhenTdengineChildTableDoesNotExistInNestedCause() throws Exception {
|
||||
RecordingQueryJdbc jdbc = new RecordingQueryJdbc();
|
||||
jdbc.executeQueryFailure = new SQLException("wrapper",
|
||||
new RuntimeException("TDengine error: table not exist"));
|
||||
TdengineJdbcHistoryReader reader = new TdengineJdbcHistoryReader(
|
||||
jdbc.dataSource(), new TdengineHistorySchema("vehicle_history"));
|
||||
|
||||
TdenginePage<TdengineLocationRow> page = reader.queryLocations(new TdengineLocationQuery(
|
||||
"JT808",
|
||||
"jt808:g7gps",
|
||||
Instant.parse("2026-06-29T00:00:00Z"),
|
||||
Instant.parse("2026-06-30T00:00:00Z"),
|
||||
TdengineQueryOrder.ASC,
|
||||
10,
|
||||
null));
|
||||
|
||||
assertThat(page.items()).isEmpty();
|
||||
assertThat(page.nextCursor()).isEmpty();
|
||||
}
|
||||
|
||||
private static Map<String, Object> rawFrameResult(String frameId, String ts) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("ts", Timestamp.from(Instant.parse(ts)));
|
||||
@@ -166,6 +209,7 @@ class TdengineJdbcHistoryReaderTest {
|
||||
private static final class RecordingQueryJdbc {
|
||||
private final List<Map<String, Object>> rows = new ArrayList<>();
|
||||
private final Map<Integer, Object> boundValues = new HashMap<>();
|
||||
private SQLException executeQueryFailure;
|
||||
private String preparedSql;
|
||||
|
||||
DataSource dataSource() {
|
||||
@@ -199,7 +243,12 @@ class TdengineJdbcHistoryReaderTest {
|
||||
boundValues.put((Integer) args[0], args[1]);
|
||||
yield null;
|
||||
}
|
||||
case "executeQuery" -> resultSet();
|
||||
case "executeQuery" -> {
|
||||
if (executeQueryFailure != null) {
|
||||
throw executeQueryFailure;
|
||||
}
|
||||
yield resultSet();
|
||||
}
|
||||
default -> null;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user