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

[question] 为什么 SqlSelectFunctionHelper 中的 hasAggregateFunction 调用的 getFunctions 没有过滤掉非聚合函数 #2025

Open
PeatBoy opened this issue Feb 2, 2025 · 0 comments
Labels
question Further information is requested

Comments

@PeatBoy
Copy link

PeatBoy commented Feb 2, 2025

Describe your question

public static boolean hasAggregateFunction(String sql) {
        return !CollectionUtils.isEmpty(getFunctions(sql));
    }
public static Set<String> getFunctions(String sql) {
        Set<Select> allSelect = SqlSelectHelper.getAllSelect(sql);
        Set<String> result = new HashSet<>();
        for (Select select : allSelect) {
            if (!(select instanceof PlainSelect)) {
                continue;
            }
            PlainSelect plainSelect = (PlainSelect) select;
            List<SelectItem<?>> selectItems = plainSelect.getSelectItems();
            FunctionVisitor visitor = new FunctionVisitor();
            for (SelectItem selectItem : selectItems) {
                selectItem.accept(visitor);
            }
            result.addAll(visitor.getFunctionNames());
        }
        return result;
    }

getFunctions 获取到 SQL 中所有的函数(不仅仅是聚合函数),那这里的 hasAggregateFunction 判断定是否含有聚合函数是否还成立?

QueryTypeParser 调用该方法受到影响。不太理解望解答

Your organization

none

@PeatBoy PeatBoy added the question Further information is requested label Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant