Skip to main content

@terascope/types / sql-interfaces / SQLDialect

Interface: SQLDialect

Defined in: packages/types/src/sql-interfaces.ts:168

The SQL that differs between engines.

The translator walks the xLucene AST; a dialect only renders the leaves and combines them with AND, OR and NOT. A caller can override one method without changing the translator.

Every predicate returned must be safe to embed in a larger expression, so anything with operator precedence is returned in parentheses.

Properties​

PropertyModifierTypeDefined in
namereadonlystringpackages/types/src/sql-interfaces.ts:169

Methods​

and()​

and(expressions): string

Defined in: packages/types/src/sql-interfaces.ts:258

All of the expressions.

Parameters​

ParameterType
expressionsstring[]

Returns​

string


compare()​

compare(fieldExpr, operator, value, fieldType?): string

Defined in: packages/types/src/sql-interfaces.ts:230

One side of a range.

Parameters​

ParameterType
fieldExprstring
operator"gte" | "gt" | "lt" | "lte"
valueunknown
fieldType?xLuceneFieldType

Returns​

string


equals()​

equals(fieldExpr, value, fieldType?): string

Defined in: packages/types/src/sql-interfaces.ts:227

Equality against a single value.

Parameters​

ParameterType
fieldExprstring
valueunknown
fieldType?xLuceneFieldType

Returns​

string


exists()​

exists(fieldExpr): string

Defined in: packages/types/src/sql-interfaces.ts:244

The field has a value.

Parameters​

ParameterType
fieldExprstring

Returns​

string


fieldRef()​

fieldRef(field): string

Defined in: packages/types/src/sql-interfaces.ts:180

The column expression for an xLucene field path.

A dotted field can be a column named a.b or member b of a struct column a, depending on how the engine stores nested data, so each dialect decides.

Parameters​

ParameterType
fieldstring

Returns​

string


geoContainsPoint()​

geoContainsPoint(fieldExpr, point, isPointColumn): string

Defined in: packages/types/src/sql-interfaces.ts:308

A geo shape field that contains a point.

Parameters​

ParameterType
fieldExprstring
pointGeoPoint
isPointColumnboolean

Returns​

string


geoPointDistance()​

geoPointDistance(fieldExpr, point): string

Defined in: packages/types/src/sql-interfaces.ts:287

The distance in meters from a geo-point field to a point, for sorting.

Parameters​

ParameterType
fieldExprstring
pointGeoPoint

Returns​

string


geoPointInBoundingBox()​

geoPointInBoundingBox(fieldExpr, topLeft, bottomRight): string

Defined in: packages/types/src/sql-interfaces.ts:290

A geo-point field inside an axis-aligned bounding box.

Parameters​

ParameterType
fieldExprstring
topLeftGeoPoint
bottomRightGeoPoint

Returns​

string


geoPointParts()​

geoPointParts(fieldExpr): SQLGeoPointColumn

Defined in: packages/types/src/sql-interfaces.ts:189

The lat and lon members of a geo-point column.

Parameters​

ParameterType
fieldExprstring

Returns​

SQLGeoPointColumn


geoPointWithinDistance()​

geoPointWithinDistance(fieldExpr, point, meters): string

Defined in: packages/types/src/sql-interfaces.ts:282

A geo-point field within distance meters of a point.

Parameters​

ParameterType
fieldExprstring
pointGeoPoint
metersnumber

Returns​

string


geoRelation()​

geoRelation(fieldExpr, shape, relation, isPointColumn): string

Defined in: packages/types/src/sql-interfaces.ts:300

A geo field related to a shape.

isPointColumn says whether the field holds a point or a shape, which decides how the column becomes a geometry.

Parameters​

ParameterType
fieldExprstring
shapeGeoShape
relationGeoShapeRelation
isPointColumnboolean

Returns​

string


ipEquals()​

ipEquals(fieldExpr, address): string

Defined in: packages/types/src/sql-interfaces.ts:267

An ip field equal to a single address, compared as addresses rather than as text.

Parameters​

ParameterType
fieldExprstring
addressstring

Returns​

string


ipInCIDR()​

ipInCIDR(fieldExpr, cidr): string

Defined in: packages/types/src/sql-interfaces.ts:264

An IP or CIDR value contained by the CIDR block of an ip field.

Parameters​

ParameterType
fieldExprstring
cidrstring

Returns​

string


ipRangeContains()​

ipRangeContains(fieldExpr, value): string

Defined in: packages/types/src/sql-interfaces.ts:270

An ip_range field whose stored block contains the address or block.

Parameters​

ParameterType
fieldExprstring
valuestring

Returns​

string


ipRangeIntersects()​

ipRangeIntersects(fieldExpr, start?, end?): string

Defined in: packages/types/src/sql-interfaces.ts:277

An ip_range field whose stored block overlaps the queried address range.

Either bound may be absent, meaning unbounded on that side.

Parameters​

ParameterType
fieldExprstring
start?SQLIPRangeBound
end?SQLIPRangeBound

Returns​

string


limitOffset()​

limitOffset(size?, offset?): string

Defined in: packages/types/src/sql-interfaces.ts:209

The row-limiting clause, or an empty string when neither bound is set.

DuckDB and PostgreSQL both use LIMIT n OFFSET m, but other engines use OFFSET … FETCH, so this is part of the dialect.

Parameters​

ParameterType
size?number
offset?number

Returns​

string


literal()​

literal(value, fieldType?): string

Defined in: packages/types/src/sql-interfaces.ts:186

A value rendered as a literal of the given xLucene field type.

Parameters​

ParameterType
valueunknown
fieldType?xLuceneFieldType

Returns​

string


matchAll()​

matchAll(): string

Defined in: packages/types/src/sql-interfaces.ts:221

TRUE - an empty query matches everything.

Returns​

string


matchNone()​

matchNone(): string

Defined in: packages/types/src/sql-interfaces.ts:224

FALSE - a query that cannot match anything.

Returns​

string


not()​

not(expression): string

Defined in: packages/types/src/sql-interfaces.ts:255

Negation.

Not a bare NOT: Elasticsearch's must_not matches a document whose field is missing, but SQL drops a row whose predicate is NULL, so a NULL result must become TRUE.

Parameters​

ParameterType
expressionstring

Returns​

string


or()​

or(expressions): string

Defined in: packages/types/src/sql-interfaces.ts:261

Any of the expressions.

Parameters​

ParameterType
expressionsstring[]

Returns​

string


orderBy()​

orderBy(sort?): string

Defined in: packages/types/src/sql-interfaces.ts:218

The ORDER BY terms, without the keyword, or '' for no ordering.

Direction and null placement are always written, because engine defaults for null placement differ and none match DataFrame. An engine without NULLS FIRST/NULLS LAST syntax can override this.

Parameters​

ParameterType
sort?readonly SQLSort[]

Returns​

string


projection()​

projection(readable, all): string

Defined in: packages/types/src/sql-interfaces.ts:201

The SELECT list for the readable fields.

This is where field restrictions are enforced, the SQL equivalent of Elasticsearch's _source_excludes.

readable is the field paths that may be returned, and all is every path the type config declares; both are needed to tell a fully readable column from a partly readable one. An empty readable still returns rows, but with no data.

Parameters​

ParameterType
readablereadonly string[]
allreadonly string[]

Returns​

string


quoteIdentifier()​

quoteIdentifier(name): string

Defined in: packages/types/src/sql-interfaces.ts:172

Quote an identifier for use as a column reference.

Parameters​

ParameterType
namestring

Returns​

string


regexp()​

regexp(fieldExpr, value, fieldType?): string

Defined in: packages/types/src/sql-interfaces.ts:241

An anchored regular expression match, as the Elasticsearch regexp query is.

Parameters​

ParameterType
fieldExprstring
valuestring
fieldType?xLuceneFieldType

Returns​

string


stringLiteral()​

stringLiteral(value): string

Defined in: packages/types/src/sql-interfaces.ts:183

A SQL string literal, escaped for this engine.

Parameters​

ParameterType
valuestring

Returns​

string


toText()​

toText(fieldExpr): string

Defined in: packages/types/src/sql-interfaces.ts:247

The value cast to text, for a query with no field.

Parameters​

ParameterType
fieldExprstring

Returns​

string


wildcard()​

wildcard(fieldExpr, value, fieldType?): string

Defined in: packages/types/src/sql-interfaces.ts:238

A wildcard match, given an xLucene wildcard value (* and ?).

Parameters​

ParameterType
fieldExprstring
valuestring
fieldType?xLuceneFieldType

Returns​

string