gmantele / vollt

Java libraries implementing the IVOA protocol: ADQL, UWS and TAP
http://cdsportal.u-strasbg.fr/taptuto/
29 stars 28 forks source link

ADQL-2.1 branch: Issue getting original column name from aliased query #156

Open jwfraustro opened 1 month ago

jwfraustro commented 1 month ago

Hi, I'm currently switching our fork over to using the feature branch supporting ADQL 2.1. I am having some issues with getting the original column name after parsing a query that uses a column alias.

For an ADQL query like: SELECT table_name AS columnalias FROM tap_schema.tables AS tablealias

the ADQLParser successfully parses and (for SQLServer at least) translates the query into: SELECT tablealias.table_name AS columnalias FROM tap_schema.tables AS tablealias

After parsing the query, I need to perform some operations that involve getting the column's original name table_name. In our old code, we made a call to getResultingColumns(), then to getDBName()

For example, an abstract code snippet:

queryObject = parser.parseQuery("SELECT table_name AS columnalias FROM tap_schema.tables AS tablealias");
// (new SQLServerTranslator()).translate(queryObject) produces correct translation
DBColumn columns = queryObject.getResultingColumns();
columns[0].getDBName();
// "table_name"

However, in the new branch, it seems that no longer works, and instead just returns the aliased name:

columns[0].getDBName();
// "columnalias"

It seems the line of affected code comes from the commit here, where Line 437 in getResultingColumns() https://github.com/gmantele/vollt/commit/d3415698b7ec7d2e0f5c424d201dc7cd97ef23eb was changed from:

col = col.copy(col.getDBName(), alias, col.getTable());

to

col = col.copy(alias, alias, col.getTable()); 

Indeed, in our own code, reverting the change does fix our issue with getting the original column name, but seems to fail some of your other aliasing tests.

Any advice would be much appreciated. Thank you!