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 ¶
- type Dialect
- func (d *Dialect) ConvertRegex(re2Pattern string) (string, bool, error)
- func (d *Dialect) MaxIdentifierLength() int
- func (d *Dialect) Name() dialect.Name
- func (d *Dialect) ReservedKeywords() map[string]bool
- func (d *Dialect) SupportsIndexAnalysis() bool
- func (d *Dialect) SupportsJSONB() bool
- func (d *Dialect) SupportsNativeArrays() bool
- func (d *Dialect) SupportsRegex() bool
- func (d *Dialect) SupportsSubqueryExpressions() bool
- func (d *Dialect) ValidateFieldName(name string) error
- func (d *Dialect) WriteArrayLength(_ *strings.Builder, _ int, _ func() error) error
- func (d *Dialect) WriteArrayLiteralClose(w *strings.Builder)
- func (d *Dialect) WriteArrayLiteralOpen(w *strings.Builder)
- func (d *Dialect) WriteArrayMembership(w *strings.Builder, writeElem func() error, writeArray func() error) error
- func (d *Dialect) WriteArraySubqueryExprClose(_ *strings.Builder)
- func (d *Dialect) WriteArraySubqueryOpen(w *strings.Builder)
- func (d *Dialect) WriteBooleanFieldPredicate(w *strings.Builder, writeField func() error) error
- func (d *Dialect) WriteBytesLiteral(_ *strings.Builder, _ []byte) error
- func (d *Dialect) WriteCastToNumeric(_ *strings.Builder)
- func (d *Dialect) WriteComprehensionExists(w *strings.Builder, writeBody func() error) error
- func (d *Dialect) WriteComprehensionNotExists(_ *strings.Builder, _ func() error) error
- func (d *Dialect) WriteContains(w *strings.Builder, writeHaystack, writeNeedle func() error) error
- func (d *Dialect) WriteDuration(w *strings.Builder, value int64, unit string)
- func (d *Dialect) WriteEmptyTypedArray(w *strings.Builder, _ string)
- func (d *Dialect) WriteEpochExtract(w *strings.Builder, writeExpr func() error) error
- func (d *Dialect) WriteExtract(w *strings.Builder, part string, writeExpr func() error, writeTZ func() error) error
- func (d *Dialect) WriteInterval(w *strings.Builder, writeValue func() error, unit string) error
- func (d *Dialect) WriteIterVarRef(w *strings.Builder, alias string) error
- func (d *Dialect) WriteJSONArrayElements(_ *strings.Builder, _ bool, _ bool, writeExpr func() error) error
- func (d *Dialect) WriteJSONArrayLength(_ *strings.Builder, _ func() error) error
- func (d *Dialect) WriteJSONArrayMembership(_ *strings.Builder, _ string, _ func() error, _ func() error) error
- func (d *Dialect) WriteJSONExistence(w *strings.Builder, _ bool, fieldName string, writeBase func() error) error
- func (d *Dialect) WriteJSONExtractPath(w *strings.Builder, pathSegments []string, writeRoot func() error) error
- func (d *Dialect) WriteJSONFieldAccess(w *strings.Builder, writeBase func() error, fieldName string, _ bool) error
- func (d *Dialect) WriteJoin(_ *strings.Builder, _, _ func() error) error
- func (d *Dialect) WriteLikeEscape(_ *strings.Builder)
- func (d *Dialect) WriteListIndex(_ *strings.Builder, _ func() error, _ func() error) error
- func (d *Dialect) WriteListIndexConst(_ *strings.Builder, _ func() error, _ int64) error
- func (d *Dialect) WriteNestedJSONArrayMembership(_ *strings.Builder, _ func() error, _ func() error) error
- func (d *Dialect) WriteParamPlaceholder(w *strings.Builder, _ int)
- func (d *Dialect) WriteRegexMatch(w *strings.Builder, writeTarget func() error, pattern string, _ bool) error
- func (d *Dialect) WriteSplit(_ *strings.Builder, _, _ func() error) error
- func (d *Dialect) WriteSplitWithLimit(_ *strings.Builder, _, _ func() error, _ int64) error
- func (d *Dialect) WriteStringConcat(w *strings.Builder, writeLHS, writeRHS func() error) error
- func (d *Dialect) WriteStringLiteral(w *strings.Builder, value string)
- func (d *Dialect) WriteStructClose(w *strings.Builder)
- func (d *Dialect) WriteStructOpen(w *strings.Builder)
- func (d *Dialect) WriteTimestampArithmetic(w *strings.Builder, op string, writeTS, writeDur func() error) error
- func (d *Dialect) WriteTimestampCast(w *strings.Builder, writeExpr func() error) error
- func (d *Dialect) WriteTypeName(w *strings.Builder, celTypeName string)
- func (d *Dialect) WriteUnnest(_ *strings.Builder, writeSource func() error) error
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 (*Dialect) ConvertRegex ¶
ConvertRegex validates an RE2 pattern for use with REGEXP.
func (*Dialect) MaxIdentifierLength ¶
MaxIdentifierLength returns 0: OpenSearch documents no identifier length limit.
func (*Dialect) ReservedKeywords ¶
ReservedKeywords returns the set of reserved OpenSearch SQL keywords.
func (*Dialect) SupportsIndexAnalysis ¶
SupportsIndexAnalysis returns false: OpenSearch indexes every mapped field itself and has no user-managed SQL indexes.
func (*Dialect) SupportsNativeArrays ¶
SupportsNativeArrays returns false: OpenSearch has multi-valued fields, not arrays.
func (*Dialect) SupportsRegex ¶
SupportsRegex returns true: OpenSearch SQL has a REGEXP operator.
func (*Dialect) SupportsSubqueryExpressions ¶
SupportsSubqueryExpressions returns false: the plugin only allows a subquery inside an EXISTS or IN predicate, never as a value.
func (*Dialect) ValidateFieldName ¶
ValidateFieldName validates a field name against OpenSearch SQL identifier rules.
func (*Dialect) WriteArrayLength ¶
WriteArrayLength returns an error: OpenSearch SQL has no array length function.
func (*Dialect) WriteArrayLiteralClose ¶
WriteArrayLiteralClose closes the value list.
func (*Dialect) WriteArrayLiteralOpen ¶
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 ¶
WriteArraySubqueryExprClose is unreachable; see WriteArraySubqueryOpen.
func (*Dialect) WriteArraySubqueryOpen ¶
WriteArraySubqueryOpen is unreachable: SupportsSubqueryExpressions is false, so the converter rejects filter/map comprehensions before writing one.
func (*Dialect) WriteBooleanFieldPredicate ¶
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 ¶
WriteBytesLiteral returns an error: OpenSearch SQL has no binary literal syntax.
func (*Dialect) WriteCastToNumeric ¶
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 ¶
WriteComprehensionExists writes EXISTS (SELECT * FROM <body>), the form the plugin documents for nested fields and rewrites to a nested query.
func (*Dialect) WriteComprehensionNotExists ¶
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 ¶
WriteContains writes LOCATE(needle, haystack) > 0.
func (*Dialect) WriteDuration ¶
WriteDuration writes INTERVAL n UNIT. OpenSearch has no MILLISECOND unit, so millisecond durations are written in microseconds.
func (*Dialect) WriteEmptyTypedArray ¶
WriteEmptyTypedArray writes (NULL): x IN (NULL) is never true, which matches membership in an empty list.
func (*Dialect) WriteEpochExtract ¶
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 ¶
WriteInterval writes INTERVAL expr UNIT.
func (*Dialect) WriteIterVarRef ¶
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 ¶
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) WriteLikeEscape ¶
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 ¶
WriteListIndex returns an error: OpenSearch SQL has no array indexing.
func (*Dialect) WriteListIndexConst ¶
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 ¶
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 ¶
WriteSplit returns an error: OpenSearch SQL has no array values to split into.
func (*Dialect) WriteSplitWithLimit ¶
WriteSplitWithLimit returns an error: OpenSearch SQL has no array values to split into.
func (*Dialect) WriteStringConcat ¶
WriteStringConcat writes string concatenation using the two-argument CONCAT().
func (*Dialect) WriteStringLiteral ¶
WriteStringLiteral writes an OpenSearch SQL string literal with ” escaping.
func (*Dialect) WriteStructClose ¶
WriteStructClose writes the closing of a struct literal.
func (*Dialect) WriteStructOpen ¶
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 ¶
WriteTimestampCast writes CAST(expr AS TIMESTAMP).
func (*Dialect) WriteTypeName ¶
WriteTypeName writes an OpenSearch SQL type name for CAST expressions.