opensearch

package
v3.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package opensearch implements the OpenSearch SQL dialect for cel2sql.

OpenSearch SQL is the query language of the OpenSearch SQL plugin (POST _plugins/_sql). Its grammar is MySQL-flavoured, but it is a search engine, not a relational database: there are no array values, no JSON functions, no array-building subqueries and no user-managed indexes. Object fields are addressed by dot path (a.b.c) and nested fields are queried PartiQL-style, with EXISTS (SELECT * FROM parent.nested AS n WHERE …).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect struct{}

Dialect implements dialect.Dialect for OpenSearch SQL.

func New

func New() *Dialect

New creates a new OpenSearch SQL dialect.

func (*Dialect) ConvertRegex

func (d *Dialect) ConvertRegex(re2Pattern string) (string, bool, error)

ConvertRegex validates an RE2 pattern for use with REGEXP.

func (*Dialect) MaxIdentifierLength

func (d *Dialect) MaxIdentifierLength() int

MaxIdentifierLength returns 0: OpenSearch documents no identifier length limit.

func (*Dialect) Name

func (d *Dialect) Name() dialect.Name

Name returns the dialect name.

func (*Dialect) ReservedKeywords

func (d *Dialect) ReservedKeywords() map[string]bool

ReservedKeywords returns the set of reserved OpenSearch SQL keywords.

func (*Dialect) SupportsIndexAnalysis

func (d *Dialect) SupportsIndexAnalysis() bool

SupportsIndexAnalysis returns false: OpenSearch indexes every mapped field itself and has no user-managed SQL indexes.

func (*Dialect) SupportsJSONB

func (d *Dialect) SupportsJSONB() bool

SupportsJSONB returns false.

func (*Dialect) SupportsNativeArrays

func (d *Dialect) SupportsNativeArrays() bool

SupportsNativeArrays returns false: OpenSearch has multi-valued fields, not arrays.

func (*Dialect) SupportsRegex

func (d *Dialect) SupportsRegex() bool

SupportsRegex returns true: OpenSearch SQL has a REGEXP operator.

func (*Dialect) SupportsSubqueryExpressions

func (d *Dialect) SupportsSubqueryExpressions() bool

SupportsSubqueryExpressions returns false: the plugin only allows a subquery inside an EXISTS or IN predicate, never as a value.

func (*Dialect) ValidateFieldName

func (d *Dialect) ValidateFieldName(name string) error

ValidateFieldName validates a field name against OpenSearch SQL identifier rules.

func (*Dialect) WriteArrayLength

func (d *Dialect) WriteArrayLength(_ *strings.Builder, _ int, _ func() error) error

WriteArrayLength returns an error: OpenSearch SQL has no array length function.

func (*Dialect) WriteArrayLiteralClose

func (d *Dialect) WriteArrayLiteralClose(w *strings.Builder)

WriteArrayLiteralClose closes the value list.

func (*Dialect) WriteArrayLiteralOpen

func (d *Dialect) WriteArrayLiteralOpen(w *strings.Builder)

WriteArrayLiteralOpen opens a parenthesised value list, the only list form OpenSearch SQL has (as the right-hand side of IN).

func (*Dialect) WriteArrayMembership

func (d *Dialect) WriteArrayMembership(w *strings.Builder, writeElem func() error, writeArray func() error) error

WriteArrayMembership writes elem IN (v1, v2, …).

OpenSearch has no array values, so the only list a membership test can be written against is a literal one, which WriteArrayLiteralOpen/Close render as a parenthesised value list. Anything else that reaches here (a list variable, a nested field, a concatenation of two literals) has no OpenSearch SQL equivalent, so the array operand is checked after it is written and the expression is rejected when it is not a single parenthesised group.

func (*Dialect) WriteArraySubqueryExprClose

func (d *Dialect) WriteArraySubqueryExprClose(_ *strings.Builder)

WriteArraySubqueryExprClose is unreachable; see WriteArraySubqueryOpen.

func (*Dialect) WriteArraySubqueryOpen

func (d *Dialect) WriteArraySubqueryOpen(w *strings.Builder)

WriteArraySubqueryOpen is unreachable: SupportsSubqueryExpressions is false, so the converter rejects filter/map comprehensions before writing one.

func (*Dialect) WriteBooleanFieldPredicate

func (d *Dialect) WriteBooleanFieldPredicate(w *strings.Builder, writeField func() error) error

WriteBooleanFieldPredicate writes field = true. The SQL plugin silently ignores a bare boolean column used as a predicate (every document matches) and rejects NOT column, so the comparison is always spelled out.

func (*Dialect) WriteBytesLiteral

