Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*): Support Time Type to Tengine Data Storage #1890

Merged
merged 2 commits into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(")
Expand Down Expand Up @@ -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) {
Expand All @@ -235,7 +239,7 @@ public void destroy() {
@Override
public Map<String, List<Value>> 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<String, List<Value>> instanceValuesMap = new HashMap<>(8);
Expand Down Expand Up @@ -322,7 +326,7 @@ public Map<String, List<Value>> 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<Value> values = instanceValuesMap.computeIfAbsent(instanceValue, k -> new LinkedList<>());
Connection connection = null;
Expand Down
Loading