Documentation
¶
Overview ¶
Package spark implements the Apache Spark SQL dialect for cel2sql.
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) ValidateFieldName(name string) error
- func (d *Dialect) WriteArrayLength(w *strings.Builder, dimension int, writeExpr 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, writeArray func() error) error
- func (d *Dialect) WriteArraySubqueryExprClose(w *strings.Builder)
- func (d *Dialect) WriteArraySubqueryOpen(w *strings.Builder)
- func (d *Dialect) WriteBytesLiteral(w *strings.Builder, value []byte) error
- func (d *Dialect) WriteCastToNumeric(w *strings.Builder)
- 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, typeName 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) WriteJSONArrayElements(w *strings.Builder, _, _ bool, writeExpr func() error) error
- func (d *Dialect) WriteJSONArrayLength(w *strings.Builder, writeExpr func() error) error
- func (d *Dialect) WriteJSONArrayMembership(w *strings.Builder, _ string, writeExpr 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(w *strings.Builder, writeArray, writeDelim func() error) error
- func (d *Dialect) WriteLikeEscape(w *strings.Builder)
- func (d *Dialect) WriteListIndex(w *strings.Builder, writeArray, writeIndex func() error) error
- func (d *Dialect) WriteListIndexConst(w *strings.Builder, writeArray func() error, index int64) error
- func (d *Dialect) WriteNestedJSONArrayMembership(w *strings.Builder, writeExpr 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(w *strings.Builder, writeStr, writeDelim func() error) error
- func (d *Dialect) WriteSplitWithLimit(w *strings.Builder, writeStr, writeDelim func() error, limit 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(w *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 Apache Spark SQL.
func (*Dialect) ConvertRegex ¶
ConvertRegex converts an RE2 regex pattern to Spark/Java regex format. Spark uses java.util.regex.Pattern, which is largely a superset of RE2 for the safe patterns cel2sql accepts.
func (*Dialect) MaxIdentifierLength ¶
MaxIdentifierLength returns 128 for Spark (Hive-derived limit).
func (*Dialect) ReservedKeywords ¶
ReservedKeywords returns the set of reserved SQL keywords for Spark.
func (*Dialect) SupportsIndexAnalysis ¶
SupportsIndexAnalysis returns false. Spark indexing is highly storage-layer-specific (Delta Z-order vs Iceberg sort vs plain Parquet) and out of scope for v1.
func (*Dialect) SupportsJSONB ¶
SupportsJSONB returns false as Spark has no separate JSONB type.
func (*Dialect) SupportsNativeArrays ¶
SupportsNativeArrays returns true as Spark has native ARRAY<T> types.
func (*Dialect) SupportsRegex ¶
SupportsRegex returns true as Spark supports regex via RLIKE.
func (*Dialect) ValidateFieldName ¶
ValidateFieldName validates a field name against Spark naming rules.
func (*Dialect) WriteArrayLength ¶
WriteArrayLength writes COALESCE(size(expr), 0) for Spark. Spark's size() returns -1 for null; COALESCE+ifnull-style handling matches cel2sql semantics where size(null) should be 0.
func (*Dialect) WriteArrayLiteralClose ¶
WriteArrayLiteralClose writes the Spark array literal closing.
func (*Dialect) WriteArrayLiteralOpen ¶
WriteArrayLiteralOpen writes the Spark array literal opening (array().
func (*Dialect) WriteArrayMembership ¶
func (d *Dialect) WriteArrayMembership(w *strings.Builder, writeElem, writeArray func() error) error
WriteArrayMembership writes a Spark array membership test using array_contains().
func (*Dialect) WriteArraySubqueryExprClose ¶
WriteArraySubqueryExprClose closes the collect_list() argument list.
func (*Dialect) WriteArraySubqueryOpen ¶
WriteArraySubqueryOpen writes the Spark array-building subquery prefix. Spark has no ARRAY(SELECT ...) constructor; collect_list() inside a subquery is the closest equivalent.
func (*Dialect) WriteBytesLiteral ¶
WriteBytesLiteral writes a Spark SQL byte literal as X'HEX'.
func (*Dialect) WriteCastToNumeric ¶
WriteCastToNumeric writes a Spark numeric coercion suffix. Spark does not support PostgreSQL-style `::TYPE` postfix casts, so we use the arithmetic coercion `+ 0` (same convention MySQL and SQLite use): `'5' + 0` evaluates as a number in Spark, ensuring JSON text extractions are compared numerically rather than lexicographically.
func (*Dialect) WriteContains ¶
WriteContains writes Spark string contains using LOCATE() > 0. LOCATE(substr, str) returns 1-based position or 0 when not found.
func (*Dialect) WriteDuration ¶
WriteDuration writes a Spark INTERVAL literal.
func (*Dialect) WriteEmptyTypedArray ¶
WriteEmptyTypedArray writes an empty Spark typed array.
func (*Dialect) WriteEpochExtract ¶
WriteEpochExtract writes UNIX_TIMESTAMP(expr) for Spark.
func (*Dialect) WriteExtract ¶
func (d *Dialect) WriteExtract(w *strings.Builder, part string, writeExpr func() error, writeTZ func() error) error
WriteExtract writes a Spark EXTRACT expression. Spark dayofweek() returns 1=Sunday..7=Saturday; CEL convention is 0=Sunday..6=Saturday.
func (*Dialect) WriteInterval ¶
WriteInterval writes a Spark INTERVAL expression.
func (*Dialect) WriteJSONArrayElements ¶
func (d *Dialect) WriteJSONArrayElements(w *strings.Builder, _, _ bool, writeExpr func() error) error
WriteJSONArrayElements writes Spark JSON array expansion as EXPLODE(from_json(...)). The converter uses this in `FROM <here> AS iter`, so the result must be a set-returning expression. EXPLODE turns the parsed array into a relation of element rows. Element type is fixed to STRING in v1; comparisons coerce via arithmetic context (see WriteCastToNumeric).
func (*Dialect) WriteJSONArrayLength ¶
WriteJSONArrayLength writes COALESCE(size(from_json(expr, 'ARRAY<STRING>')), 0) for Spark.
func (*Dialect) WriteJSONArrayMembership ¶
func (d *Dialect) WriteJSONArrayMembership(w *strings.Builder, _ string, writeExpr func() error) error
WriteJSONArrayMembership writes Spark JSON array membership as a scalar subquery that scans elements. The converter writes `lhs = ` before this, so the result is `lhs = (SELECT col FROM (SELECT EXPLODE(from_json(rhs, 'ARRAY<STRING>')) AS col) t)`. This mirrors SQLite's `lhs = (SELECT value FROM json_each(...))` pattern; both dialects rely on the subquery returning at most one match for the comparison to succeed.
func (*Dialect) WriteJSONExistence ¶
func (d *Dialect) WriteJSONExistence(w *strings.Builder, _ bool, fieldName string, writeBase func() error) error
WriteJSONExistence writes a Spark JSON key existence check.
func (*Dialect) WriteJSONExtractPath ¶
func (d *Dialect) WriteJSONExtractPath(w *strings.Builder, pathSegments []string, writeRoot func() error) error
WriteJSONExtractPath writes a Spark JSON path existence check using get_json_object.
func (*Dialect) WriteJSONFieldAccess ¶
func (d *Dialect) WriteJSONFieldAccess(w *strings.Builder, writeBase func() error, fieldName string, _ bool) error
WriteJSONFieldAccess writes Spark JSON field access using get_json_object. Spark's get_json_object always returns a string; the same function is used for both intermediate and final access (Spark has no JSON_QUERY equivalent).
func (*Dialect) WriteLikeEscape ¶
WriteLikeEscape writes the Spark SQL LIKE escape clause.
func (*Dialect) WriteListIndex ¶
WriteListIndex writes Spark 0-indexed array access.
func (*Dialect) WriteListIndexConst ¶
func (d *Dialect) WriteListIndexConst(w *strings.Builder, writeArray func() error, index int64) error
WriteListIndexConst writes a Spark constant array index (0-indexed).
func (*Dialect) WriteNestedJSONArrayMembership ¶
WriteNestedJSONArrayMembership writes Spark nested JSON array membership.
func (*Dialect) WriteParamPlaceholder ¶
WriteParamPlaceholder writes a Spark SQL positional parameter (?). The paramIndex argument is intentionally unused: Spark JDBC uses positional ? placeholders, so the converter relies on parameter order.
func (*Dialect) WriteRegexMatch ¶
func (d *Dialect) WriteRegexMatch(w *strings.Builder, writeTarget func() error, pattern string, _ bool) error
WriteRegexMatch writes a Spark SQL regex match using RLIKE. Spark regex uses Java pattern syntax; (?i) inline flag is supported, so caseInsensitive is folded into the pattern by ConvertRegex.
func (*Dialect) WriteSplit ¶
WriteSplit writes Spark string split using split().
func (*Dialect) WriteSplitWithLimit ¶
func (d *Dialect) WriteSplitWithLimit(w *strings.Builder, writeStr, writeDelim func() error, limit int64) error
WriteSplitWithLimit writes Spark string split with limit (3-arg split, Spark 3.x+).
func (*Dialect) WriteStringConcat ¶
WriteStringConcat writes Spark string concatenation using the concat() function. concat() works in all Spark versions; the || operator was added in 3.0+.
func (*Dialect) WriteStringLiteral ¶
WriteStringLiteral writes a Spark SQL string literal with ” escaping.
func (*Dialect) WriteStructClose ¶
WriteStructClose writes the Spark struct literal closing.
func (*Dialect) WriteStructOpen ¶
WriteStructOpen writes the Spark struct literal opening using struct().
func (*Dialect) WriteTimestampArithmetic ¶
func (d *Dialect) WriteTimestampArithmetic(w *strings.Builder, op string, writeTS, writeDur func() error) error
WriteTimestampArithmetic writes Spark timestamp arithmetic.
func (*Dialect) WriteTimestampCast ¶
WriteTimestampCast writes a Spark CAST to TIMESTAMP.
func (*Dialect) WriteTypeName ¶
WriteTypeName writes a Spark SQL type name for CAST expressions.
func (*Dialect) WriteUnnest ¶
WriteUnnest writes Spark explode-style unnesting via lateral view replacement. Note: cel2sql wraps this in an ARRAY-building subquery; Spark uses array higher-order functions (transform/filter/exists/forall) which don't need UNNEST. For the SELECT FROM UNNEST() pattern Spark requires a lateral view. We emit EXPLODE() and rely on the converter's subquery scaffolding.