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

zehnder pushed a commit to branch 
4133-connect-migration-for-addtimestamp-results-in-incorrect-data-type
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/4133-connect-migration-for-addtimestamp-results-in-incorrect-data-type
 by this push:
     new 6222a9e809 fix(#4133): Add originType for add timestamp rule migration
6222a9e809 is described below

commit 6222a9e809b9fed0c0ae133678ae5116dfe2ac0b
Author: Philipp Zehnder <[email protected]>
AuthorDate: Wed Jan 28 16:55:12 2026 +0100

    fix(#4133): Add originType for add timestamp rule migration
---
 .../v099/connect/AdapterRuleConverter.java         | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git 
a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v099/connect/AdapterRuleConverter.java
 
b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v099/connect/AdapterRuleConverter.java
index d964ae32ed..b5dbea2426 100644
--- 
a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v099/connect/AdapterRuleConverter.java
+++ 
b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v099/connect/AdapterRuleConverter.java
@@ -38,10 +38,12 @@ import 
org.apache.streampipes.model.connect.rules.value.TimestampTranfsformation
 import 
org.apache.streampipes.model.connect.rules.value.UnitTransformRuleDescription;
 import org.apache.streampipes.model.schema.EventPropertyPrimitive;
 import org.apache.streampipes.model.schema.EventSchema;
+import org.apache.streampipes.vocabulary.XSD;
 
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Locale;
 import java.util.Optional;
 
@@ -61,7 +63,7 @@ public class AdapterRuleConverter {
       handleDeleteRule((DeleteRuleDescription) rule, scriptBuilder);
 
     } else if (rule instanceof AddTimestampRuleDescription) {
-      handleAddTimestampRule((AddTimestampRuleDescription) rule, 
scriptBuilder);
+      handleAddTimestampRule((AddTimestampRuleDescription) rule, adapter, 
scriptBuilder);
 
     } else if (rule instanceof AddValueTransformationRuleDescription) {
       handleAddValueRule((AddValueTransformationRuleDescription) rule, 
scriptBuilder);
@@ -104,8 +106,18 @@ public class AdapterRuleConverter {
     scriptBuilder.appendLine(String.format("delete event['%s'];", 
rule.getRuntimeKey()));
   }
 
-  private void handleAddTimestampRule(AddTimestampRuleDescription rule, 
TransformationScriptBuilder scriptBuilder) {
-    scriptBuilder.appendLine(String.format("event['%s'] = Date.now();", 
rule.getRuntimeKey()));
+  private void handleAddTimestampRule(AddTimestampRuleDescription rule, 
AdapterDescription adapter, TransformationScriptBuilder scriptBuilder) {
+    // Add timestamp to the script
+    scriptBuilder.appendLine(String.format("event['%s'] = new 
Date().getTime();", rule.getRuntimeKey()));
+    if (adapter == null || rule.getRuntimeKey() == null || 
rule.getRuntimeKey().isEmpty()) {
+      return;
+    }
+
+    // add origin type to ensure that timestamp will be transformed to a long
+    findPrimitiveProperty(adapter, rule.getRuntimeKey()).ifPresent(property -> 
{
+      ensureAdditionalMetadata(property);
+      property.getAdditionalMetadata().put("originType", XSD.FLOAT.toString());
+    });
   }
 
   private void handleAddValueRule(AddValueTransformationRuleDescription rule, 
TransformationScriptBuilder scriptBuilder) {
@@ -192,6 +204,12 @@ public class AdapterRuleConverter {
         .findFirst();
   }
 
+  private void ensureAdditionalMetadata(EventPropertyPrimitive property) {
+    if (property.getAdditionalMetadata() == null) {
+      property.setAdditionalMetadata(new HashMap<>());
+    }
+  }
+
   private ReduceEventRateRule 
mapEventRate(EventRateTransformationRuleDescription rule) {
     return new ReduceEventRateRule(rule.getAggregationTimeWindow(), 
rule.getAggregationType());
   }

Reply via email to