Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
262aa0e
better type tracking: add typed postaggs, finalized types for agg fac…
clintropolis Apr 7, 2020
a27a4c8
more javadoc
clintropolis Apr 7, 2020
f2aa12f
adjustments
clintropolis Apr 8, 2020
8a59a1f
Merge remote-tracking branch 'upstream/master' into there-can-be-only…
clintropolis Apr 19, 2020
c81ba6a
transition to getTypeName to be used exclusively for complex types
clintropolis Apr 19, 2020
702b548
remove unused fn
clintropolis Apr 19, 2020
21067bc
adjust
clintropolis Apr 19, 2020
da0936c
Merge remote-tracking branch 'upstream/master' into there-can-be-only…
clintropolis Aug 14, 2020
051f53f
Merge remote-tracking branch 'upstream/master' into there-can-be-only…
clintropolis Aug 17, 2020
d01fb36
Merge remote-tracking branch 'upstream/master' into there-can-be-only…
clintropolis Aug 17, 2020
3aa9958
more better
clintropolis Aug 18, 2020
bbf60e2
rename getTypeName to getComplexTypeName
clintropolis Aug 18, 2020
9cbb602
setup expression post agg for type inference existing
clintropolis Aug 19, 2020
0c81735
more javadocs
clintropolis Aug 19, 2020
2c0347f
Merge remote-tracking branch 'upstream/master' into there-can-be-only…
clintropolis Aug 24, 2020
c4371c8
fixup
clintropolis Aug 24, 2020
1e686d8
oops
clintropolis Aug 24, 2020
881954f
more test
clintropolis Aug 24, 2020
dc27526
more test
clintropolis Aug 24, 2020
6eee25a
more comments/javadoc
clintropolis Aug 25, 2020
0c7ba70
nulls
clintropolis Aug 25, 2020
376728a
explicitly handle only numeric and complex aggregators for incrementa…
clintropolis Aug 25, 2020
59515b4
checkstyle
clintropolis Aug 25, 2020
0d709ac
more tests
clintropolis Aug 25, 2020
207f448
adjust
clintropolis Aug 25, 2020
10e2f3e
more tests to showcase difference in behavior
clintropolis Aug 26, 2020
16882b5
timeseries longsum array
clintropolis Aug 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.druid.guice.annotations.PublicApi;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.emitter.EmittingLogger;
import org.apache.druid.segment.column.ValueType;

import java.util.Objects;

Expand All @@ -52,37 +53,6 @@ public abstract class DimensionSchema
public static final String DOUBLE_TYPE_NAME = "double";
private static final EmittingLogger log = new EmittingLogger(DimensionSchema.class);


// main druid and druid-api should really use the same ValueType enum.
// merge them when druid-api is merged back into the main repo

/**
* Should be the same as {@code org.apache.druid.segment.column.ValueType}.
* TODO merge them when druid-api is merged back into the main repo
*/
public enum ValueType
{
FLOAT,
LONG,
STRING,
DOUBLE,
@SuppressWarnings("unused") // used in org.apache.druid.segment.column.ValueType
COMPLEX;

@JsonValue
@Override
public String toString()
{
return StringUtils.toUpperCase(this.name());
}

@JsonCreator
public static ValueType fromString(String name)
{
return valueOf(StringUtils.toUpperCase(name));
}
}

public enum MultiValueHandling
{
SORTED_ARRAY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.segment.column.ValueType;

public class DoubleDimensionSchema extends DimensionSchema
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.segment.column.ValueType;

public class FloatDimensionSchema extends DimensionSchema
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.segment.column.ValueType;


public class LongDimensionSchema extends DimensionSchema
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.segment.column.ValueType;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.segment.column.ValueType;

public class StringDimensionSchema extends DimensionSchema
{
Expand Down
139 changes: 139 additions & 0 deletions core/src/main/java/org/apache/druid/segment/column/ValueType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* 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 com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.druid.java.util.common.StringUtils;

import javax.annotation.Nullable;

/**
* This enumeration defines the Druid type system used to indicate the type of data stored in columns and produced by
* expressions and aggregations, used to allow query processing engine algorithms to compute results, used to compute query result
* row signatures, and all other type needs.
*
* Currently only the primitive types ({@link #isPrimitive()} is true) and {@link #COMPLEX} can be stored in columns
* and are also the only types handled directly by the query engines. Array types can currently be produced by
* expressions and by some post-aggregators, but do not currently have special engine handling, and should be used by
* implementors sparingly until full engine support is in place. Aggregators should never specify array types as their
* output type until the engines fully support these types.
*/
public enum ValueType
{
/**
* 64-bit double precision floating point number primitive type. This type may be used as a grouping key, or as an
* input to any aggregators which support primitive numerical operations like sums, minimums, maximums, etc, as well
* as an input to expression virtual columns.
*/
DOUBLE,
/**
* 32-bit single precision floating point number primitive type. This type may be used as a grouping key, or as an
* input to any aggregators which support primitive numerical operations like sums, minimums, maximums, etc, as well
* as an input to expression virtual columns.
*/
FLOAT,
/**
* 64-bit integer number primitve type. This type may be used as a grouping key, or as an
* input to any aggregators which support primitive numerical operations like sums, minimums, maximums, etc, as well
* as an input to expression virtual columns.
*/
LONG,
/**
* String object type. This type may be used as a grouping key, an input to certain types of complex sketch
* aggregators, and as an input to expression virtual columns. String types might potentially be 'multi-valued' when
* stored in segments, and contextually at various layers of query processing, but this information is not available
* through this enum alone, and must be accompany this type indicator to properly handle.
*/
STRING,
/**
* Array object of 64-bit double precision floating point numbers. This type is not currently supported as a grouping
* key for aggregations, cannot be used as an input for numerical primitive aggregations such as sums, and may have
* limited support as an input among complex type sketch aggregators.
*/
DOUBLE_ARRAY,
/**
* Array object of 64-bit integer numbers. This type is not currently supported as a grouping key for aggregations,
* and may have limited support as an input among complex type sketch aggregators.
*/
LONG_ARRAY,
/**
* Array object of String objects. This type is not currently supported as a grouping key for aggregations,
* and may have limited support as an input among complex type sketch aggregators.
*/
STRING_ARRAY,
/**
* Placeholder for arbitrary 'complex' types, which have a corresponding serializer/deserializer implementation. Note
* that knowing a type is complex alone isn't enough information to work with it directly, and additional information
* in the form of a type name that is registered in the complex type registry must be available to make this type
* meaningful. This type is not currently supported as a grouping key for aggregations, and may not be used as an
* input to expression virtual columns, and might only be supported by the specific aggregators crafted to handle
* this complex type.
*/
COMPLEX;


/**
* Type is a numeric type, not including numeric array types
*/
public boolean isNumeric()
{
return isNumeric(this);
}

/**
* Type is an array type
*/
public boolean isArray()
{
return isArray(this);
}

/**
* Type is a 'primitive' type, which includes the {@link #isNumeric} types and {@link #STRING}, but not
* {@link #COMPLEX} or array types.
*
* Primitive types support being used for grouping to compute aggregates in both group by and top-n query engines,
* while non-primitive types currently do not
*/
public boolean isPrimitive()
{
return this.equals(ValueType.STRING) || isNumeric(this);
}

@Nullable
@JsonCreator
public static ValueType fromString(@Nullable String name)
{
if (name == null) {
return null;
}
return valueOf(StringUtils.toUpperCase(name));
}

public static boolean isNumeric(ValueType type)
{
return type == ValueType.LONG || type == ValueType.FLOAT || type == ValueType.DOUBLE;
}

public static boolean isArray(ValueType type)
{
return type == ValueType.DOUBLE_ARRAY || type == ValueType.LONG_ARRAY || type == ValueType.STRING_ARRAY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.druid.query.dimension.DefaultDimensionSpec;
import org.apache.druid.segment.ColumnSelectorFactory;
import org.apache.druid.segment.DimensionSelector;
import org.apache.druid.segment.column.ValueType;

import javax.annotation.Nullable;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -194,11 +195,28 @@ public byte[] getCacheKey()
}

@Override
public String getTypeName()
public String getComplexTypeName()
{
return "distinctCount";
}

/**
* this aggregator only works on a single segment, so even though it stores a
* {@link org.apache.druid.collections.bitmap.MutableBitmap} while computing, this value never leaves the aggregator
* and {@link DistinctCountAggregator#get} returns an integer for the number of set bits in the bitmap.
*/
@Override
public ValueType getType()
{
return ValueType.LONG;
}

@Override
public ValueType getFinalizedType()
{
return ValueType.LONG;
}

@Override
public int getMaxIntermediateSize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,26 @@ public List<String> requiredFields()
}

@Override
public String getTypeName()
public String getComplexTypeName()
{
return TYPE_NAME;
}

/**
* actual type is {@link MomentSketchWrapper}
*/
@Override
public ValueType getType()
{
return ValueType.COMPLEX;
}

@Override
public ValueType getFinalizedType()
{
return ValueType.COMPLEX;
}

@Override
public int getMaxIntermediateSize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper;
import org.apache.druid.query.aggregation.post.PostAggregatorIds;
import org.apache.druid.query.cache.CacheKeyBuilder;
import org.apache.druid.segment.column.ValueType;

import java.util.Comparator;
import java.util.Map;
Expand Down Expand Up @@ -57,6 +58,12 @@ public String getName()
return name;
}

@Override
public ValueType getType()
{
return ValueType.DOUBLE;
}

@JsonProperty
public PostAggregator getField()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper;
import org.apache.druid.query.aggregation.post.PostAggregatorIds;
import org.apache.druid.query.cache.CacheKeyBuilder;
import org.apache.druid.segment.column.ValueType;

import java.util.Comparator;
import java.util.Map;
Expand Down Expand Up @@ -56,6 +57,12 @@ public String getName()
return name;
}

@Override
public ValueType getType()
{
return ValueType.DOUBLE;
}

@JsonProperty
public PostAggregator getField()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper;
import org.apache.druid.query.aggregation.post.PostAggregatorIds;
import org.apache.druid.query.cache.CacheKeyBuilder;
import org.apache.druid.segment.column.ValueType;

import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -61,6 +62,12 @@ public String getName()
return name;
}

@Override
public ValueType getType()
{
return ValueType.DOUBLE_ARRAY;
}

@JsonProperty
public PostAggregator getField()
{
Expand Down
Loading