paul-rogers commented on a change in pull request #1974: DRILL-7574: Generalize the projection parser URL: https://github.com/apache/drill/pull/1974#discussion_r379117659
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/physical/resultSet/project/Qualifier.java ########## @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.physical.resultSet.project; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.drill.exec.physical.resultSet.project.RequestedTuple.TupleProjectionType; + +/** + * Represents one level of qualifier for a column. Analogous to + * a {@code SchemaPath}, but represents the result of coalescing + * multiple occurrences of the same column. + */ +public class Qualifier implements QualifierContainer { + /** + * Marker to indicate that that a) the item is an + * array, and b) that all indexes are to be projected. + * Used when seeing both a and a[x]. + */ + private static final Set<Integer> ALL_INDEXES = new HashSet<>(); + + private Set<Integer> indexes; + private RequestedTuple members; + private Qualifier child; + + @Override + public Qualifier qualifier() { return child; } + + @Override + public Qualifier requireQualifier() { + if (child == null) { + child = new Qualifier(); + } + return child; + } + + public boolean isArray() { + return indexes != null; + } + + public boolean hasIndexes() { + return isArray() && indexes != ALL_INDEXES; + } + + public boolean hasIndex(int index) { + return hasIndexes() && indexes.contains(index); + } + + public int maxIndex() { + if (! hasIndexes()) { + return 0; Review comment: Good question. The assumption is that we know the column to be projected as an array, and we now want to know how many indexes appeared in the projection list. Added more documentation to `RequestedColumn` to explain the details. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
