Skip to main content
Version: 1.2.0

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

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
}
}
- sqrt:
field: circle.radius_from_area
value: "circle.area / 3.14159"

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
}
}
- set:
field: distance.x_diff
value: "{{point2.x - point1.x}}"
- set:
field: distance.y_diff
value: "{{point2.y - point1.y}}"
- set:
field: distance.sum_of_squares
value: "{{distance.x_diff * distance.x_diff + distance.y_diff * distance.y_diff}}"
- 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"
ignore_failure: true
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"
}
}