forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateUuidExpressionFunction.java
More file actions
40 lines (33 loc) · 1.09 KB
/
Copy pathGenerateUuidExpressionFunction.java
File metadata and controls
40 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.dataprepper.expression;
import org.opensearch.dataprepper.model.event.Event;
import javax.inject.Named;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
/**
* Expression function that generates a random UUID (version 4) string.
* Usage: {@code generateUuid()}
*/
@Named
public class GenerateUuidExpressionFunction implements ExpressionFunction {
static final String FUNCTION_NAME = "generateUuid";
@Override
public String getFunctionName() {
return FUNCTION_NAME;
}
@Override
public Object evaluate(final List<Object> args, final Event event, final Function<Object, Object> convertLiteralType) {
if (!args.isEmpty()) {
throw new RuntimeException(FUNCTION_NAME + "() does not take any arguments");
}
return UUID.randomUUID().toString();
}
}