This is an automated email from the ASF dual-hosted git repository.

gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git


The following commit(s) were added to refs/heads/master by this push:
     new e2faa44f1 [fixbug] fix string type data parsing problem (#2066)
e2faa44f1 is described below

commit e2faa44f1822f707e1935c8c5424960b9ac22301
Author: Jast <[email protected]>
AuthorDate: Mon Jun 24 17:45:12 2024 +0800

    [fixbug] fix string type data parsing problem (#2066)
    
    Co-authored-by: zhangshenghang <[email protected]>
    Co-authored-by: tomsun28 <[email protected]>
---
 .../collector/dispatch/MetricsCollect.java         | 27 ++++++++++++++--------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/dispatch/MetricsCollect.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/dispatch/MetricsCollect.java
index 1677c78b9..118e8d5a2 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/dispatch/MetricsCollect.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/dispatch/MetricsCollect.java
@@ -227,6 +227,7 @@ public class MetricsCollect implements Runnable, 
Comparable<MetricsCollect> {
         List<String> aliasFields = metrics.getAliasFields();
         Map<String, String> aliasFieldValueMap = new HashMap<>(8);
         Map<String, Object> fieldValueMap = new HashMap<>(8);
+        Map<String, Object> stringTypefieldValueMap = new HashMap<>(8);
         Map<String, String> aliasFieldUnitMap = new HashMap<>(8);
         CollectRep.ValueRow.Builder realValueRowBuilder = 
CollectRep.ValueRow.newBuilder();
         for (CollectRep.ValueRow aliasRow : aliasRowList) {
@@ -246,11 +247,14 @@ public class MetricsCollect implements Runnable, 
Comparable<MetricsCollect> {
                     } else {
                         fieldValueMap.put(aliasField, aliasFieldValue);
                     }
+                    stringTypefieldValueMap.put(aliasField, aliasFieldValue);
                 } else {
                     fieldValueMap.put(aliasField, null);
+                    stringTypefieldValueMap.put(aliasField, null);
                 }
             }
 
+
             for (Metrics.Field field : fields) {
                 String realField = field.getField();
                 JexlExpression expression = fieldExpressionMap.get(realField);
@@ -258,14 +262,22 @@ public class MetricsCollect implements Runnable, 
Comparable<MetricsCollect> {
                 String aliasFieldUnit = null;
                 if (expression != null) {
                     try {
-                        for (Map.Entry<String, String> unitEntry : 
aliasFieldUnitMap.entrySet()) {
-                            if 
(expression.getSourceText().contains(unitEntry.getKey())) {
-                                aliasFieldUnit = unitEntry.getValue();
-                                break;
+                        Map<String, Object> context;
+                        if (CommonConstants.TYPE_STRING == field.getType()) {
+                            context = stringTypefieldValueMap;
+                        } else {
+                            for (Map.Entry<String, String> unitEntry : 
aliasFieldUnitMap.entrySet()) {
+                                if 
(expression.getSourceText().contains(unitEntry.getKey())) {
+                                    aliasFieldUnit = unitEntry.getValue();
+                                    break;
+                                }
                             }
+                            context = fieldValueMap;
                         }
+
                         // Also executed when valueList is empty, covering 
pure string assignment expressions
-                        Object objValue = 
JexlExpressionRunner.evaluate(expression, fieldValueMap);
+                        Object objValue = 
JexlExpressionRunner.evaluate(expression, context);
+
                         if (objValue != null) {
                             value = String.valueOf(objValue);
                         }
@@ -315,10 +327,6 @@ public class MetricsCollect implements Runnable, 
Comparable<MetricsCollect> {
                 if (CommonConstants.TYPE_NUMBER == field.getType()) {
                     value = CommonUtil.parseDoubleStr(value, field.getUnit());
                 }
-                // Handle the case where the value is string type and value is 
numeric
-                if (CommonConstants.TYPE_STRING == field.getType() && 
CommonUtil.isNumeric(value)) {
-                    value = CommonUtil.parseDoubleStr(value, field.getUnit());
-                }
                 if (value == null) {
                     value = CommonConstants.NULL_VALUE;
                 }
@@ -327,6 +335,7 @@ public class MetricsCollect implements Runnable, 
Comparable<MetricsCollect> {
             aliasFieldValueMap.clear();
             fieldValueMap.clear();
             aliasFieldUnitMap.clear();
+            stringTypefieldValueMap.clear();
             collectData.addValues(realValueRowBuilder.build());
             realValueRowBuilder.clear();
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to