func (d *Dialect) WriteBytesLiteral(_ *strings.Builder, _ []byte) error

WriteBytesLiteral returns an error: OpenSearch SQL has no binary literal syntax.

func (*Dialect) WriteCastToNumeric

func (d *Dialect) WriteCastToNumeric(_ *strings.Builder)

WriteCastToNumeric writes nothing. The converter only requests this cast when comparing a value extracted from a JSON document; OpenSearch object sub-fields are typed by the index mapping, so no coercion is needed.

func (*Dialect) WriteComprehensionExists

func (d *Dialect) WriteComprehensionExists(w *strings.Builder, writeBody func() error) error

WriteComprehensionExists writes EXISTS (SELECT * FROM <body>), the form the plugin documents for nested fields and rewrites to a nested query.

func (*Dialect) WriteComprehensionNotExists

func (d *Dialect) WriteComprehensionNotExists(_ *strings.Builder, _ func() error) error

WriteComprehensionNotExists returns an error. NOT EXISTS itself is accepted, but the body of an all() comprehension is WHERE NOT (<predicate>) and the plugin's nested-query handler rejects NOT inside the subquery, so the form can never run.

func (*Dialect) WriteContains

func (d *Dialect) WriteContains(w *strings.Builder, writeHaystack, writeNeedle func() error) error

WriteContains writes LOCATE(needle, haystack) > 0.

func (*Dialect) WriteDuration

func (d *Dialect) WriteDuration(w *strings.Builder, value int64, unit string)

WriteDuration writes INTERVAL n UNIT. OpenSearch has no MILLISECOND unit, so millisecond durations are written in microseconds.

func (*Dialect) WriteEmptyTypedArray

func (d *Dialect) WriteEmptyTypedArray(w *strings.Builder, _ string)

WriteEmptyTypedArray writes (NULL): x IN (NULL) is never true, which matches membership in an empty list.

func (*Dialect) WriteEpochExtract

func (d *Dialect) WriteEpochExtract(w *strings.Builder, writeExpr func() error) error

WriteEpochExtract writes CAST(UNIX_TIMESTAMP(expr) AS LONG); the plugin's unix_timestamp returns a double.

func (*Dialect) WriteExtract

func (d *Dialect) WriteExtract(w *strings.Builder, part string, writeExpr func() error, writeTZ func() error) error

WriteExtract writes a date-part extraction.

DOW: OpenSearch's DAYOFWEEK is MySQL's (1=Sunday … 7=Saturday) and CEL's getDayOfWeek is ISO (0=Monday … 6=Sunday), so (DAYOFWEEK(x) + 5) % 7. DOY and MILLISECONDS have no EXTRACT part and use functions instead. Time zone conversion is rejected: the grammar has no AT TIME ZONE.

func (*Dialect) WriteInterval

func (d *Dialect) WriteInterval(w *strings.Builder, writeValue func() error, unit string) error

WriteInterval writes INTERVAL expr UNIT.

func (*Dialect) WriteIterVarRef

func (d *Dialect) WriteIterVarRef(w *strings.Builder, alias string) error

WriteIterVarRef writes the alias unchanged: `FROM parent.nested AS n` binds n to one nested document.

func (*Dialect) WriteJSONArrayElements

func (d *Dialect) WriteJSONArrayElements(_ *strings.Builder, _ bool, _ bool, writeExpr func() error) error

WriteJSONArrayElements writes the nested field itself: the comprehension source for a nested field is `parent.field AS alias`, the PartiQL form the plugin rewrites to a nested query.

func (*Dialect) WriteJSONArrayLength

func (d *Dialect) WriteJSONArrayLength(_ *strings.Builder, _ func() error) error

WriteJSONArrayLength returns an error: OpenSearch SQL has no array length function.

func (*Dialect) WriteJSONArrayMembership

func (d *Dialect) WriteJSONArrayMembership(_ *strings.Builder, _ string, _ func() error, _ func() error) error

WriteJSONArrayMembership returns an error. A multi-valued OpenSearch field is not an array to the SQL plugin: expressions over it only see the first value, so `elem IN field` cannot be expressed faithfully.

func (*Dialect) WriteJSONExistence

func (d *Dialect) WriteJSONExistence(w *strings.Builder, _ bool, fieldName string, writeBase func() error) error

WriteJSONExistence writes base.field IS NOT NULL. OpenSearch does not distinguish a missing field from one explicitly set to null.

func (*Dialect) WriteJSONExtractPath

func (d *Dialect) WriteJSONExtractPath(w *strings.Builder, pathSegments []string, writeRoot func() error) error

WriteJSONExtractPath writes root.seg1.seg2 IS NOT NULL.

