Skip to content

Commit dcff5be

Browse files
authored
Merge pull request #679 from SlideRuleEarth/carlos-dev3
Selecting canopy_h_metrics in a PhoREAL request in Analysis elevation…
2 parents 88105de + 646aefe commit dcff5be

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

web-client/src/utils/SrDuckDbUtils.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,38 @@ export const computeSamplingRate = async(req_id:number): Promise<number> => {
199199
return sample_fraction;
200200
}
201201

202+
function isScalarNumericDuckType(type: string): boolean {
203+
const T = type.toUpperCase();
204+
// reject containers
205+
if (T.includes('LIST') || T.includes('[]') || T.startsWith('STRUCT') || T.startsWith('MAP') || T.startsWith('UNION')) {
206+
return false;
207+
}
208+
// allow numeric scalars
209+
return /^(TINYINT|SMALLINT|INTEGER|BIGINT|HUGEINT|UTINYINT|USMALLINT|UINTEGER|UBIGINT|REAL|FLOAT|DOUBLE|DECIMAL)/.test(T);
210+
}
211+
202212
export async function prepareDbForReqId(reqId: number): Promise<void> {
203-
const startTime = performance.now(); // Start time
204-
try{
213+
const startTime = performance.now();
214+
try {
205215
const fileName = await indexedDb.getFilename(reqId);
206-
//console.log(`prepareDbForReqId for ${reqId} fileName:${fileName}`);
207216
const duckDbClient = await createDuckDbClient();
208217
await duckDbClient.insertOpfsParquet(fileName);
209-
const colNames = await duckDbClient.queryForColNames(fileName);
218+
219+
// Get typed columns and keep only scalar numerics (no arrays/lists)
220+
const colTypes = await duckDbClient.queryColumnTypes(fileName);
221+
const scalarNumericCols = colTypes
222+
.filter(c => isScalarNumericDuckType(c.type))
223+
.map(c => c.name);
224+
210225
await updateAllFilterOptions(reqId);
211-
//console.trace(`prepareDbForReqId reqId:${reqId} colNames:`, colNames);
212-
setElevationDataOptionsFromFieldNames(reqId.toString(), colNames);
226+
//console.trace(`prepareDbForReqId reqId:${reqId} colNames:`, scalarNumericCols);
227+
// Use filtered names so arrays never reach the chart store
228+
setElevationDataOptionsFromFieldNames(reqId.toString(), scalarNumericCols);
213229
} catch (error) {
214230
console.error('prepareDbForReqId error:', error);
215231
throw error;
216-
} finally {
217-
const endTime = performance.now(); // End time
232+
} finally {
233+
const endTime = performance.now();
218234
console.log(`prepareDbForReqId for ${reqId} took ${endTime - startTime} milliseconds.`);
219235
}
220236
}

0 commit comments

Comments
 (0)