diff options
| author | wangkuan <[email protected]> | 2024-10-12 17:53:49 +0800 |
|---|---|---|
| committer | wangkuan <[email protected]> | 2024-10-12 17:53:49 +0800 |
| commit | 72ba1827fb4a5ccf05e450a83dc930766c9f95e3 (patch) | |
| tree | 2e0fab7bac4c23d3fe4b1b9ad958b29c259130d8 | |
| parent | b400832690c4e7f50aded6b9651793f0a2870253 (diff) | |
[improve][core]uuid输出为string,uuidv7在初始化生成timeBasedEpochRandomGenerator对象feature/udf-uuid
3 files changed, 14 insertions, 10 deletions
diff --git a/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/Uuid.java b/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/Uuid.java index 6100a9f..2c77108 100644 --- a/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/Uuid.java +++ b/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/Uuid.java @@ -1,23 +1,19 @@ package com.geedgenetworks.core.udf.uuid; import com.fasterxml.uuid.Generators; +import com.fasterxml.uuid.impl.RandomBasedGenerator; import com.geedgenetworks.common.Event; import com.geedgenetworks.common.exception.CommonErrorCode; import com.geedgenetworks.common.exception.GrootStreamRuntimeException; import com.geedgenetworks.common.udf.ScalarFunction; import com.geedgenetworks.common.udf.UDFContext; -import com.geedgenetworks.core.utils.SnowflakeIdUtils; import lombok.extern.slf4j.Slf4j; import org.apache.flink.api.common.functions.RuntimeContext; -import java.util.List; -import java.util.UUID; - -import static com.geedgenetworks.utils.FormatUtils.getTopPrivateDomain; - @Slf4j public class Uuid implements ScalarFunction { private String outputFieldName; + private RandomBasedGenerator randomBasedGenerator; @Override public void open(RuntimeContext runtimeContext, UDFContext udfContext) { @@ -28,13 +24,14 @@ public class Uuid implements ScalarFunction { throw new GrootStreamRuntimeException(CommonErrorCode.ILLEGAL_ARGUMENT, "The function output fields only support 1 value"); } this.outputFieldName = udfContext.getOutput_fields().get(0); + this.randomBasedGenerator = Generators.randomBasedGenerator(); } @Override public Event evaluate(Event event) { event.getExtractedFields() - .put(outputFieldName, Generators.randomBasedGenerator().generate()); + .put(outputFieldName, randomBasedGenerator.generate().toString()); return event; } @@ -47,4 +44,6 @@ public class Uuid implements ScalarFunction { public void close() { } + + } diff --git a/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/UuidV5.java b/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/UuidV5.java index 85199af..ad46ec4 100644 --- a/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/UuidV5.java +++ b/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/UuidV5.java @@ -44,7 +44,7 @@ public class UuidV5 implements ScalarFunction { } } event.getExtractedFields() - .put(outputFieldName, nameBasedGenerator.generate(sb.toString())); + .put(outputFieldName, nameBasedGenerator.generate(sb.toString()).toString()); return event; } diff --git a/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/UuidV7.java b/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/UuidV7.java index cbffc11..9dfbce3 100644 --- a/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/UuidV7.java +++ b/groot-core/src/main/java/com/geedgenetworks/core/udf/uuid/UuidV7.java @@ -1,6 +1,8 @@ package com.geedgenetworks.core.udf.uuid; import com.fasterxml.uuid.Generators; +import com.fasterxml.uuid.impl.NameBasedGenerator; +import com.fasterxml.uuid.impl.TimeBasedEpochGenerator; import com.geedgenetworks.common.Event; import com.geedgenetworks.common.exception.CommonErrorCode; import com.geedgenetworks.common.exception.GrootStreamRuntimeException; @@ -12,6 +14,8 @@ import org.apache.flink.api.common.functions.RuntimeContext; @Slf4j public class UuidV7 implements ScalarFunction { private String outputFieldName; + private TimeBasedEpochGenerator timeBasedEpochRandomGenerator; + @Override public void open(RuntimeContext runtimeContext, UDFContext udfContext) { @@ -22,13 +26,14 @@ public class UuidV7 implements ScalarFunction { throw new GrootStreamRuntimeException(CommonErrorCode.ILLEGAL_ARGUMENT, "The function output fields only support 1 value"); } this.outputFieldName = udfContext.getOutput_fields().get(0); + this.timeBasedEpochRandomGenerator = Generators.timeBasedEpochGenerator(); + } @Override public Event evaluate(Event event) { - event.getExtractedFields() - .put(outputFieldName, Generators.timeBasedEpochRandomGenerator().generate()); + .put(outputFieldName, timeBasedEpochRandomGenerator.generate().toString()); return event; } |