func (*Dialect) WriteJSONFieldAccess

func (d *Dialect) WriteJSONFieldAccess(w *strings.Builder, writeBase func() error, fieldName string, _ bool) error

WriteJSONFieldAccess writes base.field: object and flat_object sub-fields are addressed by dot path in OpenSearch SQL, whether or not the access is the final step of the path.

func (*Dialect) WriteJoin

func (d *Dialect) WriteJoin(_ *strings.Builder, _, _ func() error) error

WriteJoin returns an error: OpenSearch SQL has no array values to join.

func (*Dialect) WriteLikeEscape

func (d *Dialect) WriteLikeEscape(_ *strings.Builder)

WriteLikeEscape writes nothing: the OpenSearch SQL grammar has no ESCAPE clause. LIKE patterns are translated to wildcard queries, which treat a backslash-prefixed % or _ literally.

func (*Dialect) WriteListIndex

func (d *Dialect) WriteListIndex(_ *strings.Builder, _ func() error, _ func() error) error

WriteListIndex returns an error: OpenSearch SQL has no array indexing.

func (*Dialect) WriteListIndexConst

func (d *Dialect) WriteListIndexConst(_ *strings.Builder, _ func() error, _ int64) error

WriteListIndexConst returns an error: OpenSearch SQL has no array indexing.

func (*Dialect) WriteNestedJSONArrayMembership

func (d *Dialect) WriteNestedJSONArrayMembership(_ *strings.Builder, _ func() error, _ func() error) error

WriteNestedJSONArrayMembership returns an error for the same reason as WriteJSONArrayMembership.

func (*Dialect) WriteParamPlaceholder

func (d *Dialect) WriteParamPlaceholder(w *strings.Builder, _ int)

WriteParamPlaceholder writes an OpenSearch SQL positional parameter (?), bound through the request's "parameters" array or a JDBC PreparedStatement.

func (*Dialect) WriteRegexMatch

func (d *Dialect) WriteRegexMatch(w *strings.Builder, writeTarget func() error, pattern string, _ bool) error

WriteRegexMatch writes (target REGEXP 'pattern') = 1. The plugin's REGEXP returns an integer, not a boolean, so a bare REGEXP in WHERE fails with "wrong result type instead of boolean"; the comparison makes it a predicate. The pattern keeps any inline (?i) flag, which the Java regex engine honours, so caseInsensitive is ignored.

func (*Dialect) WriteSplit

func (d *Dialect) WriteSplit(_ *strings.Builder, _, _ func() error) error

WriteSplit returns an error: OpenSearch SQL has no array values to split into.

func (*Dialect) WriteSplitWithLimit

func (d *Dialect) WriteSplitWithLimit(_ *strings.Builder, _, _ func() error, _ int64) error

WriteSplitWithLimit returns an error: OpenSearch SQL has no array values to split into.

func (*Dialect) WriteStringConcat

func (d *Dialect) WriteStringConcat(w *strings.Builder, writeLHS, writeRHS func() error) error

WriteStringConcat writes string concatenation using the two-argument CONCAT().

func (*Dialect) WriteStringLiteral

func (d *Dialect) WriteStringLiteral(w *strings.Builder, value string)

WriteStringLiteral writes an OpenSearch SQL string literal with ” escaping.

func (*Dialect) WriteStructClose

func (d *Dialect) WriteStructClose(w *strings.Builder)

WriteStructClose writes the closing of a struct literal.

func (*Dialect) WriteStructOpen

func (d *Dialect) WriteStructOpen(w *strings.Builder)

WriteStructOpen writes the opening of a struct literal. OpenSearch SQL has no struct constructor; this is only reached by unreachable map/filter output.

func (*Dialect) WriteTimestampArithmetic

func (d *Dialect) WriteTimestampArithmetic(w *strings.Builder, op string, writeTS, writeDur func() error) error

WriteTimestampArithmetic writes DATE_ADD(ts, interval) or DATE_SUB(ts, interval).

func (*Dialect) WriteTimestampCast

func (d *Dialect) WriteTimestampCast(w *strings.Builder, writeExpr func() error) error

WriteTimestampCast writes CAST(expr AS TIMESTAMP).

func (*Dialect) WriteTypeName

func (d *Dialect) WriteTypeName(w *strings.Builder, celTypeName string)

WriteTypeName writes an OpenSearch SQL type name for CAST expressions.

func (*Dialect) WriteUnnest

func (d *Dialect) WriteUnnest(_ *strings.Builder, writeSource func() error) error

WriteUnnest writes the source expression bare: a nested field is iterated as `parent.field AS alias` with no table function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL