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

[BigQuery] Extracting table names from resolved columns #130

Open
jrbangit opened this issue Jan 23, 2023 · 0 comments
Open

[BigQuery] Extracting table names from resolved columns #130

jrbangit opened this issue Jan 23, 2023 · 0 comments

Comments

@jrbangit
Copy link

jrbangit commented Jan 23, 2023

I am trying to extract the source table name from a resolved column, for example

resolvedFunctionCall.accept(new ResolvedNodes.Visitor() {
                            @Override
                            public void visit(ResolvedNodes.ResolvedColumnRef resolvedColumnRef) {
                                sourceCol = String.format("%s.%s", resolvedColumnRef.getColumn().getTableName(), resolvedColumnRef.getColumn().getName());
                            }
                        });

However, if the tables used in a query are aliased then the resolvedColumnRef.getColumn().getTableName() results to the alias name instead of the actual table name.

You can re-create this scenario by analyzing a simple query that utilizes subqueries and make sure the tables inside subqueries are aliased, or you can also try it using with statements, then run the usual steps below. From the resolvedStatements which was returned by Analyzer.analyzeStatement, you can visit any node like the example above.

SimpleCatalog simpleCatalog = RegisterCatalog.register(simpleTableList);
Analyzer.analyzeStatement(query, analyzerOptions, simpleCatalog);

does someone know how can we extract the origin and actual table names of a particular resolved column despite being aliased in queries?

Thank you in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant