From e0a455f4a7d12924248f6acd9d8e14cd83ad2575 Mon Sep 17 00:00:00 2001 From: Clownsw Date: Tue, 30 Apr 2024 13:16:21 +0800 Subject: [PATCH] feat(*): Support Time Type to Tengine Data Storage Signed-off-by: Clownsw --- .../store/HistoryTdEngineDataStorage.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryTdEngineDataStorage.java b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryTdEngineDataStorage.java index d760f3a17b7..18643b5d9a6 100644 --- a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryTdEngineDataStorage.java +++ b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryTdEngineDataStorage.java @@ -134,7 +134,9 @@ public void saveData(CollectRep.MetricsData metricsData) { for (int index = 0; index < fields.size(); index++) { CollectRep.Field field = fields.get(index); String value = valueRow.getColumns(index); - if (field.getType() == CommonConstants.TYPE_NUMBER) { + final int fieldType; + + if ((fieldType = field.getType()) == CommonConstants.TYPE_NUMBER || fieldType == CommonConstants.TYPE_TIME) { // number data if (CommonConstants.NULL_VALUE.equals(value)) { sqlRowBuffer.append("NULL"); @@ -183,7 +185,9 @@ public void saveData(CollectRep.MetricsData metricsData) { for (int index = 0; index < fields.size(); index++) { CollectRep.Field field = fields.get(index); String fieldName = field.getName(); - if (field.getType() == CommonConstants.TYPE_NUMBER) { + final int fieldType; + + if ((fieldType = field.getType()) == CommonConstants.TYPE_NUMBER || fieldType == CommonConstants.TYPE_TIME) { fieldSqlBuilder.append("`").append(fieldName).append("` ").append("DOUBLE"); } else { fieldSqlBuilder.append("`").append(fieldName).append("` ").append("NCHAR(") @@ -216,7 +220,7 @@ public void saveData(CollectRep.MetricsData metricsData) { } } - private String formatStringValue(String value){ + private String formatStringValue(String value) { String formatValue = SQL_SPECIAL_STRING_PATTERN.matcher(value).replaceAll("\\\\$0"); // bugfix Argument list too long if (formatValue != null && formatValue.length() > tableStrColumnDefineMaxLength) { @@ -235,7 +239,7 @@ public void destroy() { @Override public Map> getHistoryMetricData(Long monitorId, String app, String metrics, String metric, String label, String history) { String table = app + "_" + metrics + "_" + monitorId; - String selectSql = label == null ? String.format(QUERY_HISTORY_SQL, metric, table, history) : + String selectSql = label == null ? String.format(QUERY_HISTORY_SQL, metric, table, history) : String.format(QUERY_HISTORY_WITH_INSTANCE_SQL, metric, table, label, history); log.debug(selectSql); Map> instanceValuesMap = new HashMap<>(8); @@ -322,7 +326,7 @@ public Map> getHistoryIntervalMetricData(Long monitorId, Str instanceValue = ""; } String selectSql = String.format(QUERY_HISTORY_INTERVAL_WITH_INSTANCE_SQL, - metric, metric, metric, metric, table, instanceValue, history); + metric, metric, metric, metric, table, instanceValue, history); log.debug(selectSql); List values = instanceValuesMap.computeIfAbsent(instanceValue, k -> new LinkedList<>()); Connection connection = null;