codeant-ai-for-open-source[bot] commented on code in PR #41803: URL: https://github.com/apache/superset/pull/41803#discussion_r3531188827
########## superset/sql/dialects/trino.py: ########## @@ -0,0 +1,273 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import typing as t + +from sqlglot import exp +from sqlglot.dialects.trino import Trino as SqlglotTrino +from sqlglot.tokens import Token, TokenType + +# Keywords that open a block terminated by ``END`` in Trino SQL routines +# (https://trino.io/docs/current/udf/sql.html). ``CASE`` is included because +# both the ``CASE`` statement and the ``CASE`` expression are terminated by +# ``END``, so counting them keeps the depth balanced either way. +BLOCK_OPENERS = {"BEGIN", "CASE", "IF", "LOOP", "REPEAT", "WHILE"} Review Comment: **Suggestion:** Add an explicit type annotation for this module-level constant to satisfy the type-hinting rule for relevant variables. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This is a module-level variable with an inferable type (`set[str]`) that is not explicitly annotated. That matches the custom type-hint rule for relevant variables that can be annotated. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2cce5c31fe7042afbac0e400d369b218&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2cce5c31fe7042afbac0e400d369b218&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/sql/dialects/trino.py **Line:** 30:30 **Comment:** *Custom Rule: Add an explicit type annotation for this module-level constant to satisfy the type-hinting rule for relevant variables. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=a0a84544dffcd969a84ba72ea28203266e41447889d5930217fc069d24da80f3&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=a0a84544dffcd969a84ba72ea28203266e41447889d5930217fc069d24da80f3&reaction=dislike'>👎</a> ########## superset/sql/dialects/trino.py: ########## @@ -0,0 +1,273 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import typing as t + +from sqlglot import exp +from sqlglot.dialects.trino import Trino as SqlglotTrino +from sqlglot.tokens import Token, TokenType + +# Keywords that open a block terminated by ``END`` in Trino SQL routines +# (https://trino.io/docs/current/udf/sql.html). ``CASE`` is included because +# both the ``CASE`` statement and the ``CASE`` expression are terminated by +# ``END``, so counting them keeps the depth balanced either way. +BLOCK_OPENERS = {"BEGIN", "CASE", "IF", "LOOP", "REPEAT", "WHILE"} + +# Keywords that are also scalar functions in Trino (e.g. ``IF(a, b, c)`` and +# ``REPEAT('a', 3)``). When immediately followed by ``(`` they are function +# calls, not block openers. +AMBIGUOUS_OPENERS = {"IF", "REPEAT"} + +BODY_KEYWORDS = ("RETURN", "BEGIN") Review Comment: **Suggestion:** Add an explicit type annotation to this constant declaration to comply with the type-hint requirement. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This tuple constant is inferably `tuple[str, str]` but is not explicitly type hinted. The custom rule applies to relevant variables that can be annotated, so this is a real violation. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=dcbab12af0bd4281ab06a34f7aa27130&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=dcbab12af0bd4281ab06a34f7aa27130&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/sql/dialects/trino.py **Line:** 37:37 **Comment:** *Custom Rule: Add an explicit type annotation to this constant declaration to comply with the type-hint requirement. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=63203072e678d6849a8857919d71e2609950904ad9839cbcb041aa8c7e01a800&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=63203072e678d6849a8857919d71e2609950904ad9839cbcb041aa8c7e01a800&reaction=dislike'>👎</a> ########## superset/sql/dialects/trino.py: ########## @@ -0,0 +1,273 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import typing as t + +from sqlglot import exp +from sqlglot.dialects.trino import Trino as SqlglotTrino +from sqlglot.tokens import Token, TokenType + +# Keywords that open a block terminated by ``END`` in Trino SQL routines +# (https://trino.io/docs/current/udf/sql.html). ``CASE`` is included because +# both the ``CASE`` statement and the ``CASE`` expression are terminated by +# ``END``, so counting them keeps the depth balanced either way. +BLOCK_OPENERS = {"BEGIN", "CASE", "IF", "LOOP", "REPEAT", "WHILE"} + +# Keywords that are also scalar functions in Trino (e.g. ``IF(a, b, c)`` and +# ``REPEAT('a', 3)``). When immediately followed by ``(`` they are function +# calls, not block openers. +AMBIGUOUS_OPENERS = {"IF", "REPEAT"} Review Comment: **Suggestion:** Add an explicit type annotation for this module-level constant so the variable is fully type hinted. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This module-level constant is also inferably a `set[str]` and lacks an explicit annotation, so it violates the type-hint requirement for annotatable variables. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=87b73c77764a493793b805392700768f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=87b73c77764a493793b805392700768f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/sql/dialects/trino.py **Line:** 35:35 **Comment:** *Custom Rule: Add an explicit type annotation for this module-level constant so the variable is fully type hinted. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=fcb338c020f9884cb2392edefc98b90f35d39f65a32396155e293efdb2759814&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=fcb338c020f9884cb2392edefc98b90f35d39f65a32396155e293efdb2759814&reaction=dislike'>👎</a> ########## superset/sql/dialects/trino.py: ########## @@ -0,0 +1,273 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import typing as t + +from sqlglot import exp +from sqlglot.dialects.trino import Trino as SqlglotTrino +from sqlglot.tokens import Token, TokenType + +# Keywords that open a block terminated by ``END`` in Trino SQL routines +# (https://trino.io/docs/current/udf/sql.html). ``CASE`` is included because +# both the ``CASE`` statement and the ``CASE`` expression are terminated by +# ``END``, so counting them keeps the depth balanced either way. +BLOCK_OPENERS = {"BEGIN", "CASE", "IF", "LOOP", "REPEAT", "WHILE"} + +# Keywords that are also scalar functions in Trino (e.g. ``IF(a, b, c)`` and +# ``REPEAT('a', 3)``). When immediately followed by ``(`` they are function +# calls, not block openers. +AMBIGUOUS_OPENERS = {"IF", "REPEAT"} + +BODY_KEYWORDS = ("RETURN", "BEGIN") + + +class InlineUDF(exp.CTE): + """ + An inline SQL user-defined function declared in a ``WITH`` clause. + + Trino supports declaring UDFs inline as part of a query:: + + WITH FUNCTION meaning_of_life() + RETURNS tinyint + BEGIN + DECLARE a tinyint DEFAULT CAST(6 AS tinyint); + DECLARE b tinyint DEFAULT CAST(7 AS tinyint); + RETURN a * b; + END + SELECT meaning_of_life() + + The function definition is stored verbatim as an opaque string (wrapped + in an ``exp.Var`` so that AST traversal helpers see an expression), since + sqlglot has no representation for SQL routine bodies. Trino does not + allow queries inside SQL UDF bodies, so no table references are hidden + by the opaque representation. + + This subclasses ``exp.CTE`` because ``sqlglot.parser.Parser._parse_with`` + only collects ``exp.CTE`` instances into the ``WITH`` clause. + """ + + arg_types = {"this": True} + + +class Trino(SqlglotTrino): + """ + Custom Trino dialect with support for inline SQL UDFs. + + sqlglot cannot parse Trino SQL routine syntax; see + https://github.com/tobymao/sqlglot/issues/5178. There are two separate + problems: + + 1. The parser splits statements on every semicolon, including the ones + inside a ``BEGIN ... END`` routine body. + 2. The ``FUNCTION`` specification in a ``WITH`` clause is not valid CTE + syntax. + + This dialect keeps routine bodies intact when splitting statements, and + parses inline function specifications into opaque `InlineUDF` nodes that + regenerate verbatim. + + Note that sqlglot's ``Dialect`` metaclass registers subclasses by class + name, so once this module is imported this class also replaces the + built-in dialect for string-based lookups (``dialect="trino"``). This is + intentional, and consistent with how other Superset dialects (e.g. + ``Dremio``) shadow their sqlglot counterparts: the extensions are purely + additive, only activating on syntax that fails to parse upstream. + """ + + class Parser(SqlglotTrino.Parser): + @staticmethod + def _block_depth_delta( + text: str, + prev_text: str, + next_token: Token | None, + ) -> int: + """ + Compute the block nesting change contributed by a routine token. + """ + if text in BLOCK_OPENERS: + if prev_text == "END": + return 0 # block terminator, e.g. `END IF`, `END CASE` + if ( + text in AMBIGUOUS_OPENERS + and next_token + and next_token.token_type == TokenType.L_PAREN + ): + return 0 # scalar function call, e.g. `IF(a, b, c)` + return 1 + if text == "END": + return -1 + return 0 + + def _parse( + self, + parse_method: t.Callable[..., exp.Expression | None], + raw_tokens: list[Token], + sql: str | None = None, + ) -> list[exp.Expression | None]: + """ + Split tokens into statements, keeping routine bodies intact. + + This is a copy of ``sqlglot.parser.Parser._parse`` with one + change: when a statement starts with ``WITH FUNCTION``, ``CREATE + FUNCTION``, or ``CREATE OR REPLACE FUNCTION``, semicolons inside + ``BEGIN ... END`` blocks do not split the statement. + """ + self.reset() + self.sql = sql or "" + + total = len(raw_tokens) + chunks: list[list[Token]] = [[]] + routine_mode = False + depth = 0 + prev_text = "" + + for i, token in enumerate(raw_tokens): + if token.token_type == TokenType.SEMICOLON and depth <= 0: + if token.comments: + chunks.append([token]) + if i < total - 1: + chunks.append([]) + routine_mode = False + depth = 0 + prev_text = "" + continue + + chunk = chunks[-1] + chunk.append(token) + + if token.token_type == TokenType.FUNCTION and not routine_mode: + heads = [tok.token_type for tok in chunk[:-1]] + routine_mode = heads in ( + [TokenType.WITH], + [TokenType.CREATE], + [TokenType.CREATE, TokenType.OR, TokenType.REPLACE], + ) + elif routine_mode: + text = token.text.upper() + next_token = raw_tokens[i + 1] if i < total - 1 else None + depth += self._block_depth_delta(text, prev_text, next_token) + + prev_text = token.text.upper() + + self._chunks = chunks + return self._parse_batch_statements( + parse_method=parse_method, + sep_first_statement=False, + ) + + def _parse_cte(self) -> exp.CTE | None: + """ + Parse a single entry in a ``WITH`` clause. + + An entry starting with the ``FUNCTION`` keyword followed by an + identifier is an inline UDF specification; anything else + (including a CTE named "function") is handled by sqlglot. + """ + if ( + self._curr + and self._curr.token_type == TokenType.FUNCTION + and self._next + and self._next.token_type + not in (TokenType.ALIAS, TokenType.L_PAREN, TokenType.COMMA) + ): + return self._parse_inline_udf() + + return super()._parse_cte() + + def _parse_inline_udf(self) -> InlineUDF: + """ + Consume an inline UDF specification and return it verbatim. + + The specification is ``FUNCTION name(params) RETURNS type`` plus + optional routine characteristics, followed by a body that is + either ``RETURN expression`` or a ``BEGIN ... END`` block. + """ + start = self._curr + self._advance() + + # scan for the start of the function body, skipping over the + # signature, return type, and routine characteristics + paren_depth = 0 + body: str | None = None Review Comment: **Suggestion:** Add a type annotation for this local counter variable to meet the type-hint rule for annotatable variables. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This local counter is an obvious `int` and is not annotated. Under the stated type-hinting rule, this is a valid omission to flag. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f12c4911af114c8ebf18fa545d41fcf6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=f12c4911af114c8ebf18fa545d41fcf6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/sql/dialects/trino.py **Line:** 207:207 **Comment:** *Custom Rule: Add a type annotation for this local counter variable to meet the type-hint rule for annotatable variables. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=3e7a698e37c4ced6292dd5321962ba21da23540ae5007f3ea27cd89815d7cb1c&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=3e7a698e37c4ced6292dd5321962ba21da23540ae5007f3ea27cd89815d7cb1c&reaction=dislike'>👎</a> ########## superset/sql/dialects/trino.py: ########## @@ -0,0 +1,273 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import typing as t + +from sqlglot import exp +from sqlglot.dialects.trino import Trino as SqlglotTrino +from sqlglot.tokens import Token, TokenType + +# Keywords that open a block terminated by ``END`` in Trino SQL routines +# (https://trino.io/docs/current/udf/sql.html). ``CASE`` is included because +# both the ``CASE`` statement and the ``CASE`` expression are terminated by +# ``END``, so counting them keeps the depth balanced either way. +BLOCK_OPENERS = {"BEGIN", "CASE", "IF", "LOOP", "REPEAT", "WHILE"} + +# Keywords that are also scalar functions in Trino (e.g. ``IF(a, b, c)`` and +# ``REPEAT('a', 3)``). When immediately followed by ``(`` they are function +# calls, not block openers. +AMBIGUOUS_OPENERS = {"IF", "REPEAT"} + +BODY_KEYWORDS = ("RETURN", "BEGIN") + + +class InlineUDF(exp.CTE): + """ + An inline SQL user-defined function declared in a ``WITH`` clause. + + Trino supports declaring UDFs inline as part of a query:: + + WITH FUNCTION meaning_of_life() + RETURNS tinyint + BEGIN + DECLARE a tinyint DEFAULT CAST(6 AS tinyint); + DECLARE b tinyint DEFAULT CAST(7 AS tinyint); + RETURN a * b; + END + SELECT meaning_of_life() + + The function definition is stored verbatim as an opaque string (wrapped + in an ``exp.Var`` so that AST traversal helpers see an expression), since + sqlglot has no representation for SQL routine bodies. Trino does not + allow queries inside SQL UDF bodies, so no table references are hidden + by the opaque representation. + + This subclasses ``exp.CTE`` because ``sqlglot.parser.Parser._parse_with`` + only collects ``exp.CTE`` instances into the ``WITH`` clause. + """ + + arg_types = {"this": True} + + +class Trino(SqlglotTrino): + """ + Custom Trino dialect with support for inline SQL UDFs. + + sqlglot cannot parse Trino SQL routine syntax; see + https://github.com/tobymao/sqlglot/issues/5178. There are two separate + problems: + + 1. The parser splits statements on every semicolon, including the ones + inside a ``BEGIN ... END`` routine body. + 2. The ``FUNCTION`` specification in a ``WITH`` clause is not valid CTE + syntax. + + This dialect keeps routine bodies intact when splitting statements, and + parses inline function specifications into opaque `InlineUDF` nodes that + regenerate verbatim. + + Note that sqlglot's ``Dialect`` metaclass registers subclasses by class + name, so once this module is imported this class also replaces the + built-in dialect for string-based lookups (``dialect="trino"``). This is + intentional, and consistent with how other Superset dialects (e.g. + ``Dremio``) shadow their sqlglot counterparts: the extensions are purely + additive, only activating on syntax that fails to parse upstream. + """ + + class Parser(SqlglotTrino.Parser): + @staticmethod + def _block_depth_delta( + text: str, + prev_text: str, + next_token: Token | None, + ) -> int: + """ + Compute the block nesting change contributed by a routine token. + """ + if text in BLOCK_OPENERS: + if prev_text == "END": + return 0 # block terminator, e.g. `END IF`, `END CASE` + if ( + text in AMBIGUOUS_OPENERS + and next_token + and next_token.token_type == TokenType.L_PAREN + ): + return 0 # scalar function call, e.g. `IF(a, b, c)` + return 1 + if text == "END": + return -1 + return 0 + + def _parse( + self, + parse_method: t.Callable[..., exp.Expression | None], + raw_tokens: list[Token], + sql: str | None = None, + ) -> list[exp.Expression | None]: + """ + Split tokens into statements, keeping routine bodies intact. + + This is a copy of ``sqlglot.parser.Parser._parse`` with one + change: when a statement starts with ``WITH FUNCTION``, ``CREATE + FUNCTION``, or ``CREATE OR REPLACE FUNCTION``, semicolons inside + ``BEGIN ... END`` blocks do not split the statement. + """ + self.reset() + self.sql = sql or "" + + total = len(raw_tokens) + chunks: list[list[Token]] = [[]] + routine_mode = False + depth = 0 + prev_text = "" + Review Comment: **Suggestion:** Add inline type annotations for these control-state local variables in the method, since they are relevant variables with clear concrete types. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> These local state variables have clear concrete types (`bool`, `int`, and `str`) and are assigned without annotations. That fits the rule flagging new or modified Python code that omits type hints on relevant variables. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3376d5898f304551a6763ce2d4de38b3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3376d5898f304551a6763ce2d4de38b3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/sql/dialects/trino.py **Line:** 137:139 **Comment:** *Custom Rule: Add inline type annotations for these control-state local variables in the method, since they are relevant variables with clear concrete types. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=0b9de867357582189ef7f3e0e036bb0fe2b9862f1f82898f7bca4b95b47b2871&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=0b9de867357582189ef7f3e0e036bb0fe2b9862f1f82898f7bca4b95b47b2871&reaction=dislike'>👎</a> ########## tests/unit_tests/sql/dialects/trino_tests.py: ########## @@ -0,0 +1,239 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest +import sqlglot + +from superset.exceptions import SupersetParseError +from superset.sql.dialects.trino import InlineUDF, Trino +from superset.sql.parse import SQLScript, SQLStatement, Table + +# example from https://trino.io/docs/current/udf/sql/begin.html, reported in +# https://github.com/apache/superset/issues/26162 +INLINE_UDF = """ Review Comment: **Suggestion:** Add an explicit `str` type hint to the new module-level SQL constant to satisfy the Python type-hint requirement for annotatable variables. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> The new module-level constant is a Python variable that can be annotated, but it is introduced without a type hint. This matches the rule requiring type hints for new or modified Python code where annotations are applicable. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=52c371dd3d994ed7872afd6269015e9c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=52c371dd3d994ed7872afd6269015e9c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/sql/dialects/trino_tests.py **Line:** 27:27 **Comment:** *Custom Rule: Add an explicit `str` type hint to the new module-level SQL constant to satisfy the Python type-hint requirement for annotatable variables. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=ff4220ba19e4903a79487927b8370c6a588c90d02fe4ad7447613640991e0a1d&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41803&comment_hash=ff4220ba19e4903a79487927b8370c6a588c90d02fe4ad7447613640991e0a1d&reaction=dislike'>👎</a> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
