clintropolis commented on code in PR #12388: URL: https://github.com/apache/druid/pull/12388#discussion_r866487698
########## processing/src/main/java/org/apache/druid/segment/ColumnSelectorColumnIndexSelector.java: ########## @@ -0,0 +1,91 @@ +/* + * 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.druid.segment; + +import org.apache.druid.collections.bitmap.BitmapFactory; +import org.apache.druid.query.filter.ColumnIndexSelector; +import org.apache.druid.segment.column.ColumnCapabilities; +import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.ColumnIndexSupplier; +import org.apache.druid.segment.column.NumericColumn; + +import javax.annotation.Nullable; + +/** + */ +public class ColumnSelectorColumnIndexSelector implements ColumnIndexSelector +{ + private final BitmapFactory bitmapFactory; + private final VirtualColumns virtualColumns; + private final ColumnSelector columnSelector; + + public ColumnSelectorColumnIndexSelector( + final BitmapFactory bitmapFactory, + final VirtualColumns virtualColumns, + final ColumnSelector index + ) + { + this.bitmapFactory = bitmapFactory; + this.virtualColumns = virtualColumns; + this.columnSelector = index; + } + + @Override + public int getNumRows() + { + try (final NumericColumn column = (NumericColumn) columnSelector.getColumnHolder(ColumnHolder.TIME_COLUMN_NAME).getColumn()) { + return column.length(); + } + } + + @Override + public BitmapFactory getBitmapFactory() + { + return bitmapFactory; + } + + @Override + public ColumnIndexSupplier getIndexSupplier(String column) + { + final ColumnIndexSupplier indexSupplier; + if (isVirtualColumn(column)) { + indexSupplier = virtualColumns.getIndexSupplier(column, columnSelector); + } else { + final ColumnHolder columnHolder = columnSelector.getColumnHolder(column); + if (columnHolder == null || !columnHolder.getCapabilities().isFilterable()) { Review Comment: >Or do we want a not filterable column to act like it doesn't even exist? This is the way it is currently intended to behave, if it is not filterable the column is meant to be treated as only nulls. I lost some comments about what was going on along the way, which i will try to add back. ``` // for missing columns and columns with types that do not support filtering, // treat the column as if it were a String column full of nulls. // Create a BitmapIndex so that filters applied to null columns can use // bitmap indexes. Filters check for the presence of a bitmap index, this is used to determine // whether the filter is applied in the pre or post filtering stage. ``` To be fair, i'm not completely certain this is the best way to handle this, since it does create odd situations where `unfilterable IS NULL` matches every row for a column that is not filterable when amusingly the value is not null, so I will be revisiting this in the future I think. It should probably never match anything ever if the column is not filterable, but that probably needs discussion since would be a behavior change, so i'm only going to make sure the comments documenting existing behavior are there and save logic changes for future work. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
