Skip to main content

Sqrt

Arithmetic Data Analysis

Synopsis​

Calculates the square root of a numeric value.

Schema​

- sqrt:
field: <ident>
value: <string>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration​

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Target field to store the square root result
valueY-Value to process - can be a literal value or field reference
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if square root calculation fails
ignore_missingNfalseSkip if referenced fields don't exist
on_failureN-Error handling processors
on_successN-Success handling processors
tagN-Identifier
disabledNfalseWhen true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration
warning

This operand is resolved by getNumericValue, which accepts exactly two forms: a numeric literal such as 3600, or a bare field path such as stats.total. Nothing else is evaluated.

There is no expression evaluator here, and no template expansion. "a / b" is looked up as a field literally named a / b, and "{{price}}" as a field literally named {{price}} — both fail with field does not exist. To compute a value first, use a math processor and reference the field it writes.

Details​

Calculates the square root of a numeric value and stores the result in the target field. The processor can extract values from existing fields or use literal numeric values.

note

The square root calculation uses the math.Sqrt function from Go's standard library, which provides accurate results for all non-negative numbers.

The processor is useful for mathematical transformations, statistical calculations, and implementing various formulas that require square root operations.

warning

Attempting to calculate the square root of a negative number will result in an error unless ignore_failure is set to true. Real-valued square roots are only defined for non-negative numbers.

Examples​

Basic​

Calculating the square root of a literal value...

{
"math": {}
}
- sqrt:
field: math.result
value: "144"

calculates and stores the result:

{
"math": {
"result": 12
}
}

Field-Based​

Calculating square root of a field value...

{
"circle": {
"area": 78.54
}
}
- math:
field: circle._area_over_pi
operation: divide
left_operand: circle.area
right_operand: "3.14159"
- sqrt:
field: circle.radius_from_area
value: "circle._area_over_pi"

computes radius from area:

{
"circle": {
"area": 78.54,
"radius_from_area": 5
}
}

Statistical​

Calculating standard deviation from variance...

{
"stats": {
"variance": 25.6
}
}
- sqrt:
field: stats.std_dev
value: "stats.variance"

derives standard deviation:

{
"stats": {
"variance": 25.6,
"std_dev": 5.06
}
}

Distances​

Calculating Euclidean distance...

{
"point1": {
"x": 3,
"y": 4
},
"point2": {
"x": 6,
"y": 8
}
}
- math:
field: distance.x_diff
operation: subtract
left_operand: point2.x
right_operand: point1.x
- math:
field: distance.y_diff
operation: subtract
left_operand: point2.y
right_operand: point1.y
- math:
field: distance.x_squared
operation: multiply
left_operand: distance.x_diff
right_operand: distance.x_diff
- math:
field: distance.y_squared
operation: multiply
left_operand: distance.y_diff
right_operand: distance.y_diff
- math:
field: distance.sum_of_squares
operation: add
left_operand: distance.x_squared
right_operand: distance.y_squared
- sqrt:
field: distance.euclidean
value: "distance.sum_of_squares"

implements the distance formula:

{
"point1": {
"x": 3,
"y": 4
},
"point2": {
"x": 6,
"y": 8
},
"distance": {
"x_diff": 3,
"y_diff": 4,
"sum_of_squares": 25,
"euclidean": 5
}
}

Error Handling​

Handling potential negative values...

{
"value": -9,
"calculation": {}
}
- sqrt:
field: calculation.result
value: "value"
on_failure:
- set:
field: calculation.error
value: "Cannot calculate square root of negative number"
- set:
field: calculation.result
value: "NaN"

continues execution:

{
"value": -9,
"calculation": {
"error": "Cannot calculate square root of negative number",
"result": "NaN"
}
}