LakshSingla commented on code in PR #16068: URL: https://github.com/apache/druid/pull/16068#discussion_r1553265926
########## processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/GroupByColumnSelectorStrategyFactory.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.query.groupby.epinephelinae; + +import org.apache.druid.error.DruidException; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.query.dimension.ColumnSelectorStrategyFactory; +import org.apache.druid.query.groupby.epinephelinae.column.DictionaryBuildingGroupByColumnSelectorStrategy; +import org.apache.druid.query.groupby.epinephelinae.column.FixedWidthGroupByColumnSelectorStrategy; +import org.apache.druid.query.groupby.epinephelinae.column.GroupByColumnSelectorStrategy; +import org.apache.druid.query.groupby.epinephelinae.column.PrebuiltDictionaryStringGroupByColumnSelectorStrategy; +import org.apache.druid.segment.ColumnValueSelector; +import org.apache.druid.segment.DimensionSelector; +import org.apache.druid.segment.column.ColumnCapabilities; +import org.apache.druid.segment.column.ColumnType; + +/** + * Creates {@link org.apache.druid.query.dimension.ColumnSelectorStrategy}s for grouping dimensions + */ +public class GroupByColumnSelectorStrategyFactory implements ColumnSelectorStrategyFactory<GroupByColumnSelectorStrategy> +{ + @Override + public GroupByColumnSelectorStrategy makeColumnSelectorStrategy( + ColumnCapabilities capabilities, + ColumnValueSelector selector + ) + { + if (capabilities == null || capabilities.getType() == null) { + throw DruidException.defensive("Unable to deduce type for the grouping dimension"); + } + switch (capabilities.getType()) { + case STRING: + DimensionSelector dimSelector = (DimensionSelector) selector; + if (dimSelector.getValueCardinality() >= 0 && dimSelector.nameLookupPossibleInAdvance()) { + return PrebuiltDictionaryStringGroupByColumnSelectorStrategy.forType( + ColumnType.STRING, + selector, + capabilities + ); + } else { + return DictionaryBuildingGroupByColumnSelectorStrategy.forType(ColumnType.STRING); + } + case LONG: + return new FixedWidthGroupByColumnSelectorStrategy<Long>( + Byte.BYTES + Long.BYTES, Review Comment: Good point, I am always surprised that the `NullableTypeStrategy` isn't an instance of `TypeStrategy`. I think a cleaner approach would be to make the `NullableTypeStrategy` instanceof `TypeStrategy` and proceed from there. If not addressed here, I can make up a follow-up improvement for the same. -- 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...@druid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org