-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(bigquery): add typed handling for AI scalar functions #7479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,6 +321,24 @@ class AIClassify(Expression, Func): | |
| _sql_names = ["AI_CLASSIFY"] | ||
|
|
||
|
|
||
| class AIEmbed(Expression, Func): | ||
| arg_types = {"expressions": False} | ||
| is_var_len_args = True | ||
| _sql_names = ["EMBED"] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you add |
||
|
|
||
|
|
||
| class AISimilarity(Expression, Func): | ||
| arg_types = {"expressions": False} | ||
| is_var_len_args = True | ||
| _sql_names = ["SIMILARITY"] | ||
|
|
||
|
|
||
| class AIGenerate(Expression, Func): | ||
| arg_types = {"expressions": False} | ||
| is_var_len_args = True | ||
| _sql_names = ["GENERATE"] | ||
|
|
||
|
|
||
| class FeaturesAtTime(Expression, Func): | ||
| arg_types = {"this": True, "time": False, "num_rows": False, "ignore_feature_nulls": False} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -730,6 +730,16 @@ def _parse_column_ops(self, this: exp.Expr | None) -> exp.Expr | None: | |
| self._retreat(func_index) | ||
| parsed = self._parse_function(any_token=True) | ||
| if parsed: | ||
| if prefix == "AI" and isinstance(parsed, exp.Anonymous): | ||
| ai_scalars: dict[str, type[exp.Func]] = { | ||
| "EMBED": exp.AIEmbed, | ||
| "SIMILARITY": exp.AISimilarity, | ||
| "GENERATE": exp.AIGenerate, | ||
| } | ||
|
Comment on lines
+734
to
+738
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary if you have proper function parsers (e.g., using As a side-note, we generally don't define constants like this mapping inline, but instead "bubble them up" in the parser class. |
||
| expr_type = ai_scalars.get(parsed.name.upper()) | ||
| if expr_type: | ||
| parsed = expr_type(expressions=parsed.expressions) | ||
|
|
||
| this = self.expression(exp.Dot(this=this.this, expression=parsed)) | ||
|
|
||
| return this | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should increase the test coverage a bit by including more AI.EMBED(
[ content => ] 'content',
{ endpoint => 'endpoint' | model => 'model' }
[, task_type => 'task_type']
[, title => 'title']
[, model_params => model_params]
[, connection_id => 'connection']
)ideally, we want some representative tests with more arguments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be
True, as at least one argument is expected. The same holds forAISimilarityandAIGenerate.