Skip to content
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

获取函数参数会返回生成器,导致程序报错 #655

Closed
cainiaodarui opened this issue Oct 11, 2024 · 1 comment
Closed

获取函数参数会返回生成器,导致程序报错 #655

cainiaodarui opened this issue Oct 11, 2024 · 1 comment
Labels
invalid This doesn't seem right

Comments

@cainiaodarui
Copy link

Describe the bug

  • sqllineage\core\parser\sqlparse\utils.py 解析SQL函数时,返回了生成器parameters ,parameters += [
    tk for tk in last_token.tokens if tk.is_group or tk.ttype == Wildcard
    ]
    报错 TypeError: unsupported operand type(s) for +=: 'generator' and 'list'

SQL
Paste the SQL text here. For example:

无法提供

To Reproduce
Note here we refer to SQL provided in prior step as stored in a file named test.sql

  • if CLI (Command Line Interface): provide the command you're calling and the output.
    For example:
sqllineage -f test.sql --dialect=ansi
Statements(#): 1
Source Tables:
    <default>.foo
Target Tables:
    <default>.analyze
  • elif API (Application Programming Interface): provide the python code you're using and the output.
    For example:
#
def get_parameters(token: Function):
    """
    This is a replacement for sqlparse.sql.Function.get_parameters(), which produces problematic result for:
        if(col1 = 'foo' AND col2 = 'bar', 1, 0)
    This implementation ignores the constant parameter as we don't need them for column lineage for now
    """
    last_token = token.tokens[-1]
    parameters = []
    if isinstance(last_token, Over):
        # special handling for window function
        parameters = token.get_parameters()
    parameters += [
        tk for tk in last_token.tokens if tk.is_group or tk.ttype == Wildcard
    ]
    return parameters
#token.get_parameters()
    def get_parameters(self):
        """Return a list of parameters."""
        parenthesis = self.token_next_by(i=Parenthesis)[1]
        result = []
        for token in parenthesis.tokens:
            if isinstance(token, IdentifierList):
                return token.get_identifiers()
            elif imt(token, i=(Function, Identifier, TypedLiteral),
                     t=T.Literal):
                result.append(token)
        return result
#当满足条件时,调用sqlparse .get_identifiers()返回生成器, parameters += [
#        tk for tk in last_token.tokens if tk.is_group or tk.ttype == Wildcard ]
#if isinstance(token, IdentifierList):
#                return token.get_identifiers()
TypeError: unsupported operand type(s) for +=: 'generator' and 'list'
  • elif Web UI (Web User Interface): provide the lineage graph which could be downloaded from the page, or screenshots if there're components other than the lineage graph that's related to this bug.

  • else: whatever other ways to reproduce this bug.

Expected behavior
A clear and concise description of what you expected to happen, and the output in accordance with the To Reproduce section.

Python version (available via python --version)

  • 3.8.17
  • 3.9.18
  • 3.10.13
  • 3.11.5
  • etc.

SQLLineage version (available via sqllineage --version):

  • 1.3.8
  • 1.4.7
  • etc.

Additional context
Add any other context about the problem here.

@cainiaodarui cainiaodarui added the bug Something isn't working label Oct 11, 2024
@reata
Copy link
Owner

reata commented Feb 7, 2025

I can't reproduce the issue without the SQL provided. Please desensitize the sensitive information from the SQL and provide a minimum example for debugging.

Also please communicate in English (中英双语也可以) and create a new issue once you have a minimum example.

@reata reata closed this as completed Feb 7, 2025
@reata reata added invalid This doesn't seem right and removed bug Something isn't working labels Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants