Back to Influxdb

strings.compare() function

content/flux/v0/stdlib/strings/compare.md

latest2.3 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/strings/strings.flux#L387-L387 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

strings.compare() compares the lexicographical order of two strings.

Return values

ComparisonReturn value
v < t-1
v == t0
v > t1
Function type signature
js
(t: string, v: string) => int

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

v

({{< req >}}) String value to compare.

t

({{< req >}}) String value to compare against.

Examples

Compare the lexicographical order of column values

js
import "strings"

data
    |> map(fn: (r) => ({r with same: strings.compare(v: r.string1, t: r.string2)}))

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

timestring1string2
2022-01-01T00:00:00ZRJqcVGNlcJrjQCvGNLCj
2022-01-01T00:01:00ZunfbcNAXUAhBumdSljCQ
2022-01-01T00:02:00ZITcHyLZuquITcHyLZuqu
2022-01-01T00:03:00ZHyXdjvrjgphyxDJvrJGP
2022-01-01T00:04:00ZSVepvUBAVxGuKKjuGsyI

Output data

samestring1string2time
-1RJqcVGNlcJrjQCvGNLCj2022-01-01T00:00:00Z
1unfbcNAXUAhBumdSljCQ2022-01-01T00:01:00Z
0ITcHyLZuquITcHyLZuqu2022-01-01T00:02:00Z
-1HyXdjvrjgphyxDJvrJGP2022-01-01T00:03:00Z
1SVepvUBAVxGuKKjuGsyI2022-01-01T00:04:00Z

{{% /expand %}} {{< /expand-wrapper >}}