xiangfu0 edited a comment on pull request #7678: URL: https://github.com/apache/pinot/pull/7678#issuecomment-962576529
> The column names in the resultset look good now, but I think there is more here than meets the eye. During runtime `AsTransformFunction` is being constantly called by `DistinctOperator`. This appears to be redundant since `AsTransformFunction` is simply passing the underlying resultset and has no use during runtime. I think this can be fixed by making the following modification to `BrokerRequestToQueryContextConverter.java`: > > ``` > case "DISTINCT": > // Handle alias > operands = thriftExpression.getFunctionCall().getOperands(); > for (Expression operand : operands) { > if (operand.isSetFunctionCall() && operand.getFunctionCall().getOperator().equalsIgnoreCase("AS")) { > List<Expression> asOperands = operand.getFunctionCall().getOperands(); > aliasList.add(asOperands.get(1).getIdentifier().getName()); > > // Now that alias has been set, we don't need AS function, so replace AS function with its first > // operand. > Expression mainOperand = asOperands.get(0); > operand.setType(mainOperand.getType()); > operand.unsetFunctionCall(); > > switch (mainOperand.getType()) { > case LITERAL: > operand.setLiteral(mainOperand.getLiteral()); > break; > case FUNCTION: > operand.setFunctionCall(mainOperand.getFunctionCall()); > break; > case IDENTIFIER: > operand.setIdentifier(mainOperand.getIdentifier()); > break; > } > } else { > aliasList.add(null); > } > } > break; > ``` > > However, this fix still appears a bit "hacky" since AsTransformFunction is used only during compile time and then discarded. One way to fix this might be to modify `org.apache.pinot.common.request.Function` to contain a list of output aliases (?) Since DISTINCT is a Function that outputs an entire row (and there are probably other functions like this), it makes sense for `Function` to have a list of aliases for the row output as well (?) and this will avoid the use of `AsTransformFunction` and all we would need to do is to fetch the list of aliases from the Function and set it (?) In this case, then we should try to delete the AsTransformFunction and try to compute the alias at the beginning then replace the AS expression to just its left expression. Typical query engine can generate the query plan with the output column names. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org