Skip to content
Snippets Groups Projects
Commit 2ad2007f authored by vforchi's avatar vforchi
Browse files

Merge remote-tracking branch 'upstream/master'

parents 0ee4525f 704877d2
No related branches found
No related tags found
No related merge requests found
......@@ -455,7 +455,7 @@ public class ResultSetTableIterator implements TableIterator {
* @since 2.1
*/
public ResultSetTableIterator(final DBConnection dbConn, final ResultSet dataSet, final DBColumn[] metadata) throws NullPointerException, DataReadException{
this(dbConn, dataSet, null, null, null);
this(dbConn, dataSet, metadata, null, null);
}
/**
......@@ -579,9 +579,12 @@ public class ResultSetTableIterator implements TableIterator {
colMeta = new TAPColumn[nbColumns];
for(int i = 1; i <= nbColumns; i++){
if (resultMeta != null && (i - 1) < resultMeta.length && resultMeta[i - 1] != null){
try{
if (resultMeta[i - 1] instanceof TAPColumn)
colMeta[i - 1] = (TAPColumn)resultMeta[i - 1];
}catch(ClassCastException cce){
else if (resultMeta[i - 1].getDatatype() != null){
colMeta[i - 1] = new TAPColumn(resultMeta[i - 1].getADQLName(), resultMeta[i - 1].getDatatype());
colMeta[i - 1].setDBName(resultMeta[i - 1].getDBName());
}else{
DBType datatype = convertType(metadata.getColumnType(i), metadata.getColumnTypeName(i), dbms);
colMeta[i - 1] = new TAPColumn(resultMeta[i - 1].getADQLName(), datatype);
}
......
......@@ -12,6 +12,11 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import adql.db.DBType;
import adql.parser.ADQLParser;
import adql.query.ADQLQuery;
import adql.translator.PgSphereTranslator;
import tap.metadata.TAPColumn;
import testtools.DBTools;
public class ResultSetTableIteratorTest {
......@@ -165,4 +170,41 @@ public class ResultSetTableIteratorTest {
}
}
}
@Test
public void testGeometryColumns(){
ResultSet rs = null;
try{
ADQLQuery query = (new ADQLParser()).parseQuery("SELECT TOP 1 POINT('', ra, deg), CENTROID(CIRCLE('', ra, deg, 2)), BOX('', ra-10, deg-2, ra+10, deg+2), CIRCLE('', ra, deg, 2) FROM gums;");
// create a valid ResultSet:
rs = DBTools.select(conn, (new PgSphereTranslator()).translate(query));
// Create the iterator:
ResultSetTableIterator rsit = new ResultSetTableIterator(rs, query.getResultingColumns());
assertTrue(rsit.nextRow());
// Fetch the metadata:
TAPColumn[] cols = rsit.getMetadata();
assertEquals(4, cols.length);
// Check that the two first columns are POINTs:
for(int i = 0; i < 2; i++)
assertEquals(DBType.DBDatatype.POINT, cols[i].getDatatype().type);
// Check that the next columns are REGIONs:
for(int i = 2; i < 3; i++)
assertEquals(DBType.DBDatatype.REGION, cols[i].getDatatype().type);
}catch(Exception ex){
ex.printStackTrace(System.err);
fail("An exception occurs while formatting dates/times.");
}finally{
if (rs != null){
try{
rs.close();
}catch(Exception ex){}
}
}
}
}
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