Skip to content

Commit 6687bdf

Browse files
authored
Add explain/trace example (#114)
* Add explain/trace example * Minor typo * Minor update to fix ci/cd
1 parent 2c33931 commit 6687bdf

15 files changed

+120
-21
lines changed

.github/workflows/build-compatability-1412.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
coherenceVersion:
26-
- 14.1.2-0-0
2726
- 14.1.2-0-1
2827
- 14.1.2-0-2-SNAPSHOT
2928
go-version:

.github/workflows/build-compatability-2206.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
coherenceVersion:
26-
- 22.06.10
2726
- 22.06.11
2827
- 22.06.12-SNAPSHOT
2928
go-version:

.github/workflows/build-compatability-v1-1412.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
coherenceVersion:
26-
- 14.1.2-0-0
2726
- 14.1.2-0-1
2827
- 14.1.2-0-2-SNAPSHOT
2928
go-version:

.github/workflows/build-compatability-v1.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
coherenceVersion:
26-
- 24.09
2726
- 24.09.2
2827
- 24.09.4-SNAPSHOT
2928
go-version:

.github/workflows/build-compatability.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
coherenceVersion:
26-
- 24.09
2726
- 24.09.3
2827
go-version:
2928
- 1.19.x

.github/workflows/build-queues-1412.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
coherenceVersion:
26-
- 14.1.2-0-0
2726
- 14.1.2-0-1
2827
- 14.1.2-0-2-SNAPSHOT
2928
go-version:

.github/workflows/build-queues.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
coherenceVersion:
26-
- 24.09
2726
- 24.09.3
2827
- 24.09.4-SNAPSHOT
2928
go-version:

.github/workflows/examples-v1.2.2.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
matrix:
2323
coherenceVersion:
2424
- 22.06.12-SNAPSHOT
25-
- 22.06.10
2625
- 22.06.11
2726
go-version:
2827
- 1.19.x

.github/workflows/examples.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ jobs:
2121
matrix:
2222
coherenceVersion:
2323
- 22.06.12-SNAPSHOT
24-
- 22.06.10
2524
- 22.06.11
26-
- 14.1.2-0-0
2725
- 14.1.2-0-1
2826
- 14.1.2-0-2-SNAPSHOT
2927
go-version:

.github/workflows/resolver-clusters-compatability-tests.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
coherenceVersion:
23-
- 22.06.10
2423
- 22.06.11
25-
- 24.09
2624
- 24.09.2
27-
- 14.1.2-0-0
2825
- 14.1.2-0-1
2926
go-version:
3027
- 1.19.x

.github/workflows/resolver-compatability-tests.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
coherenceVersion:
23-
- 22.06.10
2423
- 22.06.11
25-
- 24.09
26-
- 24.09.2
27-
- 14.1.2-0-0
24+
- 24.09.3
2825
- 14.1.2-0-1
2926
go-version:
3027
- 1.19.x

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# ----------------------------------------------------------------------------------------------------------------------
99

1010
# This is the version of the coherence-go-client
11-
VERSION ?=2.0.0-rc1
11+
VERSION ?=2.0.1
1212
CURRDIR := $(shell pwd)
1313
USER_ID := $(shell echo "`id -u`:`id -g`")
1414

examples/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,18 @@ go run querying/main.go
165165
166166
This example shows how to carry out various aggregations against a NamedMap or NamedCache.
167167
168-
Source code: [aggregators/main.go](aggregators/main.go)
168+
Source code: [aggregators/basic/main.go](aggregators/basic/main.go)
169169
170170
```go
171-
go run aggregators/main.go
171+
go run aggregators/basic/main.go
172+
```
173+
174+
This example shows how to carry out an explain plan against a NamedMap or NamedCache.
175+
176+
Source code: [aggregators/explain/main.go](aggregators/explain/main.go)
177+
178+
```go
179+
go run aggregators/explain/main.go
172180
```
173181
174182
### <a name="processors"></a> Running processors

examples/aggregators/main.go renamed to examples/aggregators/basic/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* https://oss.oracle.com/licenses/upl.
55
*/

examples/aggregators/explain/main.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
3+
* Licensed under the Universal Permissive License v 1.0 as shown at
4+
* https://oss.oracle.com/licenses/upl.
5+
*/
6+
7+
/*
8+
Package main shows how to run an explain plan using a NamedMap with key of int and value of Person struct.
9+
*/
10+
package main
11+
12+
import (
13+
"context"
14+
"encoding/json"
15+
"fmt"
16+
"github.com/oracle/coherence-go-client/v2/coherence"
17+
"github.com/oracle/coherence-go-client/v2/coherence/aggregators"
18+
"github.com/oracle/coherence-go-client/v2/coherence/extractors"
19+
"github.com/oracle/coherence-go-client/v2/coherence/filters"
20+
)
21+
22+
type Person struct {
23+
ID int `json:"id"`
24+
Name string `json:"name"`
25+
Age int `json:"age"`
26+
Department string `json:"department"`
27+
}
28+
29+
func main() {
30+
var (
31+
personData = map[int]Person{
32+
1: {ID: 1, Name: "Tim", Age: 19, Department: "IT"},
33+
2: {ID: 2, Name: "Andrew", Age: 20, Department: "IT"},
34+
3: {ID: 3, Name: "John", Age: 30, Department: "HR"},
35+
4: {ID: 4, Name: "Steve", Age: 40, Department: "Finance"},
36+
}
37+
ctx = context.Background()
38+
)
39+
40+
// create a new Session to the default gRPC port of 1408 using plain text
41+
session, err := coherence.NewSession(ctx, coherence.WithPlainText())
42+
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
defer session.Close()
48+
49+
// create a new NamedMap of Person with key int
50+
namedMap, err := coherence.GetNamedMap[int, Person](session, "explain-test")
51+
if err != nil {
52+
panic(err)
53+
}
54+
55+
// Add an index on department
56+
department := extractors.Extract[string]("department")
57+
58+
err = coherence.AddIndex(ctx, namedMap, department, true)
59+
if err != nil {
60+
panic(err)
61+
}
62+
63+
// clear and populate the Map
64+
_ = namedMap.Clear(ctx)
65+
66+
if err = namedMap.PutAll(ctx, personData); err != nil {
67+
panic(err)
68+
}
69+
70+
jsonResult, err := coherence.AggregateFilter[int, Person, map[string]interface{}](ctx, namedMap,
71+
filters.Equal(department, "IT"),
72+
aggregators.QueryRecorder(aggregators.Explain))
73+
if err != nil {
74+
panic(err)
75+
}
76+
77+
var results string
78+
79+
if results, err = getResults(jsonResult); err != nil {
80+
panic(err)
81+
}
82+
83+
fmt.Println(aggregators.Explain)
84+
fmt.Println(results)
85+
86+
jsonResult, err = coherence.AggregateFilter[int, Person, map[string]interface{}](ctx, namedMap,
87+
filters.Equal(department, "IT"),
88+
aggregators.QueryRecorder(aggregators.Trace))
89+
if err != nil {
90+
panic(err)
91+
}
92+
93+
if results, err = getResults(jsonResult); err != nil {
94+
panic(err)
95+
}
96+
fmt.Println(aggregators.Trace)
97+
fmt.Println(results)
98+
}
99+
100+
func getResults(results *map[string]interface{}) (string, error) {
101+
prettyJSON, err := json.MarshalIndent(results, "", " ")
102+
if err != nil {
103+
return "", fmt.Errorf("error marshalling: %v", err)
104+
}
105+
106+
return string(prettyJSON), nil
107+
}

0 commit comments

Comments
 (0)