Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/mosaic/sql/src/ast/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ export function isNode(value: unknown): value is SQLNode {
export class SQLNode {
/** The SQL AST node type. */
readonly type: string;
/** The SQL dialect. */
readonly dialect: string;

/**
* Instantiate a SQL AST node.
* @param type The SQL AST node type.
* @param dialect The SQL dialect (defaults to "duckdb").
*/
constructor(type: string) {
constructor(type: string, dialect: string = "duckdb") {
this.type = type;
this.dialect = dialect;
}

/**
Expand Down
33 changes: 30 additions & 3 deletions packages/mosaic/sql/src/functions/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@
list1: ExprValue | ExprValue[],
element: ExprValue,
) {
return fn("list_contains", asList(list1), asLiteral(element));
switch (this.dialect) {

Check failure on line 36 in packages/mosaic/sql/src/functions/list.ts

View workflow job for this annotation

GitHub Actions / Test in Node

'this' implicitly has type 'any' because it does not have a type annotation.
case "clickhouse":
return fn("has", asList(list1), asLiteral(element));
case "starrocks":
return fn("array_contains", asList(list1), asLiteral(element));
case "bigquery":
return "element IN UNNEST(list1)";
default:
return fn("list_contains", asList(list1), asLiteral(element));
}
}

/**
Expand All @@ -46,7 +55,16 @@
list1: ExprValue | ExprValue[],
list2: ExprValue | ExprValue[],
) {
return fn("list_has_all", asList(list1), asList(list2));
switch (this.dialect) {

Check failure on line 58 in packages/mosaic/sql/src/functions/list.ts

View workflow job for this annotation

GitHub Actions / Test in Node

'this' implicitly has type 'any' because it does not have a type annotation.
case "clickhouse":
return fn("hasAll", asList(list1), asList(list2));
case "starrocks":
return fn("array_contains_all", asList(list1), asList(list2));
case "bigquery":
return "(SELECT COUNT(l2) = ARRAY_LENGTH(list2) FROM UNNEST(list1) AS l1 JOIN UNNEST(list1) AS l2 ON l1 = l2)";
default:
return fn("list_has_all", asList(list1), asList(list2));
}
}

/**
Expand All @@ -59,5 +77,14 @@
list1: ExprValue | ExprValue[],
list2: ExprValue | ExprValue[],
) {
return fn("list_has_any", asList(list1), asList(list2));
switch (this.dialect) {

Check failure on line 80 in packages/mosaic/sql/src/functions/list.ts

View workflow job for this annotation

GitHub Actions / Test in Node

'this' implicitly has type 'any' because it does not have a type annotation.
case "clickhouse":
return fn("hasAny", asList(list1), asList(list2));
case "starrocks":
return fn("arrays_overlap", asList(list1), asList(list2));
case "bigquery":
return "EXISTS(SELECT * FROM UNNEST(list1) AS l1 WHERE l1 IN UNNEST(list2))";
default:
return fn("list_has_any", asList(list1), asList(list2));
}
}
Loading