Skip to content

Commit

Permalink
Merge pull request #30 from lsst-sqre/tickets/DM-44759
Browse files Browse the repository at this point in the history
Fix issue with quoted column names in recent tap-postgres release
  • Loading branch information
stvoutsin committed Jun 10, 2024
2 parents 00817d0 + d7bcae1 commit 6e33b92
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ Find changes for the upcoming release in the project's [changelog.d](https://git

<!-- scriv-insert-here -->

<a id='changelog-8.1.0'></a>

<a id='changelog-1.17.1'></a>
## 1.17.1 (2024-06-10)

### Fixed

- Added PgsphereDeParser to AdqlQueryImpl / Fixes issue with queries having quotes around column names ("size")

<a id='changelog-1.17.0'></a>
## 1.17.0 (2024-06-07)

## Changed

- Bump cadc dependency versions & switch to using cadc-tomcat image by @stvoutsin in #28


<a id='changelog-1.16.0'></a>
## 1.16.0 (2024-05-30)

### New features
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/scriv.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[scriv]
format = md
9 changes: 9 additions & 0 deletions tap/src/main/java/ca/nrc/cadc/sample/AdqlQueryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
import ca.nrc.cadc.tap.AdqlQuery;
import ca.nrc.cadc.tap.parser.converter.TableNameConverter;
import ca.nrc.cadc.tap.parser.converter.TableNameReferenceConverter;
import ca.nrc.cadc.tap.parser.BaseExpressionDeParser;
import ca.nrc.cadc.tap.parser.PgsphereDeParser;
import net.sf.jsqlparser.util.deparser.SelectDeParser;
import ca.nrc.cadc.tap.parser.converter.TopConverter;
import ca.nrc.cadc.tap.parser.navigator.ExpressionNavigator;
import ca.nrc.cadc.tap.parser.navigator.FromItemNavigator;
Expand Down Expand Up @@ -117,4 +120,10 @@ protected void init()

// TODO: add more custom query visitors here
}

@Override
protected BaseExpressionDeParser getExpressionDeparser(SelectDeParser dep, StringBuffer sb) {
return new PgsphereDeParser(dep, sb);
}

}
36 changes: 36 additions & 0 deletions tap/src/test/java/ca/nrc/cadc/sample/AdqlQueryImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,54 @@ public void testTopConverter()
}
}

// Test that a query using size works as expected (No quotes)
@Test
public void testQueryWithSizeConverter()
{
try
{
job.getParameterList().add(new Parameter("QUERY", "select top 5 * from test.tables as t"));

AdqlQueryImpl q = new AdqlQueryImpl();
q.setJob(job);
q.setTapSchema(mockTapSchema());

String sql = q.getSQL();
log.debug("SQL: " + sql);
Assert.assertNotNull("sql", sql);
sql = sql.toLowerCase();
int i = sql.indexOf("select") + 6;
int j = sql.indexOf("from") - 1;
String selectList = sql.substring(i, j);
log.debug("select-list: " + selectList);
Assert.assertTrue(selectList.contains("t.size"));
}
catch(Exception unexpected)
{
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
finally
{
job.getParameterList().clear();
}
}

TapSchema mockTapSchema()
{
TapSchema ret = new TapSchema();
SchemaDesc sd = new SchemaDesc("test");
TableDesc foo = new TableDesc("test", "test.foo");
TableDesc bar = new TableDesc("test", "test.bar");
TableDesc tables = new TableDesc("test", "test.tables");
foo.getColumnDescs().add(new ColumnDesc("test.foo", "f1", TapDataType.INTEGER));
foo.getColumnDescs().add(new ColumnDesc("test.foo", "f2", new TapDataType("char", "8", null)));
bar.getColumnDescs().add(new ColumnDesc("test.bar", "b1", TapDataType.INTEGER));
bar.getColumnDescs().add(new ColumnDesc("test.bar", "b2", new TapDataType("char", "8", null)));
tables.getColumnDescs().add(new ColumnDesc("test.tables", "size", new TapDataType("char", "8", null)));
sd.getTableDescs().add(foo);
sd.getTableDescs().add(bar);
sd.getTableDescs().add(tables);
ret.getSchemaDescs().add(sd);
return ret;
}
Expand Down

0 comments on commit 6e33b92

Please sign in to comment.