Querying Data with Ickle and the Go Client

Tip
The source code for this tutorial is available on GitHub.

This tutorial demonstrates how to register Protobuf schemas and run Ickle queries with the Go Hot Rod client.

Prerequisites

  • A running Infinispan server.

  • Go 1.25 or later.

Running the Example

go run ./query

Code Walkthrough

Schema and Code Generation

The example uses a proto/person.proto file to generate a Go Person struct at build time with protoc. The same schema — with Infinispan indexing annotations — is registered on the server.

/* @Indexed */
message Person {
    /* @Keyword(projectable = true, sortable = true, normalizer = "lowercase") */
    string firstName = 1;
    /* @Keyword(projectable = true, sortable = true, normalizer = "lowercase") */
    string lastName = 2;
    /* @Basic(projectable = true, sortable = true) */
    int32 bornYear = 3;
    /* @Keyword(projectable = true, sortable = true, normalizer = "lowercase") */
    string bornIn = 4;
}

Creating a Typed Cache

TypedCache with ProtoStreamMarshaller handles serialization using the generated protobuf type. No manual encoding or decoding is needed.

cache := hotrod.NewTypedCache[string, *pb.Person](client, "indexedPeopleCache").Build()

Query All (Typed)

results, err := cache.Query(ctx, "from tutorial.Person")
for _, p := range results {
    fmt.Printf("  %s %s\n", p.FirstName, p.LastName)
}

Query with Named Parameters

results, err := cache.Query(ctx, "from tutorial.Person p where p.lastName = :lastName",
    hotrod.WithQueryParam("lastName", "Granger"),
)

Query with Projections

result, err := cache.QueryProjection(ctx, "select p.firstName, p.lastName from tutorial.Person p where p.bornIn = 'London'")
for _, entry := range result.Entries {
    fmt.Printf("  %s %s\n", entry.Projections[0], entry.Projections[1])
}

Expected Output

Registered person.proto schema.
Cache 'indexedPeopleCache' ready.
Added 4 people.

=== Query all ===
Total results: 4
  Hermione Granger
  Harry Potter
  Ron Wesley
  Draco Malfoy

=== Query: people with lastName = 'Granger' ===
  Hermione Granger

=== Query: projection of people born in London ===
  Hermione Granger
  Ron Wesley
  Draco Malfoy

Cache removed.