Skip to content

Commit f6e2b5b

Browse files
Add Go snippets for datasets
1 parent 3cebc4b commit f6e2b5b

27 files changed

+1203
-232
lines changed

api-reference/go/datasets/As.mdx

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: As
3+
sidebarTitle: As
4+
icon: layer-group
5+
---
6+
7+
```go
8+
func As[T proto.Message](seq iter.Seq2[[]byte, error]) iter.Seq2[T, error]
9+
```
10+
11+
Convert a sequence of bytes into a sequence of `proto.Message`.
12+
13+
Useful to convert the output of [`Datapoints.Query`](/api-reference/go/datasets/Datapoints.Query) into a sequence of `proto.Message`.
14+
15+
## Parameters
16+
17+
<ParamField path="seq" type="iter.Seq2[[]byte, error]">
18+
The sequence of bytes to convert
19+
</ParamField>
20+
21+
## Returns
22+
23+
A sequence of `proto.Message` or an error if any.
24+
25+
<RequestExample>
26+
```go Go
27+
import (
28+
"time"
29+
datasets "github.com/tilebox/tilebox-go/datasets/v1"
30+
"github.com/tilebox/tilebox-go/query"
31+
)
32+
33+
startDate := time.Date(2014, 10, 4, 0, 0, 0, 0, time.UTC)
34+
endDate := time.Date(2021, 2, 24, 0, 0, 0, 0, time.UTC)
35+
queryInterval := query.NewTimeInterval(startDate, endDate)
36+
37+
seq := datasets.As[*tileboxv1.Sentinel1Sar](
38+
client.Datapoints.Query(ctx, collectionID, datasets.WithTemporalExtent(queryInterval)),
39+
)
40+
```
41+
</RequestExample>

api-reference/go/datasets/Collect.mdx

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Collect
3+
sidebarTitle: Collect
4+
icon: layer-group
5+
---
6+
7+
```go
8+
func Collect[K any](seq iter.Seq2[K, error]) ([]K, error)
9+
```
10+
11+
Convert any sequence into a slice.
12+
13+
It return an error if any of the elements in the sequence has a non-nil error.
14+
15+
## Parameters
16+
17+
<ParamField path="seq" type="iter.Seq2[[]K, error]">
18+
The sequence of bytes to convert
19+
</ParamField>
20+
21+
## Returns
22+
23+
A slice of `K` or an error if any.
24+
25+
<RequestExample>
26+
```go Go
27+
import (
28+
"time"
29+
datasets "github.com/tilebox/tilebox-go/datasets/v1"
30+
"github.com/tilebox/tilebox-go/query"
31+
)
32+
33+
startDate := time.Date(2014, 10, 4, 0, 0, 0, 0, time.UTC)
34+
endDate := time.Date(2021, 2, 24, 0, 0, 0, 0, time.UTC)
35+
queryInterval := query.NewTimeInterval(startDate, endDate)
36+
37+
datapoints, err := datasets.Collect(datasets.As[*tileboxv1.Sentinel1Sar](
38+
client.Datapoints.Query(ctx, collectionID, datasets.WithTemporalExtent(queryInterval)),
39+
))
40+
```
41+
</RequestExample>
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: CollectAs
3+
sidebarTitle: CollectAs
4+
icon: layer-group
5+
---
6+
7+
```go
8+
func CollectAs[T proto.Message](seq iter.Seq2[[]byte, error]) ([]T, error)
9+
```
10+
11+
Convert a sequence of bytes into a slice of `proto.Message`.
12+
13+
Useful to convert the output of [`Datapoints.Query`](/api-reference/go/datasets/Datapoints.Query) into a slice of `proto.Message`.
14+
15+
This a convenience function for `Collect(As[T](seq))`.
16+
17+
## Parameters
18+
19+
<ParamField path="seq" type="iter.Seq2[[]byte, error]">
20+
The sequence of bytes to convert
21+
</ParamField>
22+
23+
## Returns
24+
25+
A slice of `proto.Message` or an error if any.
26+
27+
<RequestExample>
28+
```go Go
29+
import (
30+
"time"
31+
datasets "github.com/tilebox/tilebox-go/datasets/v1"
32+
"github.com/tilebox/tilebox-go/query"
33+
)
34+
35+
startDate := time.Date(2014, 10, 4, 0, 0, 0, 0, time.UTC)
36+
endDate := time.Date(2021, 2, 24, 0, 0, 0, 0, time.UTC)
37+
queryInterval := query.NewTimeInterval(startDate, endDate)
38+
39+
datapoints, err := datasets.CollectAs[*tileboxv1.Sentinel1Sar](
40+
client.Datapoints.Query(ctx, collectionID, datasets.WithTemporalExtent(queryInterval)),
41+
)
42+
```
43+
</RequestExample>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Client.Collections.GetOrCreate
3+
sidebarTitle: Collections.GetOrCreate
4+
icon: layer-group
5+
---
6+
7+
```go
8+
func (collectionClient) GetOrCreate(
9+
ctx context.Context,
10+
datasetID uuid.UUID,
11+
name string,
12+
) (*datasets.Collection, error)
13+
```
14+
15+
Get or create a collection by its name. If the collection does not exist, it will be created.
16+
17+
## Parameters
18+
19+
<ParamField path="datasetID" type="uuid.UUID">
20+
The id of the dataset
21+
</ParamField>
22+
<ParamField path="name" type="string">
23+
The name of the collection
24+
</ParamField>
25+
26+
## Returns
27+
28+
A collection object.
29+
30+
<RequestExample>
31+
```go Go
32+
collection, err := client.Collections.GetOrCreate(ctx,
33+
datasetID,
34+
"My-collection",
35+
)
36+
```
37+
</RequestExample>

