clintropolis commented on code in PR #14014: URL: https://github.com/apache/druid/pull/14014#discussion_r1156573389
########## processing/src/main/java/org/apache/druid/segment/column/CapabilitiesBasedFormat.java: ########## @@ -0,0 +1,151 @@ +/* + * 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.column; + +import org.apache.druid.data.input.impl.DimensionSchema; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.segment.DimensionHandler; +import org.apache.druid.segment.DimensionHandlerUtils; + +import javax.annotation.Nullable; +import java.util.Objects; + +public class CapabilitiesBasedFormat implements ColumnFormat +{ + // merge logic for the state capabilities will be in after incremental index is persisted + public static final ColumnCapabilities.CoercionLogic DIMENSION_CAPABILITY_MERGE_LOGIC = + new ColumnCapabilities.CoercionLogic() + { + @Override + public boolean dictionaryEncoded() + { + return true; + } + + @Override + public boolean dictionaryValuesSorted() + { + return true; + } + + @Override + public boolean dictionaryValuesUnique() + { + return true; + } + + @Override + public boolean multipleValues() + { + return false; + } + + @Override + public boolean hasNulls() + { + return false; + } + }; + private final ColumnCapabilities capabilities; + + public CapabilitiesBasedFormat(ColumnCapabilities capabilities) + { + this.capabilities = capabilities; + } + + @Override + public DimensionHandler getColumnHandler(String columnName) + { + return DimensionHandlerUtils.getHandlerFromCapabilities(columnName, capabilities, null); + } + + @Override + public DimensionSchema getColumnSchema(String columnName) + { + return getColumnHandler(columnName).getDimensionSchema(capabilities); + } + + @Override + public ColumnFormat merge(@Nullable ColumnFormat otherFormat) + { + if (otherFormat == null) { + return this; + } + + ColumnCapabilitiesImpl merged = ColumnCapabilitiesImpl.copyOf(this.toColumnCapabilities()); + ColumnCapabilitiesImpl otherSnapshot = ColumnCapabilitiesImpl.copyOf(otherFormat.toColumnCapabilities()); + + if (!Objects.equals(merged.getType(), otherSnapshot.getType()) + || !Objects.equals(merged.getElementType(), otherSnapshot.getElementType())) { + final String mergedType = merged.getType() == null ? null : merged.asTypeString(); + final String otherType = otherSnapshot.getType() == null ? null : otherSnapshot.asTypeString(); + throw new ISE( + "Cannot merge columns of type[%s] and [%s]", + mergedType, + otherType + ); + } else if (!Objects.equals(merged.getComplexTypeName(), otherSnapshot.getComplexTypeName())) { + throw new ISE( + "Cannot merge columns of type[%s] and [%s]", + merged.getComplexTypeName(), + otherSnapshot.getComplexTypeName() + ); + } + + merged.setDictionaryEncoded(merged.isDictionaryEncoded().or(otherSnapshot.isDictionaryEncoded()).isTrue()); + merged.setHasMultipleValues(merged.hasMultipleValues().or(otherSnapshot.hasMultipleValues()).isTrue()); + merged.setDictionaryValuesSorted( + merged.areDictionaryValuesSorted().and(otherSnapshot.areDictionaryValuesSorted()).isTrue() + ); + merged.setDictionaryValuesUnique( + merged.areDictionaryValuesUnique().and(otherSnapshot.areDictionaryValuesUnique()).isTrue() + ); + merged.setHasNulls(merged.hasNulls().or(otherSnapshot.hasNulls()).isTrue()); + // When merging persisted queryableIndexes in the same ingestion job, + // all queryableIndexes should have the exact same hasBitmapIndexes flag set which is set in the ingestionSpec. + // One exception is null-only columns as they always do NOT have bitmap indexes no matter whether the flag is set + // in the ingestionSpec. As a result, the mismatch checked in the if clause below can happen + // when one of the columnCapability is from a real column and another is from a null-only column. + // See NullColumnPartSerde for how columnCapability is created for null-only columns. + // When the mismatch is found, we prefer the flag set in the ingestionSpec over + // the columnCapability of null-only columns. + if (merged.hasBitmapIndexes() != otherSnapshot.hasBitmapIndexes()) { + merged.setHasBitmapIndexes(false); + } Review Comment: yeah i copied this code from elsewhere, but agree it seems strange, looking into it. the comment isn't even true, null column part serde sets 'has bitmap indexes' to true because it has a 'null' index supplier which allows it to use all true/all false bitmaps if the filter matches null... -- 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]
