Skip to content

Commit

Permalink
Support VECTOR_SEARCH() function in BigQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Feb 7, 2024
1 parent 69cea94 commit 4022329
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ table_clause
});
}

// Used in cases where we only want to allow TABLE statement, not just any SELECT statement.
// Like in BigQuery VECTOR_SEARCH() function.
table_stmt
= tableCls:table_clause {
return loc({
type: "select_stmt",
clauses: [tableCls],
});
}

/**
* SELECT .. WITH
* --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -6409,14 +6419,17 @@ func_args_list
}

// For aggregate functions, first argument can be "*"
// The table_stmt is included because of BigQuery VECTOR_SEARCH() function
func_1st_arg
= star
= &bigquery x:table_stmt { return x; }
/ star
/ named_arg
/ expr
/ compound_select_stmt

func_arg
= named_arg
= &bigquery x:table_stmt { return x; }
/ named_arg
/ expr

named_arg
Expand Down
10 changes: 10 additions & 0 deletions test/expr/func_call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,15 @@ describe("function call", () => {
it("supports GROUPING() function", () => {
testExpr(`GROUPING(product_name)`);
});

it("supports VECTOR_SEARCH() function", () => {
testExpr(`VECTOR_SEARCH(
TABLE mydataset.table1,
'my_embedding',
TABLE mydataset.table2,
'embedding',
top_k => 2
)`);
});
});
});

0 comments on commit 4022329

Please sign in to comment.