api-reference/go/datasets/Datapoints.Delete.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func (datapointClient) Delete(
99
ctx context.Context,
1010
collectionID uuid.UUID,
1111
datapoints any,
12-
) (*datasets.DeleteResponse, error)
12+
) (int64, error)
1313
```
1414

1515
Delete data points from a collection.
@@ -34,7 +34,7 @@ The number of data points that were deleted.
3434
var datapoints []*tileboxv1.Sentinel1Sar
3535
// assuming the slice is filled with datapoints
3636

37-
deleteResponse, err := client.Datapoints.Delete(ctx,
37+
numDeleted, err := client.Datapoints.Delete(ctx,
3838
collectionID,
3939
datapoints,
4040
)

api-reference/go/datasets/Datapoints.DeleteIDs.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func (datapointClient) DeleteIDs(
99
ctx context.Context,
1010
collectionID uuid.UUID,
1111
datapointIDs []uuid.UUID,
12-
) (*datasets.DeleteResponse, error)
12+
) (int64, error)
1313
```
1414

1515
Delete data points from a collection.
@@ -29,7 +29,7 @@ The number of data points that were deleted.
2929

3030
<RequestExample>
3131
```go Go
32-
deleteResponse, err := client.Datapoints.DeleteIDs(ctx,
32+
numDeleted, err := client.Datapoints.DeleteIDs(ctx,
3333
collectionID,
3434
[]uuid.UUID{
3535
uuid.MustParse("0195c87a-49f6-5ffa-e3cb-92215d057ea6"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Client.Datapoints.GetInto
3+
sidebarTitle: Datapoints.GetInto
4+
icon: layer-group
5+
---
6+
7+
```go
8+
func (datapointClient) GetInto(
9+
ctx context.Context,
10+
collectionIDs []uuid.UUID,
11+
datapointID uuid.UUID,
12+
datapoint proto.Message,
13+
options ...QueryOption,
14+
) error
15+
```
16+
17+
Get a data point by its id from one of the specified collections.
18+
19+
The data point is stored in the `datapoint` parameter.
20+
21+
## Parameters
22+
23+
<ParamField path="collectionIDs" type="[]uuid.UUID">
24+
The ids of the collections to query
25+
</ParamField>
26+
<ParamField path="datapointID" type="uuid.UUID">
27+
The id of the datapoint to query
28+
</ParamField>
29+
<ParamField path="datapoint" type="proto.Message">
30+
The datapoint to query into
31+
</ParamField>
32+
<ParamField path="options" type="[]QueryOption">
33+
Options for querying data points.
34+
</ParamField>
35+
36+
## Options
37+
38+
<ParamField path="WithSkipData()" default="false">
39+
Skip the data when querying datapoint.
40+
If set, only the required and auto-generated fields will be returned.
41+
</ParamField>
42+
43+
## Returns
44+
45+
An error if data point could not be queried.
46+
47+
<RequestExample>
48+
```go Go
49+
var datapoint tileboxv1.Sentinel1Sar
50+
err = client.Datapoints.GetInto(ctx,
51+
[]uuid.UUID{collection.ID}, datapointID, &datapoint,
52+
)
53+
```
54+
</RequestExample>

api-reference/go/datasets/Datapoints.Load.mdx

-60
This file was deleted.

api-reference/go/datasets/Datapoints.LoadInto.mdx

-63
This file was deleted.

0 commit comments

Comments
 (0)