Scenario 4: Converting Log Parameter Types Using the v, Cn_int, and Dt_totimestamp Functions
- Sub-scenario 1: calls the op_add function to concatenate characters and add data.
The op_add function supports both string and numeric types. Therefore, parameter type conversion is not required.
Example:
- Raw log
{ "a":"1", "b":"2" } - Processing rule
e_set("d",op_add(v("a"), v("b"))) e_set("e",op_add(ct_int(v("a")), ct_int(v("b")))) - Processing result
{ "a": 1, "b": 2, "d": 12, "e": 3 }
- Raw log
- Sub-scenario 2: calls the field operation and ct_int functions to convert a data type, and call the op_mul function to multiply data.
Example:
- Raw logs
{ "a":"2", "b":"5" } - Processing rule
e_set("c",op_mul(ct_int(v("a")), ct_int(v("b")))) e_set("d",op_mul(v("a"), ct_int(v("b")))) - Processing result
{ "a": 2, "b": 5, "c": 10, "d": 22222 }
- Raw logs
- Scenario 3: calls the dt_parse and dt_parsetimestamp functions to convert a string or date and time to the standard time.
The dt_totimestamp function receives datetime objects, not strings. Therefore, you need to call the dt_parse function to convert the string value type of time1 to the datetime object type. You can also use the dt_parsetimestamp function, which can receive both datetime objects and strings.
Example:
- Raw logs
{ "time1":"2019-09-17 9:00:00" } - Processing rule: converts the date and time represented by time1 to a Unix timestamp.
e_set("time2", dt_totimestamp(dt_parse(v("time1")))) - Processing result
{ "time1": "2019-09-17 9:00:00", "time2": 1568710800 }
- Raw logs
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot