Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -71,7 +71,7 @@ public void testSerde() throws IOException
data
)
);
String expected = "{\"numRowsRead\":1123,\"numRowsIndexed\":1112,\"logicalDimensions\":[{\"type\":\"string\",\"name\":\"dim1\",\"multiValueHandling\":\"SORTED_ARRAY\",\"createBitmapIndex\":true}],\"physicalDimensions\":[{\"type\":\"json\",\"name\":\"dim1\",\"multiValueHandling\":\"SORTED_ARRAY\",\"createBitmapIndex\":true}],\"logicalSegmentSchema\":[{\"name\":\"__time\",\"type\":\"LONG\"},{\"name\":\"dim1\",\"type\":\"STRING\"},{\"name\":\"met1\",\"type\":\"LONG\"}],\"data\":[{\"input\":{\"row1\":\"val1\"},\"parsed\":{\"t\":123456,\"dim1\":\"foo\",\"met1\":6}},{\"input\":{\"row2\":\"val2\"},\"parsed\":{\"t\":123457,\"dim1\":\"foo2\",\"met1\":7}},{\"input\":{\"row3\":\"val3\"},\"unparseable\":true,\"error\":\"Could not parse\"}]}";
String expected = "{\"numRowsRead\":1123,\"numRowsIndexed\":1112,\"logicalDimensions\":[{\"type\":\"string\",\"name\":\"dim1\",\"multiValueHandling\":\"SORTED_ARRAY\",\"createBitmapIndex\":true}],\"physicalDimensions\":[{\"type\":\"auto\",\"name\":\"dim1\",\"multiValueHandling\":\"SORTED_ARRAY\",\"createBitmapIndex\":true}],\"logicalSegmentSchema\":[{\"name\":\"__time\",\"type\":\"LONG\"},{\"name\":\"dim1\",\"type\":\"STRING\"},{\"name\":\"met1\",\"type\":\"LONG\"}],\"data\":[{\"input\":{\"row1\":\"val1\"},\"parsed\":{\"t\":123456,\"dim1\":\"foo\",\"met1\":6}},{\"input\":{\"row2\":\"val2\"},\"parsed\":{\"t\":123457,\"dim1\":\"foo2\",\"met1\":7}},{\"input\":{\"row3\":\"val3\"},\"unparseable\":true,\"error\":\"Could not parse\"}]}";

Assert.assertEquals(expected, out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.druid.segment.AutoTypeColumnSchema;
import org.apache.druid.segment.DimensionHandler;
import org.apache.druid.segment.DimensionHandlerUtils;
import org.apache.druid.segment.NestedDataColumnSchema;
import org.apache.druid.segment.column.ColumnType;
import org.apache.druid.segment.column.TypeSignature;
import org.apache.druid.segment.column.ValueType;
Expand All @@ -50,7 +51,7 @@
@JsonSubTypes.Type(name = DimensionSchema.FLOAT_TYPE_NAME, value = FloatDimensionSchema.class),
@JsonSubTypes.Type(name = DimensionSchema.DOUBLE_TYPE_NAME, value = DoubleDimensionSchema.class),
@JsonSubTypes.Type(name = DimensionSchema.SPATIAL_TYPE_NAME, value = NewSpatialDimensionSchema.class),
@JsonSubTypes.Type(name = NestedDataComplexTypeSerde.TYPE_NAME, value = AutoTypeColumnSchema.class),
@JsonSubTypes.Type(name = NestedDataComplexTypeSerde.TYPE_NAME, value = NestedDataColumnSchema.class),
@JsonSubTypes.Type(name = AutoTypeColumnSchema.TYPE, value = AutoTypeColumnSchema.class)
})
public abstract class DimensionSchema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Binder;
import com.google.inject.Provides;
import org.apache.druid.initialization.DruidModule;
import org.apache.druid.segment.DefaultColumnFormatConfig;
import org.apache.druid.segment.DimensionHandler;
import org.apache.druid.segment.DimensionHandlerProvider;
import org.apache.druid.segment.DimensionHandlerUtils;
import org.apache.druid.segment.NestedCommonFormatColumnHandler;
import org.apache.druid.segment.NestedDataColumnHandlerV4;
import org.apache.druid.segment.nested.NestedDataComplexTypeSerde;
import org.apache.druid.segment.nested.StructuredData;
import org.apache.druid.segment.nested.StructuredDataJsonSerializer;
Expand All @@ -47,20 +52,28 @@ public List<? extends Module> getJacksonModules()
@Override
public void configure(Binder binder)
{
registerHandlersAndSerde();
registerSerde();
// binding our side effect class to the lifecycle causes registerHandler to be called on service start, allowing
// use of the config to get the system default format version
LifecycleModule.register(binder, SideEffectHandlerRegisterer.class);
}


@VisibleForTesting
public static void registerHandlersAndSerde()
@Provides
@LazySingleton
public SideEffectHandlerRegisterer registerHandler(DefaultColumnFormatConfig formatsConfig)
{
if (ComplexMetrics.getSerdeForType(NestedDataComplexTypeSerde.TYPE_NAME) == null) {
ComplexMetrics.registerSerde(NestedDataComplexTypeSerde.TYPE_NAME, NestedDataComplexTypeSerde.INSTANCE);
if (formatsConfig.getNestedColumnFormatVersion() != null && formatsConfig.getNestedColumnFormatVersion() == 4) {
DimensionHandlerUtils.registerDimensionHandlerProvider(
NestedDataComplexTypeSerde.TYPE_NAME,
new NestedColumnV4HandlerProvider()
);
} else {
DimensionHandlerUtils.registerDimensionHandlerProvider(
NestedDataComplexTypeSerde.TYPE_NAME,
new NestedCommonFormatHandlerProvider()
);
}
DimensionHandlerUtils.registerDimensionHandlerProvider(
NestedDataComplexTypeSerde.TYPE_NAME,
NestedCommonFormatColumnHandler::new
);
return new SideEffectHandlerRegisterer();
}

public static List<SimpleModule> getJacksonModulesList()
Expand All @@ -71,4 +84,56 @@ public static List<SimpleModule> getJacksonModulesList()
.addSerializer(StructuredData.class, new StructuredDataJsonSerializer())
);
}

/**
* Helper for wiring stuff up for tests
*/
@VisibleForTesting
public static void registerHandlersAndSerde()
{
registerSerde();
DimensionHandlerUtils.registerDimensionHandlerProvider(
NestedDataComplexTypeSerde.TYPE_NAME,
new NestedCommonFormatHandlerProvider()
);
}

private static void registerSerde()
{
if (ComplexMetrics.getSerdeForType(NestedDataComplexTypeSerde.TYPE_NAME) == null) {
ComplexMetrics.registerSerde(NestedDataComplexTypeSerde.TYPE_NAME, NestedDataComplexTypeSerde.INSTANCE);
}
}

public static class NestedCommonFormatHandlerProvider
implements DimensionHandlerProvider<StructuredData, StructuredData, StructuredData>
{

@Override
public DimensionHandler<StructuredData, StructuredData, StructuredData> get(String dimensionName)
{
return new NestedCommonFormatColumnHandler(dimensionName);
}
}

public static class NestedColumnV4HandlerProvider
implements DimensionHandlerProvider<StructuredData, StructuredData, StructuredData>
{

@Override
public DimensionHandler<StructuredData, StructuredData, StructuredData> get(String dimensionName)
{
return new NestedDataColumnHandlerV4(dimensionName);
}
}
/**
* this is used as a vehicle to register the correct version of the system default nested column handler by side
* effect with the help of binding to {@link org.apache.druid.java.util.common.lifecycle.Lifecycle} so that
* {@link #registerHandler(DefaultColumnFormatConfig)} can be called with the injected
* {@link DefaultColumnFormatConfig}.
*/
public static class SideEffectHandlerRegisterer
{
// nothing to see here
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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 com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.error.DruidException;

import javax.annotation.Nullable;
import java.util.Objects;

public class DefaultColumnFormatConfig
{
public static void validateNestedFormatVersion(@Nullable Integer formatVersion)
{
if (formatVersion != null) {
if (formatVersion < 4 || formatVersion > 5) {
throw DruidException.forPersona(DruidException.Persona.USER)
.ofCategory(DruidException.Category.INVALID_INPUT)
.build("Unsupported nested column format version[%s]", formatVersion);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - can you add in the error message that supported values are 4 and 5?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think im going to skip this for now to not churn through CI again, and also seems like we should find some programmatic way to list what versions are supported so the error messaging doesn't become stale if we add another version. Also the versions are still kind of confusing so idk how I feel about exposing them too much, 4 makes sense, but 5 is a virtual version since 5 is really version 0 of the new nested common format introduced by 'auto'.

}
}
}

@JsonProperty("nestedColumnFormatVersion")
private final Integer nestedColumnFormatVersion;

@JsonCreator
public DefaultColumnFormatConfig(
@JsonProperty("nestedColumnFormatVersion") @Nullable Integer nestedColumnFormatVersion
)
{
this.nestedColumnFormatVersion = nestedColumnFormatVersion;
validateNestedFormatVersion(this.nestedColumnFormatVersion);
}

@Nullable
@JsonProperty("nestedColumnFormatVersion")
public Integer getNestedColumnFormatVersion()
{
return nestedColumnFormatVersion;
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DefaultColumnFormatConfig that = (DefaultColumnFormatConfig) o;
return Objects.equals(nestedColumnFormatVersion, that.nestedColumnFormatVersion);
}

@Override
public int hashCode()
{
return Objects.hash(nestedColumnFormatVersion);
}

@Override
public String toString()
{
return "DefaultColumnFormatConfig{" +
"nestedColumnFormatVersion=" + nestedColumnFormatVersion +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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.data.input.impl.DimensionSchema;
import org.apache.druid.java.util.common.io.Closer;
import org.apache.druid.query.dimension.DefaultDimensionSpec;
import org.apache.druid.query.dimension.DimensionSpec;
import org.apache.druid.segment.column.ColumnCapabilities;
import org.apache.druid.segment.column.ColumnType;
import org.apache.druid.segment.nested.StructuredData;
import org.apache.druid.segment.selector.settable.SettableColumnValueSelector;
import org.apache.druid.segment.selector.settable.SettableObjectColumnValueSelector;
import org.apache.druid.segment.writeout.SegmentWriteOutMedium;

import java.util.Comparator;

public class NestedDataColumnHandlerV4 implements DimensionHandler<StructuredData, StructuredData, StructuredData>
{
private static Comparator<ColumnValueSelector> COMPARATOR = (s1, s2) ->
StructuredData.COMPARATOR.compare(
StructuredData.wrap(s1.getObject()),
StructuredData.wrap(s2.getObject())
);

private final String name;

public NestedDataColumnHandlerV4(String name)
{
this.name = name;
}

@Override
public String getDimensionName()
{
return name;
}

@Override
public DimensionSpec getDimensionSpec()
{
return new DefaultDimensionSpec(name, name, ColumnType.NESTED_DATA);
}

@Override
public DimensionSchema getDimensionSchema(ColumnCapabilities capabilities)
{
return new NestedDataColumnSchema(name, 4);
}

@Override
public DimensionIndexer<StructuredData, StructuredData, StructuredData> makeIndexer(boolean useMaxMemoryEstimates)
{
return new NestedDataColumnIndexerV4();
}

@Override
public DimensionMergerV9 makeMerger(
IndexSpec indexSpec,
SegmentWriteOutMedium segmentWriteOutMedium,
ColumnCapabilities capabilities,
ProgressIndicator progress,
Closer closer
)
{
return new NestedDataColumnMergerV4(name, indexSpec, segmentWriteOutMedium, closer);
}

@Override
public int getLengthOfEncodedKeyComponent(StructuredData dimVals)
{
// this is called in one place, OnheapIncrementalIndex, where returning 0 here means the value is null
// so the actual value we return here doesn't matter. we should consider refactoring this to a boolean
return 1;
}

@Override
public Comparator<ColumnValueSelector> getEncodedValueSelectorComparator()
{
return COMPARATOR;
}

@Override
public SettableColumnValueSelector makeNewSettableEncodedValueSelector()
{
return new SettableObjectColumnValueSelector();
}
}
Loading