Skip to content

Commit 61cf882

Browse files
esensarrtrieupront
authored andcommitted
docs(external): add docs for haversine VRL function (vectordotdev#23336)
* docs(external): add docs for `haversine` VRL function Related: vectordotdev/vrl#1442 * Apply suggestions from code review Co-authored-by: Rosa Trieu <107086888+rtrieu@users.noreply.github.com> * Rename haversine function in docs * Add map category to docs * Fix docs formatting * Generate #FunctionCategory disjunction from list to reduce duplication * Update names of arguments * Update VRL * Update VRL * Update types for haversine in docs --------- Co-authored-by: Rosa Trieu <107086888+rtrieu@users.noreply.github.com> Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>
1 parent 6440255 commit 61cf882

File tree

4 files changed

+79
-7
lines changed

4 files changed

+79
-7
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/cue/reference/remap/functions.cue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ remap: {
2828
pure: bool | *true
2929
}
3030

31-
#FunctionCategory: "Array" | "Codec" | "Coerce" | "Convert" | "Debug" | "Enrichment" | "Enumerate" | "Event" | "Path" | "Cryptography" | "IP" | "Number" | "Object" | "Parse" | "Random" | "String" | "System" | "Timestamp" | "Type" | "Checksum"
32-
33-
// A helper array for generating docs. At some point, we should generate this from the
34-
// #FunctionCategory enum if CUE adds support for that.
3531
function_categories: [
3632
"Array",
3733
"Codec",
@@ -44,6 +40,7 @@ remap: {
4440
"Path",
4541
"Cryptography",
4642
"IP",
43+
"Map",
4744
"Number",
4845
"Object",
4946
"Parse",
@@ -55,6 +52,8 @@ remap: {
5552
"Checksum",
5653
]
5754

55+
#FunctionCategory: or(function_categories)
56+
5857
functions: [Name=string]: #Function & {
5958
name: Name
6059
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package metadata
2+
3+
remap: functions: haversine: {
4+
category: "Map"
5+
description: """
6+
Calculates [haversine](\(urls.haversine)) distance and bearing between two points.
7+
Results are available in kilometers or miles.
8+
"""
9+
10+
arguments: [
11+
{
12+
name: "latitude1"
13+
description: "Latitude of the first point."
14+
required: true
15+
type: ["float"]
16+
},
17+
{
18+
name: "longitude1"
19+
description: "Longitude of the first point."
20+
required: true
21+
type: ["float"]
22+
},
23+
{
24+
name: "latitude2"
25+
description: "Latitude of the second point."
26+
required: true
27+
type: ["float"]
28+
},
29+
{
30+
name: "longitude2"
31+
description: "Longitude of the second point."
32+
required: true
33+
type: ["float"]
34+
},
35+
{
36+
name: "measurement"
37+
description: "Measurement system to use for resulting distance."
38+
required: false
39+
type: ["string"]
40+
default: "kilometers"
41+
enum: {
42+
kilometers: "Use kilometers for the resulting distance."
43+
miles: "Use miles for the resulting distance."
44+
}
45+
},
46+
]
47+
internal_failure_reasons: []
48+
return: types: ["object"]
49+
50+
examples: [
51+
{
52+
title: "Haversine in kilometers"
53+
source: #"""
54+
haversine(0.0, 0.0, 10.0, 10.0)
55+
"""#
56+
return: {
57+
distance: 1568.5227233
58+
bearing: 44.561
59+
}
60+
},
61+
{
62+
title: "Haversine in miles"
63+
source: #"""
64+
haversine(0.0, 0.0, 10.0, 10.0, "miles")
65+
"""#
66+
return: {
67+
distance: 974.6348468
68+
bearing: 44.561
69+
}
70+
},
71+
]
72+
}

website/cue/reference/urls.cue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ urls: {
246246
grok_patterns: "\(github)/daschl/grok/tree/master/patterns"
247247
gzip: "https://www.gzip.org/"
248248
haproxy: "https://www.haproxy.org/"
249+
haversine: "\(wikipedia)/wiki/Haversine_formula"
249250
helm: "https://helm.sh/"
250251
heroku: "https://www.heroku.com"
251252
heroku_http_log_drain: "https://devcenter.heroku.com/articles/log-drains#https-drains"

0 commit comments

Comments
 (0)