Scenario 4: Converting Log Parameter Types Using the v, Cn_int, and Dt_totimestamp Functions
- Sub-scenario 1: calling 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: calling the field operation and ct_int functions to convert a data type, and calling the op_mul function to multiply data
Example:
- Raw log
{ "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 log
- Sub-scenario 3: calling the dt_parse and dt_parsetimestamp functions to convert a string or date and time to the standard time
The dt_totimestamp function requires datetime objects as input, not strings. Therefore, you must use 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 accepts both datetime objects and strings.
Example:
- Raw log
{ "time1":"2019-09-17 9:00:00" } - Processing rule: converts the date and time in 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 log
What is your overall rating for this page?
Thank 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