Skip to content
Snippets Groups Projects
Commit 118f357a authored by gmantele's avatar gmantele
Browse files

[ADQL] Fix handling of delimited column references (e.g. items of ORDER BY).

This error has been raised on the issue #32 by Zarquan.
parent 006cb03d
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ package adql.db; ...@@ -16,7 +16,7 @@ package adql.db;
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with ADQLLibrary. If not, see <http://www.gnu.org/licenses/>. * along with ADQLLibrary. If not, see <http://www.gnu.org/licenses/>.
* *
* Copyright 2011-2016 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2011-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Astronomisches Rechen Institut (ARI) * Astronomisches Rechen Institut (ARI)
*/ */
...@@ -97,7 +97,7 @@ import adql.search.SimpleSearchHandler; ...@@ -97,7 +97,7 @@ import adql.search.SimpleSearchHandler;
* </i></p> * </i></p>
* *
* @author Gr&eacute;gory Mantelet (CDS;ARI) * @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 1.4 (03/2016) * @version 1.4 (03/2017)
*/ */
public class DBChecker implements QueryChecker { public class DBChecker implements QueryChecker {
...@@ -723,18 +723,16 @@ public class DBChecker implements QueryChecker { ...@@ -723,18 +723,16 @@ public class DBChecker implements QueryChecker {
}else }else
throw new ParseException("Column index out of bounds: " + index + " (must be between 1 and " + select.size() + ") !", colRef.getPosition()); throw new ParseException("Column index out of bounds: " + index + " (must be between 1 and " + select.size() + ") !", colRef.getPosition());
}else{ }else{
ADQLColumn col = new ADQLColumn(colRef.getColumnName()); ADQLColumn col = new ADQLColumn(null, colRef.getColumnName());
col.setCaseSensitive(colRef.isCaseSensitive()); col.setCaseSensitive(colRef.isCaseSensitive());
col.setPosition(colRef.getPosition()); col.setPosition(colRef.getPosition());
// search among the select_item aliases: // search among the select_item aliases:
if (col.getTableName() == null){
ArrayList<SelectItem> founds = select.searchByAlias(colRef.getColumnName(), colRef.isCaseSensitive()); ArrayList<SelectItem> founds = select.searchByAlias(colRef.getColumnName(), colRef.isCaseSensitive());
if (founds.size() == 1) if (founds.size() == 1)
return null; return null;
else if (founds.size() > 1) else if (founds.size() > 1)
throw new UnresolvedColumnException(col, founds.get(0).getAlias(), founds.get(1).getAlias()); throw new UnresolvedColumnException(col, founds.get(0).getAlias(), founds.get(1).getAlias());
}
// check the corresponding column: // check the corresponding column:
return resolveColumn(col, dbColumns, null); return resolveColumn(col, dbColumns, null);
......
...@@ -32,6 +32,7 @@ import adql.query.operand.function.DefaultUDF; ...@@ -32,6 +32,7 @@ import adql.query.operand.function.DefaultUDF;
import adql.query.operand.function.UserDefinedFunction; import adql.query.operand.function.UserDefinedFunction;
import adql.search.SimpleSearchHandler; import adql.search.SimpleSearchHandler;
import adql.translator.ADQLTranslator; import adql.translator.ADQLTranslator;
import adql.translator.PostgreSQLTranslator;
import adql.translator.TranslationException; import adql.translator.TranslationException;
public class TestDBChecker { public class TestDBChecker {
...@@ -135,6 +136,22 @@ public class TestDBChecker { ...@@ -135,6 +136,22 @@ public class TestDBChecker {
}catch(ParseException pe){} }catch(ParseException pe){}
} }
@Test
public void testColRefWithDottedAlias(){
ADQLParser parser = new ADQLParser(new DBChecker(tables));
try{
ADQLQuery adql = parser.parseQuery("SELECT colI AS \"col.I\" FROM aschema.foo ORDER BY \"col.I\"");
assertNotNull(adql);
assertEquals("SELECT \"aschema\".\"foo\".\"colI\" AS \"col.I\"\nFROM \"aschema\".\"foo\"\nORDER BY \"col.I\" ASC", (new PostgreSQLTranslator()).translate(adql));
}catch(ParseException pe){
pe.printStackTrace();
fail();
}catch(TranslationException te){
te.printStackTrace();
fail();
}
}
@Test @Test
public void testNumericOrStringValueExpressionPrimary(){ public void testNumericOrStringValueExpressionPrimary(){
ADQLParser parser = new ADQLParser(); ADQLParser parser = new ADQLParser();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment