Skip to content
Snippets Groups Projects
Commit 0be32298 authored by gmantele's avatar gmantele
Browse files

[ADQL] Based on the previous commit, fix and simplify the way SelectAllColummns

are translated: the table part (if a reference to an aliased table) should be
as declared in the DBTable (especially now that we have DBTableAlias to deal
nicely with table aliases).
parent d7927d84
No related branches found
No related tags found
No related merge requests found
...@@ -19,9 +19,7 @@ package adql.translator; ...@@ -19,9 +19,7 @@ package adql.translator;
* Copyright 2017 - Astronomisches Rechen Institut (ARI) * Copyright 2017 - Astronomisches Rechen Institut (ARI)
*/ */
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import adql.db.DBColumn; import adql.db.DBColumn;
import adql.db.DBTable; import adql.db.DBTable;
...@@ -456,30 +454,17 @@ public abstract class JDBCTranslator implements ADQLTranslator { ...@@ -456,30 +454,17 @@ public abstract class JDBCTranslator implements ADQLTranslator {
@Override @Override
public String translate(SelectAllColumns item) throws TranslationException{ public String translate(SelectAllColumns item) throws TranslationException{
HashMap<String,String> mapAlias = new HashMap<String,String>();
// Fetch the full list of columns to display: // Fetch the full list of columns to display:
Iterable<DBColumn> dbCols = null; Iterable<DBColumn> dbCols = null;
if (item.getAdqlTable() != null && item.getAdqlTable().getDBLink() != null){ if (item.getAdqlTable() != null && item.getAdqlTable().getDBLink() != null){
ADQLTable table = item.getAdqlTable(); ADQLTable table = item.getAdqlTable();
dbCols = table.getDBLink(); dbCols = table.getDBLink();
if (table.hasAlias()){
String key = getQualifiedTableName(table.getDBLink());
mapAlias.put(key, table.isCaseSensitive(IdentifierField.ALIAS) ? ("\"" + table.getAlias() + "\"") : table.getAlias());
}
}else if (item.getQuery() != null){ }else if (item.getQuery() != null){
try{ try{
dbCols = item.getQuery().getFrom().getDBColumns(); dbCols = item.getQuery().getFrom().getDBColumns();
}catch(UnresolvedJoinException pe){ }catch(UnresolvedJoinException pe){
throw new TranslationException("Due to a join problem, the ADQL to SQL translation can not be completed!", pe); throw new TranslationException("Due to a join problem, the ADQL to SQL translation can not be completed!", pe);
} }
List<ADQLTable> tables = item.getQuery().getFrom().getTables();
for(ADQLTable table : tables){
if (table.hasAlias()){
String key = getQualifiedTableName(table.getDBLink());
mapAlias.put(key, table.isCaseSensitive(IdentifierField.ALIAS) ? ("\"" + table.getAlias() + "\"") : table.getAlias());
}
}
} }
// Write the DB name of all these columns: // Write the DB name of all these columns:
...@@ -489,11 +474,10 @@ public abstract class JDBCTranslator implements ADQLTranslator { ...@@ -489,11 +474,10 @@ public abstract class JDBCTranslator implements ADQLTranslator {
if (cols.length() > 0) if (cols.length() > 0)
cols.append(','); cols.append(',');
if (col.getTable() != null){ if (col.getTable() != null){
String fullDbName = getQualifiedTableName(col.getTable()); if (col.getTable() instanceof DBTableAlias)
if (mapAlias.containsKey(fullDbName)) cols.append(getTableName(col.getTable(), false)).append('.');
appendIdentifier(cols, mapAlias.get(fullDbName), false).append('.');
else else
cols.append(fullDbName).append('.'); cols.append(getQualifiedTableName(col.getTable())).append('.');
} }
appendIdentifier(cols, col.getDBName(), IdentifierField.COLUMN); appendIdentifier(cols, col.getDBName(), IdentifierField.COLUMN);
cols.append(" AS \"").append(col.getADQLName()).append('\"'); cols.append(" AS \"").append(col.getADQLName()).append('\"');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment