Skip to content

docs(golang): give the sort expression for each ordered EQL type - #1915

Open
auxesis wants to merge 2 commits into
nextfrom
docs/go-type-table
Open

auxesis wants to merge 2 commits into
nextfrom
docs/go-type-table

Conversation

@auxesis

@auxesis auxesis commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Go SDK docs now say how to sort each ordered EQL column correctly. EQL (Encrypt Query Language) is the PostgreSQL extension that stores and queries the encrypted values. The type table said that ordered types support ORDER BY. But a plain ORDER BY col returns rows in the wrong order, with no error.

The docs also now say that decimal, date, and timestamp fields can take an order index. They no longer say that bytes can.

Changes

languages/golang/encrypt/README.md:

  • The EQL type table gives the sort expression for each ordered type. The OrdOre types now have rows of their own, because they sort with a different function.
  • A "Take care" note before the table warns that a plain ORDER BY col sorts wrongly, with no error. The note also says that eql_v4.ord_term(col) fails on an OrdOre or TextSearchOre column.
  • The "What is stored" table lists ore and ope for encrypt.Decimal, encrypt.Date, and time.Time, with their query methods. The sentence that said these orders are refused is replaced.
  • The Queries table lists every type that takes index=ore or index=ope.

languages/golang/encrypt/doc.go:

  • The list of ordered EQL types includes DateOrd, TimestampOrd, and NumericOrd. It also gives the sort expressions and the warning.
  • Bytes are removed from the types that take ORE (order-revealing encryption) and OPE (order-preserving encryption). A new sentence says that stashgen refuses an order index on bytes.

languages/golang/CHANGELOG.md: an entry under Unreleased.

The sort expression for each type:

Types Sort with
*Ord, *OrdOpe, TextSearch ORDER BY eql_v4.ord_term(col)
*OrdOre, TextSearchOre ORDER BY eql_v4.ord_term_ore(col)

Verification

  • Sort expressions. I read them from the EQL v4 SQL source in packages/eql/src/v3/scalars/*/. EQL v4 is built from that source. eql_v4.ord_term is defined for every *_ord and *_ord_ope domain, and for text_search. eql_v4.ord_term_ore is defined for every *_ord_ore domain, and for text_search_ore. No ord_term is defined for an OrdOre domain. So PostgreSQL finds more than one candidate, and the call fails (EQL v4: ORDER BY eql_v4.ord_term(col) on an OrdOre column fails with "function is not unique" #1903).
  • Why a plain ORDER BY is wrong. Every EQL type is CREATE DOMAIN ... AS jsonb (for example bigint_types.sql). So PostgreSQL sorts by jsonb order. The EQL test suites sort with the same expressions: tests/encryption/tests/v4_order.rs with ord_term, and v4_ore_block.rs with ord_term_ore. I did not run SQL against a database for this PR. The issue reports the wrong order as tested in a database.
  • Order indexes. I ran a throwaway test, not committed, that calls stashgen with the real embedded engine:
    • index=ore and index=ope on encrypt.Decimal, encrypt.Date, and time.Time are accepted. stashgen writes Lt, Lte, Gt, Gte, and Between for each.
    • index=ore and index=ope on []byte are refused: "the declared type has no such index".
    • encrypt_into=DateOrd, DateOrdOre, TimestampOrdOpe, and NumericOrdOre are accepted, with Lt, Lte, Gt, and Gte.
  • CGO_ENABLED=0 go test -timeout=25m ./encrypt/ ./stashgen/ ./cmd/stashgen/ passed, after I built the guests with mise.
  • go vet ./encrypt/ reported nothing. gofmt -l listed no files. golangci-lint run ./encrypt/ ./stashgen/ (2.14.0) reported 0 issues.
  • I ran the plain-language checker on the new text and fixed what it found. The README text follows the file's existing style, with no serial comma.

Related

Closes #1851
Closes #1855
Closes #1857

Refs #1903, the ord_term error on OrdOre columns. This PR documents the workaround and does not fix the error.

Review notes

  • I left cmd/stashgen/README.md unchanged. Its type table makes no ORDER BY claim. It already lists the order types for decimals, dates, and timestamps.
  • The Date, Timestamp, and Numeric ordered rows still list no = or <>, as before. Those operators are outside these issues, so I did not check them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk

Summary by CodeRabbit

  • Documentation
    • Clarified which sort expressions to use when ordering encrypted values, and noted that plain ORDER BY sorts stored JSON rather than the underlying values.
    • Expanded guidance for equality, ordering, and range queries on decimal and date values, including time.Time.
    • Clarified that byte fields do not support order indexes.

Each EQL type is a PostgreSQL domain over jsonb. So a plain ORDER BY col
sorts the stored JSON, and returns rows in the wrong order with no error.

The type table said ordered types support ORDER BY. It now gives the
expression that sorts correctly for each type:

- eql_v4.ord_term(col) for the Ord, OrdOpe, and TextSearch types.
- eql_v4.ord_term_ore(col) for the OrdOre and TextSearchOre types. On
  these, ord_term fails with "function is not unique".

The package documentation says the same.

The README said that a decimal, date, or timestamp field takes an equality
index only. stashgen accepts an ore or ope index on all three. It writes
the Lt, Lte, Gt, Gte, and Between methods for them. The type and query
tables now say so.

The package documentation said ORE and OPE apply to bytes. stashgen
refuses an order index on bytes, so that claim is removed.

Refs #1851
Refs #1855
Refs #1857

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
@auxesis auxesis added documentation Improvements or additions to documentation SDK Golang Pull requests that update Go code labels Nov 26, 2026
@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ebda37e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5447fdc8-c84f-440e-a19d-0c87cf0fa5ee

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The Go encryption documentation now describes order indexes for decimal, date, and timestamp fields, specifies SQL sorting expressions for ordered columns, and states that stashgen refuses order indexes on byte fields.

Changes: Go encryption documentation

Layer / File(s) Summary
Document order-index support
languages/golang/encrypt/README.md, languages/golang/CHANGELOG.md
The README and changelog list ore and ope indexes and ordering queries for encrypt.Decimal, encrypt.Date, and time.Time. The README describes the comparison precision for these types.
Document ordered-column sorting
languages/golang/encrypt/README.md, languages/golang/encrypt/doc.go, languages/golang/CHANGELOG.md
The documentation specifies eql_v4.ord_term or eql_v4.ord_term_ore for ordered columns and warns that plain ORDER BY col sorts the stored JSON.
Correct byte index documentation
languages/golang/encrypt/doc.go, languages/golang/CHANGELOG.md
The package documentation and changelog state that stashgen refuses order indexes on []byte fields.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other · Severity of issue fixed: Medium

Possibly related issues

Possibly related PRs

Suggested reviewers: coderdan

Merge Risk: Minimal · previous review ebda3

This documentation-only change corrects the sort expressions for ordered types, the index support for decimal, date and timestamp fields, and the bytes restriction. It has no runtime effect and is safe to merge. The author has not run SQL against a database for this PR, so the sort-expression guidance rests on the linked issue's report.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "docs(golang): give the sort expression for each ordered EQL type" matches the main change. The PR updates the Go SDK README and package docs to give the correct sort expression (ord_term or…
Linked Issues check Passed The linked issues are docs-only, but the changed package comments are Go source, so they count as coding requirements here. Evidence is the head revision of languages/golang/encrypt/doc.go. (1) [#1851…
Out of Scope Changes check Passed All changed files are documentation for the Go SDK: languages/golang/encrypt/README.md, languages/golang/encrypt/doc.go, and languages/golang/CHANGELOG.md. Each change maps to one of #1851, #1855 or #…
Full details: Title check

Explanation

The title "docs(golang): give the sort expression for each ordered EQL type" matches the main change. The PR updates the Go SDK README and package docs to give the correct sort expression (ord_term or ord_term_ore) for each ordered EQL type, and it adds a warning that plain ORDER BY sorts the stored JSON. The title is specific and concise, and it follows a conventional commit style.

Full details: Linked Issues check

Explanation

The linked issues are docs-only, but the changed package comments are Go source, so they count as coding requirements here. Evidence is the head revision of languages/golang/encrypt/doc.go. (1) [#1851] The doc comment gives the sort expression per type: Ord, OrdOpe and TextSearch use ORDER BY eql_v4.ord_term(col), and OrdOre and TextSearchOre use ORDER BY eql_v4.ord_term_ore(col). It warns that a plain ORDER BY col returns rows in the wrong order with no error. (2) [#1855] The ORE/OPE list in the Declarations section now covers decimals, dates and timestamps. The ordered-type list includes DateOrd, TimestampOrd and NumericOrd. (3) [#1857] The Declarations section says ORE and OPE apply to integers of 16 bits or more, floats, text, decimals, dates and timestamps. It states that stashgen refuses an order index on bytes. Bytes no longer appear in that list. The README table changes for #1851 and #1855 and the CHANGELOG entry were not readable with the tools available. Their content is taken from the PR description and the raw summary, not from direct inspection. The PR does not need to fix the database-level ord_term error (#1903); the PR documents it only.

Full details: Out of Scope Changes check

Explanation

All changed files are documentation for the Go SDK: languages/golang/encrypt/README.md, languages/golang/encrypt/doc.go, and languages/golang/CHANGELOG.md. Each change maps to one of #1851, #1855 or #1857. The doc.go hunks shown in the evidence (sort expressions, order-index type list, bytes removal) belong to those issues. The PR adds no code behavior changes, so no unrelated functional change is present. The README and CHANGELOG hunks were not directly read, so this verdict relies on the PR description and summary for those files.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bfdd0333-7890-421a-8896-67a1149467f3
Commits

Reviewing files that changed from the base of the PR and between 1885e92 and ebda37e.

Files selected for processing: 3

  • languages/golang/CHANGELOG.md
  • languages/golang/encrypt/README.md
  • languages/golang/encrypt/doc.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@auxesis

auxesis commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review attestation

Reviewed ebda37ed · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review standards agent · claude-opus-5-5; mattpocock-skills:code-review spec agent · claude-opus-5-5
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check

Findings (5): 5 minor — 5 inline, 0 below.

Checked and not posted: the raw Ope "ORDER BY" line (README.md:430) is correct for a raw bytea term column. Open questions for the author: state the ord_term/ord_term_ore rule once rather than in 20 rows, so a fix to #1903 is one edit; stashgen/enginetest lists fewer EQL types than the real engine (test-only). Issues #1851, #1855 and #1857 are met. No changeset is needed: the Go module releases outside Changesets.


Generated by Claude Code

Comment thread languages/golang/encrypt/README.md Resolved
Comment thread languages/golang/encrypt/README.md Resolved
Comment thread languages/golang/encrypt/README.md Resolved
Comment thread languages/golang/encrypt/doc.go Resolved
Comment thread languages/golang/encrypt/doc.go Resolved
Review found four gaps in the type docs.

- The README said an order index follows the equality rules. Those rules
  say an integer equals itself at every width. But each integer width has
  its own order term, so the sentence now covers decimals, dates, and
  timestamps only.
- The ordered Date, Timestamp, and Numeric rows left out = and <>. EQL v4
  defines both on those domains.
- The package docs left out the OrdOre types, TextSearch, and
  TextSearchOre, from both the Go field types and the operators. The Go
  field types are now a list by family.
- The paragraphs are wrapped again at the file's width.

Refs #1851
Refs #1855

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Golang Pull requests that update Go code SDK

Projects

None yet

2 participants