This is an automated email from the ASF dual-hosted git repository.
zhaoqingran pushed a commit to branch doris
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/doris by this push:
new 0867f3594 ```fix(doris): adjust SQL query string and remove unused
methods
0867f3594 is described below
commit 0867f35942d534b73992e3ed5f426f8fda4cf0ae
Author: zqr10159 <[email protected]>
AuthorDate: Mon Aug 26 23:54:00 2024 +0800
```fix(doris): adjust SQL query string and remove unused methods
Refactor the DorisDataStorage class by revising the QUERY_HISTORY_SQL
static final
string to properly format the SQL query with corrected interval syntax and
ordering
by 'ts' in descending order. Additionally, remove the unused
double2decimalString
and history2interval methods to clean up the codebase.
BREAKING CHANGE: The query history SQL syntax has been adjusted, which may
affect
existing dependent systems that rely on the previous SQL format.
```
---
.../store/history/doris/DorisDataStorage.java | 39 ++++++++++------------
1 file changed, 17 insertions(+), 22 deletions(-)
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/doris/DorisDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/doris/DorisDataStorage.java
index 8a4baddd2..420d204ae 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/doris/DorisDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/doris/DorisDataStorage.java
@@ -77,7 +77,7 @@ public class DorisDataStorage extends
AbstractHistoryDataStorage {
);
""";
- private static final String QUERY_HISTORY_SQL = "SELECT UNIX_TIMESTAMP(ts)
as ts, v['%s'], metrics FROM %s WHERE ts >= now() - interval '%s' and
monitor_id = %s `ORDER BY` ts `DESC`;";
+ private static final String QUERY_HISTORY_SQL = "SELECT UNIX_TIMESTAMP(ts)
as ts, v['%s'], metrics FROM %s WHERE ts >= now() - interval %s and monitor_id
= %s ORDER BY ts DESC;";
private HikariDataSource hikariDataSource;
@@ -115,7 +115,6 @@ public class DorisDataStorage extends
AbstractHistoryDataStorage {
private void createDatabase(String database) {
try (Connection connection = hikariDataSource.getConnection()) {
connection.createStatement().executeUpdate(String.format(CREATE_DATABASE_SQL,
database));
- log.info("[warehouse doris]--Create database {} successful",
database);
} catch (SQLException e) {
log.error("[warehouse doris]--Error: {}", e.getMessage(), e);
}
@@ -155,17 +154,15 @@ public class DorisDataStorage extends
AbstractHistoryDataStorage {
}
String interval = history2interval(history);
- String selectSql = String.format(QUERY_HISTORY_SQL, getTableName(app),
metric, interval, monitorId);
+ String selectSql = String.format(QUERY_HISTORY_SQL,
metric,getTableName(app), interval, monitorId);
try (Connection connection = hikariDataSource.getConnection()) {
connection.createStatement().execute("USE " +
dorisProperties.database());
ResultSet resultSet =
connection.createStatement().executeQuery(selectSql);
while (resultSet.next()) {
long ts = resultSet.getLong(1);
if (ts == 0) {
- if (log.isErrorEnabled()) {
log.error("[warehouse doris] getHistoryMetricData
query result timestamp is 0, ignore. {}.",
selectSql);
- }
continue;
}
String instanceValue = resultSet.getString(2);
@@ -186,22 +183,7 @@ public class DorisDataStorage extends
AbstractHistoryDataStorage {
}
return Map.of();
}
- private String double2decimalString(double d) {
- return BigDecimal.valueOf(d).setScale(4,
RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
- }
- private String history2interval(String history) {
- if (history == null) {
- return null;
- }
- history = history.trim().toLowerCase();
- // Be careful, the order matters.
- return history.replaceAll("d", " day") //
- .replaceAll("s", " second") //
- .replaceAll("w", " week") //
- .replaceAll("h", " hour")//
- .replaceAll("m", " minute");
- }
/**
* query history range interval metrics data from doris
* max min mean metrics value
@@ -270,7 +252,6 @@ public class DorisDataStorage extends
AbstractHistoryDataStorage {
tableName,
json
);
- log.info("[warehouse doris]-Write successful: {}", json);
} catch (Exception e) {
log.error("[warehouse doris]--Error: {}", e.getMessage(), e);
}
@@ -278,7 +259,21 @@ public class DorisDataStorage extends
AbstractHistoryDataStorage {
@Override
- public void destroy() throws Exception {
+ public void destroy() throws Exception {}
+ private String double2decimalString(double d) {
+ return BigDecimal.valueOf(d).setScale(4,
RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
+ }
+
+ private String history2interval(String history) {
+ if (history == null) {
+ return null;
+ }
+ history = history.trim().toLowerCase();
+ return history.replaceAll("d", " day") //
+ .replaceAll("s", " second") //
+ .replaceAll("w", " week") //
+ .replaceAll("h", " hour")//
+ .replaceAll("m", " minute");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]