Skip to content

Add explain/trace example #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-compatability-1412.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 14.1.2-0-0
- 14.1.2-0-1
- 14.1.2-0-2-SNAPSHOT
go-version:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-compatability-2206.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 22.06.10
- 22.06.11
- 22.06.12-SNAPSHOT
go-version:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-compatability-v1-1412.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 14.1.2-0-0
- 14.1.2-0-1
- 14.1.2-0-2-SNAPSHOT
go-version:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-compatability-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 24.09
- 24.09.2
- 24.09.4-SNAPSHOT
go-version:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-compatability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 24.09
- 24.09.3
go-version:
- 1.19.x
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-queues-1412.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 14.1.2-0-0
- 14.1.2-0-1
- 14.1.2-0-2-SNAPSHOT
go-version:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-queues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 24.09
- 24.09.3
- 24.09.4-SNAPSHOT
go-version:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/examples-v1.2.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
matrix:
coherenceVersion:
- 22.06.12-SNAPSHOT
- 22.06.10
- 22.06.11
go-version:
- 1.19.x
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ jobs:
matrix:
coherenceVersion:
- 22.06.12-SNAPSHOT
- 22.06.10
- 22.06.11
- 14.1.2-0-0
- 14.1.2-0-1
- 14.1.2-0-2-SNAPSHOT
go-version:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/resolver-clusters-compatability-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 22.06.10
- 22.06.11
- 24.09
- 24.09.2
- 14.1.2-0-0
- 14.1.2-0-1
go-version:
- 1.19.x
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/resolver-compatability-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ jobs:
fail-fast: false
matrix:
coherenceVersion:
- 22.06.10
- 22.06.11
- 24.09
- 24.09.2
- 14.1.2-0-0
- 24.09.3
- 14.1.2-0-1
go-version:
- 1.19.x
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# ----------------------------------------------------------------------------------------------------------------------

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

Expand Down
12 changes: 10 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,18 @@ go run querying/main.go

This example shows how to carry out various aggregations against a NamedMap or NamedCache.

Source code: [aggregators/main.go](aggregators/main.go)
Source code: [aggregators/basic/main.go](aggregators/basic/main.go)

```go
go run aggregators/main.go
go run aggregators/basic/main.go
```

This example shows how to carry out an explain plan against a NamedMap or NamedCache.

Source code: [aggregators/explain/main.go](aggregators/explain/main.go)

```go
go run aggregators/explain/main.go
```

### <a name="processors"></a> Running processors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
Expand Down
107 changes: 107 additions & 0 deletions examples/aggregators/explain/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/

/*
Package main shows how to run an explain plan using a NamedMap with key of int and value of Person struct.
*/
package main

import (
"context"
"encoding/json"
"fmt"
"github.com/oracle/coherence-go-client/v2/coherence"
"github.com/oracle/coherence-go-client/v2/coherence/aggregators"
"github.com/oracle/coherence-go-client/v2/coherence/extractors"
"github.com/oracle/coherence-go-client/v2/coherence/filters"
)

type Person struct {
ID int `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
Department string `json:"department"`
}

func main() {
var (
personData = map[int]Person{
1: {ID: 1, Name: "Tim", Age: 19, Department: "IT"},
2: {ID: 2, Name: "Andrew", Age: 20, Department: "IT"},
3: {ID: 3, Name: "John", Age: 30, Department: "HR"},
4: {ID: 4, Name: "Steve", Age: 40, Department: "Finance"},
}
ctx = context.Background()
)

// create a new Session to the default gRPC port of 1408 using plain text
session, err := coherence.NewSession(ctx, coherence.WithPlainText())

if err != nil {
panic(err)
}

defer session.Close()

// create a new NamedMap of Person with key int
namedMap, err := coherence.GetNamedMap[int, Person](session, "explain-test")
if err != nil {
panic(err)
}

// Add an index on department
department := extractors.Extract[string]("department")

err = coherence.AddIndex(ctx, namedMap, department, true)
if err != nil {
panic(err)
}

// clear and populate the Map
_ = namedMap.Clear(ctx)

if err = namedMap.PutAll(ctx, personData); err != nil {
panic(err)
}

jsonResult, err := coherence.AggregateFilter[int, Person, map[string]interface{}](ctx, namedMap,
filters.Equal(department, "IT"),
aggregators.QueryRecorder(aggregators.Explain))
if err != nil {
panic(err)
}

var results string

if results, err = getResults(jsonResult); err != nil {
panic(err)
}

fmt.Println(aggregators.Explain)
fmt.Println(results)

jsonResult, err = coherence.AggregateFilter[int, Person, map[string]interface{}](ctx, namedMap,
filters.Equal(department, "IT"),
aggregators.QueryRecorder(aggregators.Trace))
if err != nil {
panic(err)
}

if results, err = getResults(jsonResult); err != nil {
panic(err)
}
fmt.Println(aggregators.Trace)
fmt.Println(results)
}

func getResults(results *map[string]interface{}) (string, error) {
prettyJSON, err := json.MarshalIndent(results, "", " ")
if err != nil {
return "", fmt.Errorf("error marshalling: %v", err)
}

return string(prettyJSON), nil
}
Loading