walterddr commented on code in PR #11327:
URL: https://github.com/apache/pinot/pull/11327#discussion_r1292141880


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/validate/Validator.java:
##########
@@ -34,4 +42,85 @@ public Validator(SqlOperatorTable opTab, 
SqlValidatorCatalogReader catalogReader
     // TODO: support BABEL validator. Currently parser conformance is set to 
use BABEL.
     super(opTab, catalogReader, typeFactory, 
Config.DEFAULT.withSqlConformance(SqlConformanceEnum.LENIENT));
   }
+
+  /**
+   * Expand the star in the select list.
+   * Pinot table schema has all columns along with virtual columns.
+   * We don't want to include virtual columns in the select * query
+   *
+   * @param selectList        Select clause to be expanded
+   * @param select             Query
+   * @param includeSystemVars Whether to include system variables
+   * @return Expanded select list
+   */
+  @Override
+  public SqlNodeList expandStar(
+      SqlNodeList selectList,
+      SqlSelect select,
+      boolean includeSystemVars) {
+    SqlNodeList expandedSelectList = super.expandStar(selectList, select, 
includeSystemVars);
+    RelRecordType validatedNodeType = (RelRecordType) 
getValidatedNodeType(select);
+
+    List<String> selectedVirtualColumns = getSelectedVirtualColumns(select);
+    // ExpandStar will add a field for each column in the table, but we don't 
want to include the virtual columns
+    List<SqlNode> newSelectList = new ArrayList<>();
+    List<RelDataTypeField> newFieldList = new ArrayList<>();
+    for (int i = 0; i < expandedSelectList.size(); i++) {
+      SqlNode node = expandedSelectList.get(i);
+      if (node instanceof SqlIdentifier) {
+        String columnName = getColumnName((SqlIdentifier) node);
+        if (isVirtualColumn(columnName)) {
+          // If the virtual column is selected, remove it from the list of 
selected virtual columns
+          if (!selectedVirtualColumns.remove(columnName)) {

Review Comment:
   Can we add some test including
   - table name variances `tbl.*` 
   - star with some virtual column such as `*, $segmentName` 
   



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

Reply via email to