Skip to content

Commit a19bf8c

Browse files
authored
Bug Fix: Merge PR #1089 from brianv0/u/bvan/fix-table
Bug Fix: Fix ADQL query generation
2 parents 774678f + 0b06d4d commit a19bf8c

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/firefly/js/ui/tap/ColumnConstraintsPanel.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ export function getTableConstraints(tbl_id) {
9393

9494
// collect the names of all selected columns
9595
let allSelected = true;
96+
let selcolsArray = [];
9697
let selcolsFragment = tbl_data.reduce((prev, d, idx) => {
9798
if ((sel_info.selectAll && (!sel_info.exceptions.has(idx))) ||
9899
(!sel_info.selectAll && (sel_info.exceptions.has(idx)))) {
99100
prev += d[0] + ',';
101+
selcolsArray.push(d[0]);
100102
} else {
101103
allSelected = false;
102104
}
@@ -107,7 +109,7 @@ export function getTableConstraints(tbl_id) {
107109
selcolsFragment = '';
108110
}
109111

110-
return {whereFragment, selcolsFragment, errors, filters};
112+
return {whereFragment, selcolsFragment, errors, filters, selcolsArray};
111113
}
112114

113115
/**

src/firefly/js/ui/tap/TableColumnsConstraints.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,5 @@ export function tableColumnsConstraints(columnsModel) {
215215
const colsToSelect = selcolsFragment.lastIndexOf(',') > 0 ?
216216
selcolsFragment.substring(0, selcolsFragment.lastIndexOf(',')) : selcolsFragment;
217217

218-
return {valid: true, where: whereFragment, selcols: (colsToSelect.length > 0) ? colsToSelect : ''};
218+
return {valid: true, where: whereFragment, selcols: (colsToSelect.length > 0) ? colsToSelect : '', selcolsArray: tableconstraints.selcolsArray};
219219
}

src/firefly/js/ui/tap/TableSelectViewPanel.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export function BasicUI(props) {
266266
value={tableName}
267267
onSelect={(selectedTapTable) => {
268268
setTableName(selectedTapTable);
269+
dispatchValueChange({groupKey: gkey, fieldKey: 'tableName', value: selectedTapTable});
269270
}}
270271
/>
271272
</div>

src/firefly/js/ui/tap/TapSearchRootPanel.jsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { gkey, SectionTitle, AdqlUI, BasicUI} from 'firefly/ui/tap/TableSelectVi
2828

2929

3030
const SERVICE_TIP= 'Select a TAP service, or type to enter the URL of any other TAP service';
31+
const ADQL_LINE_LENGTH = 100;
3132

3233
//-------------
3334
//-------------
@@ -338,7 +339,24 @@ function getAdqlQuery(showErrors= true) {
338339
if (adqlFragment.where) {
339340
constraints += (addAnd ? ' AND ' : '') + `(${adqlFragment.where})`;
340341
}
341-
const selcols = adqlFragment.selcols || '*';
342+
let selcols = adqlFragment.selcols || '*';
343+
344+
// If the line is long, rebuild the line from array of column names
345+
// breaking at ADQL_LINE_LENGTH
346+
if (selcols.length > ADQL_LINE_LENGTH) {
347+
selcols = '';
348+
let line = adqlFragment.selcolsArray[0];
349+
const colsCopy = adqlFragment.selcolsArray.slice(1);
350+
colsCopy.forEach((value) => {
351+
const nextColumn = ',' + value;
352+
if ((line + nextColumn).length > ADQL_LINE_LENGTH){
353+
selcols += line + '\n';
354+
line = ' ';
355+
}
356+
line += nextColumn;
357+
});
358+
selcols += line;
359+
}
342360

343361
if (constraints) {
344362
constraints = `WHERE ${constraints}`;
@@ -347,5 +365,5 @@ function getAdqlQuery(showErrors= true) {
347365
// if we use TOP when maxrec is set `${maxrec ? `TOP ${maxrec} `:''}`,
348366
// overflow indicator will not be included with the results
349367
// and we will not know if the results were truncated
350-
return `SELECT ${selcols} FROM ${tableName} ${constraints}`;
368+
return `SELECT ${selcols} \nFROM ${tableName} \n${constraints}`;
351369
}

0 commit comments

Comments
 (0)