column data type is always STRING when results are empty.
- Dominant language
- Java
- Stars
- 6.1k
- Forks
- 1.5k
- Avg merge
- 2d 55m
- Merged PRs (30d)
- 182
Description
This caused a bit of confusion when one of our users ran an query on their table and the metadata that came back showed that all the columns in the result set were STRING. I debugged the issue and narrowed down the cause to the code below:
```
private static SelectionResultsBlock buildEmptySelectionQueryResults(QueryContext queryContext) {
List selectExpressions = queryContext.getSelectExpressions();
int numSelectExpressions = selectExpressions.size();
String[] columnNames = new String[numSelectExpressions];
for (int i = 0; i < numSelectExpressions; i++) {
columnNames[i] = selectExpressions.get(i).toString();
}
ColumnDataType[] columnDataTypes = new ColumnDataType[numSelectExpressions];
// NOTE: Use STRING column data type as default for selection query
Arrays.fill(columnDataTypes, ColumnDataType.STRING);
DataSchema dataSchema = new DataSchema(columnNames, columnDataTypes);
return new SelectionResultsBlock(dataSchema, Collections.emptyList());
}
```
Note the use of `Arrays.fill(columnDataTypes, ColumnDataType.STRING)` which sets all the columns in result metadata to STRING when resultset is empty. I am wondering if can modify this to return either no metadata or no column datatypes or are there backward compatibly concerns around making such a change?
Contributor guide
Research direction
Start with buildEmptySelectionQueryResults(QueryContext) and inspect how SelectionResultsBlock and DataSchema metadata are consumed for empty selection results. Trace the relevant query-result and metadata tests, then establish whether empty results should preserve inferred types, omit types, or return no metadata while maintaining compatibility. Done means empty-result metadata no longer reports every column as STRING and the behavior is covered by regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100