Skip to content

column data type is always STRING when results are empty. #9660

@amrishlal

Description

@amrishlal

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<ExpressionContext> 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions