Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.nested;
import com.google.common.base.Predicate;
import com.google.common.primitives.Doubles;
import com.google.common.primitives.Floats;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
import org.apache.druid.collections.bitmap.ImmutableBitmap;
import org.apache.druid.common.guava.GuavaUtils;
import org.apache.druid.error.DruidException;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.math.expr.ExprEval;
import org.apache.druid.math.expr.ExpressionType;
import org.apache.druid.query.extraction.ExtractionFn;
import org.apache.druid.query.filter.DruidPredicateFactory;
import org.apache.druid.query.filter.StringPredicateDruidPredicateFactory;
import org.apache.druid.query.filter.ValueMatcher;
import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import org.apache.druid.segment.AbstractDimensionSelector;
import org.apache.druid.segment.ColumnValueSelector;
import org.apache.druid.segment.DimensionHandlerUtils;
import org.apache.druid.segment.DimensionSelector;
import org.apache.druid.segment.IdLookup;
import org.apache.druid.segment.column.ColumnType;
import org.apache.druid.segment.column.ColumnTypeFactory;
import org.apache.druid.segment.column.DictionaryEncodedColumn;
import org.apache.druid.segment.column.StringEncodingStrategies;
import org.apache.druid.segment.column.StringUtf8DictionaryEncodedColumn;
import org.apache.druid.segment.data.ColumnarInts;
import org.apache.druid.segment.data.FixedIndexed;
import org.apache.druid.segment.data.FrontCodedIntArrayIndexed;
import org.apache.druid.segment.data.Indexed;
import org.apache.druid.segment.data.IndexedInts;
import org.apache.druid.segment.data.ReadableOffset;
import org.apache.druid.segment.data.SingleIndexedInt;
import org.apache.druid.segment.historical.SingleValueHistoricalDimensionSelector;
import org.apache.druid.segment.vector.BaseDoubleVectorValueSelector;
import org.apache.druid.segment.vector.MultiValueDimensionVectorSelector;
import org.apache.druid.segment.vector.ReadableVectorInspector;
import org.apache.druid.segment.vector.ReadableVectorOffset;
import org.apache.druid.segment.vector.SingleValueDimensionVectorSelector;
import org.apache.druid.segment.vector.VectorObjectSelector;
import org.apache.druid.segment.vector.VectorSelectorUtils;
import org.apache.druid.segment.vector.VectorValueSelector;
import org.roaringbitmap.PeekableIntIterator;
import javax.annotation.Nullable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.BitSet;
import java.util.Iterator;
import java.util.SortedMap;
import java.util.TreeMap;
/**
* {@link NestedCommonFormatColumn} for single type array columns, and mixed type columns. If {@link #variantTypes}
* is non-null, the column is composed of all of the types defined there, otherwise all rows are consistently
* {@link #logicalType}. If mixed type, logical type is set by {@link ColumnType#leastRestrictiveType}.
*/
public class VariantColumn>
implements DictionaryEncodedColumn, NestedCommonFormatColumn
{
private final TStringDictionary stringDictionary;
private final FixedIndexed longDictionary;
private final FixedIndexed doubleDictionary;
private final FrontCodedIntArrayIndexed arrayDictionary;
private final ColumnarInts encodedValueColumn;
private final ImmutableBitmap nullValueBitmap;
private final ColumnType logicalType;
private final ExpressionType logicalExpressionType;
@Nullable
private final FieldTypeInfo.TypeSet variantTypes;
private final int adjustLongId;
private final int adjustDoubleId;
private final int adjustArrayId;
public VariantColumn(
TStringDictionary stringDictionary,
FixedIndexed longDictionary,
FixedIndexed doubleDictionary,
FrontCodedIntArrayIndexed arrayDictionary,
ColumnarInts encodedValueColumn,
ImmutableBitmap nullValueBitmap,
ColumnType logicalType,
@Nullable Byte variantTypeSetByte
)
{
this.stringDictionary = stringDictionary;
this.longDictionary = longDictionary;
this.doubleDictionary = doubleDictionary;
this.arrayDictionary = arrayDictionary;
this.encodedValueColumn = encodedValueColumn;
this.nullValueBitmap = nullValueBitmap;
this.logicalExpressionType = ExpressionType.fromColumnTypeStrict(logicalType);
this.variantTypes = variantTypeSetByte == null ? null : new FieldTypeInfo.TypeSet(variantTypeSetByte);
// use the variant type bytes if set, in current code the logical type should have been computed via this same means
// however older versions of the code had a bug which could incorrectly classify mixed types as nested data
if (variantTypeSetByte != null) {
ColumnType theType = null;
for (ColumnType type : FieldTypeInfo.convertToSet(variantTypeSetByte)) {
theType = ColumnType.leastRestrictiveType(theType, type);
}
if (theType != null) {
// sign bit is used to indicate empty arrays, this
if (variantTypeSetByte < 0 && !theType.isArray()) {
theType = ColumnTypeFactory.getInstance().ofArray(theType);
}
this.logicalType = theType;
} else {
this.logicalType = logicalType;
}
} else {
this.logicalType = logicalType;
}
this.adjustLongId = stringDictionary.size();
this.adjustDoubleId = adjustLongId + longDictionary.size();
this.adjustArrayId = adjustDoubleId + doubleDictionary.size();
}
@Override
public ColumnType getLogicalType()
{
return logicalType;
}
@Override
public Indexed getStringDictionary()
{
return new StringEncodingStrategies.Utf8ToStringIndexed(stringDictionary);
}
@Override
public Indexed getLongDictionary()
{
return longDictionary;
}
@Override
public Indexed getDoubleDictionary()
{
return doubleDictionary;
}
@Override
public Indexed