google / google/googlesql

How to read where clause columns

Open
#93 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
2.6k
Forks
260
PR merge metrics
No merged PRs in 30d

Description

I am using the ZetaSql analyzeStatement and reading the where clause column names from the query after the analysis like the following.

String query = "Select count(*) from table1 where column1 = 'ABC' and column2 = 'abc' and column3 = 'zxc'";

ResolvedStatement resolvedStatement = analyzer.analyzeStatement(query);

Set columnNameSet = new HashSet<>();

resolvedStatement.accept(new ResolvedNodes.Visitor() {
@Override
public void visit(ResolvedNodes.ResolvedColumnRef node) {
columnNameSet.add(node.getColumn().getName());
}
});

Above callback method is giving me the where clause column name like following.

columnNameSet = [column1, column2, column3]

Is there a better way to read the where clause column names?

Contributor guide

Open the contributing guide

Research direction

Start with the issue's analyzeStatement call and the ResolvedNodes.Visitor implementation, especially visit(ResolvedNodes.ResolvedColumnRef), to understand how column references are collected. Done means documenting whether this is the supported way to identify WHERE-clause columns or pointing to a better analyzer API.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
api, databases
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.