make ComplexColumn an interface and ExtensionPoint (#7633)

* make ComplexColumn an interface and ExtensionPoint

* incorporate review comments

* make ColumnValueSelector @ExtensionPoint

* more java docs

* add close() method to ComplexColumn interface
This commit is contained in:
Himanshu 2019-05-15 20:59:55 -07:00 committed by GitHub
parent 3df364c472
commit 8687f424f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 121 additions and 43 deletions

View File

@ -19,7 +19,7 @@
package org.apache.druid.segment; package org.apache.druid.segment;
import org.apache.druid.guice.annotations.PublicApi; import org.apache.druid.guice.annotations.ExtensionPoint;
import org.apache.druid.query.monomorphicprocessing.CalledFromHotLoop; import org.apache.druid.query.monomorphicprocessing.CalledFromHotLoop;
import org.apache.druid.query.monomorphicprocessing.HotLoopCallee; import org.apache.druid.query.monomorphicprocessing.HotLoopCallee;
@ -30,7 +30,7 @@ import org.apache.druid.query.monomorphicprocessing.HotLoopCallee;
* *
* All implementations of this interface MUST also implement {@link ColumnValueSelector}. * All implementations of this interface MUST also implement {@link ColumnValueSelector}.
*/ */
@PublicApi @ExtensionPoint
public interface BaseDoubleColumnValueSelector extends HotLoopCallee, BaseNullableColumnValueSelector public interface BaseDoubleColumnValueSelector extends HotLoopCallee, BaseNullableColumnValueSelector
{ {
@CalledFromHotLoop @CalledFromHotLoop

View File

@ -19,7 +19,7 @@
package org.apache.druid.segment; package org.apache.druid.segment;
import org.apache.druid.guice.annotations.PublicApi; import org.apache.druid.guice.annotations.ExtensionPoint;
import org.apache.druid.query.monomorphicprocessing.CalledFromHotLoop; import org.apache.druid.query.monomorphicprocessing.CalledFromHotLoop;
import org.apache.druid.query.monomorphicprocessing.HotLoopCallee; import org.apache.druid.query.monomorphicprocessing.HotLoopCallee;
@ -30,7 +30,7 @@ import org.apache.druid.query.monomorphicprocessing.HotLoopCallee;
* *
* All implementations of this interface MUST also implement {@link ColumnValueSelector}. * All implementations of this interface MUST also implement {@link ColumnValueSelector}.
*/ */
@PublicApi @ExtensionPoint
public interface BaseFloatColumnValueSelector extends HotLoopCallee, BaseNullableColumnValueSelector public interface BaseFloatColumnValueSelector extends HotLoopCallee, BaseNullableColumnValueSelector
{ {
@CalledFromHotLoop @CalledFromHotLoop

View File

@ -19,7 +19,7 @@
package org.apache.druid.segment; package org.apache.druid.segment;
import org.apache.druid.guice.annotations.PublicApi; import org.apache.druid.guice.annotations.ExtensionPoint;
import org.apache.druid.query.monomorphicprocessing.CalledFromHotLoop; import org.apache.druid.query.monomorphicprocessing.CalledFromHotLoop;
import org.apache.druid.query.monomorphicprocessing.HotLoopCallee; import org.apache.druid.query.monomorphicprocessing.HotLoopCallee;
@ -30,7 +30,7 @@ import org.apache.druid.query.monomorphicprocessing.HotLoopCallee;
* *
* All implementations of this interface MUST also implement {@link ColumnValueSelector}. * All implementations of this interface MUST also implement {@link ColumnValueSelector}.
*/ */
@PublicApi @ExtensionPoint
public interface BaseLongColumnValueSelector extends HotLoopCallee, BaseNullableColumnValueSelector public interface BaseLongColumnValueSelector extends HotLoopCallee, BaseNullableColumnValueSelector
{ {
@CalledFromHotLoop @CalledFromHotLoop

View File

@ -19,7 +19,7 @@
package org.apache.druid.segment; package org.apache.druid.segment;
import org.apache.druid.guice.annotations.PublicApi; import org.apache.druid.guice.annotations.ExtensionPoint;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -30,7 +30,7 @@ import javax.annotation.Nullable;
* *
* All implementations of this interface MUST also implement {@link ColumnValueSelector}. * All implementations of this interface MUST also implement {@link ColumnValueSelector}.
*/ */
@PublicApi @ExtensionPoint
public interface BaseObjectColumnValueSelector<T> extends BaseNullableColumnValueSelector public interface BaseObjectColumnValueSelector<T> extends BaseNullableColumnValueSelector
{ {
@Nullable @Nullable

View File

@ -19,7 +19,7 @@
package org.apache.druid.segment; package org.apache.druid.segment;
import org.apache.druid.guice.annotations.PublicApi; import org.apache.druid.guice.annotations.ExtensionPoint;
/** /**
* Base type for interfaces that manage column value selection, e.g. {@link DimensionSelector}, {@link * Base type for interfaces that manage column value selection, e.g. {@link DimensionSelector}, {@link
@ -33,7 +33,7 @@ import org.apache.druid.guice.annotations.PublicApi;
* methods and null from {@link #getObject()}, should always be an instance of {@link NilColumnValueSelector}. * methods and null from {@link #getObject()}, should always be an instance of {@link NilColumnValueSelector}.
* `selector instanceof NilColumnValueSelector` is the recommended way to check for this condition. * `selector instanceof NilColumnValueSelector` is the recommended way to check for this condition.
*/ */
@PublicApi @ExtensionPoint
public interface ColumnValueSelector<T> extends BaseLongColumnValueSelector, BaseDoubleColumnValueSelector, public interface ColumnValueSelector<T> extends BaseLongColumnValueSelector, BaseDoubleColumnValueSelector,
BaseFloatColumnValueSelector, BaseObjectColumnValueSelector<T> BaseFloatColumnValueSelector, BaseObjectColumnValueSelector<T>
{ {

View File

@ -19,45 +19,60 @@
package org.apache.druid.segment.column; package org.apache.druid.segment.column;
import org.apache.druid.guice.annotations.ExtensionPoint;
import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector; import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import org.apache.druid.segment.ColumnValueSelector; import org.apache.druid.segment.ColumnValueSelector;
import org.apache.druid.segment.ObjectColumnSelector; import org.apache.druid.segment.ObjectColumnSelector;
import org.apache.druid.segment.data.GenericIndexed;
import org.apache.druid.segment.data.ReadableOffset; import org.apache.druid.segment.data.ReadableOffset;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
*/ * This interface represents a complex column and can be implemented by druid extension writer of a custom column
public class ComplexColumn implements BaseColumn * with arbitrary serialization instead of a custom column that serializes rows of objects serialized using
* {@link org.apache.druid.segment.data.GenericIndexed} class which is default implementation of "writeToXXX" methods in
* {@link org.apache.druid.segment.serde.ComplexColumnSerializer}. In that case {@link GenericIndexedBasedComplexColumn}
* should be used.
*/
@ExtensionPoint
public interface ComplexColumn extends BaseColumn
{ {
private final GenericIndexed<?> index; /**
private final String typeName; * @return Class of objects returned on calls to {@link ComplexColumn#getRowValue(int)} .
*/
Class<?> getClazz();
public ComplexColumn(String typeName, GenericIndexed<?> index) /**
{ * @return Typename associated with this column.
this.index = index; */
this.typeName = typeName; String getTypeName();
}
public String getTypeName() /**
{ * Return rows in the column.
return typeName; * @param rowNum the row number
} * @return row object of type same as {@link ComplexColumn#getClazz()} } at row number "rowNum" .
*/
Object getRowValue(int rowNum);
@Nullable /**
public Object getRowValue(int rowNum) * @return serialized size (in bytes) of this column.
{ */
return index.get(rowNum); int getLength();
}
public int getLength()
{
return index.size();
}
/**
* Close and release any resources associated with this column.
*/
@Override @Override
public ColumnValueSelector<?> makeColumnValueSelector(ReadableOffset offset) void close();
/**
* Optionally overridden when complex column serialization is not based on default serialization based
* on {@link org.apache.druid.segment.data.GenericIndexed} in {@link org.apache.druid.segment.serde.ComplexColumnSerializer}.
* @param offset object to retrieve row number
* @return the {@link ColumnValueSelector} object
*/
@Override
default ColumnValueSelector<?> makeColumnValueSelector(ReadableOffset offset)
{ {
return new ObjectColumnSelector() return new ObjectColumnSelector()
{ {
@ -71,7 +86,7 @@ public class ComplexColumn implements BaseColumn
@Override @Override
public Class classOfObject() public Class classOfObject()
{ {
return index.getClazz(); return getClazz();
} }
@Override @Override
@ -81,10 +96,4 @@ public class ComplexColumn implements BaseColumn
} }
}; };
} }
@Override
public void close()
{
// nothing to close
}
} }

View File

@ -0,0 +1,68 @@
/*
* 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.segment.data.GenericIndexed;
/**
* Implementation of {@link ComplexColumn} to be used when complex column serialization is done by using
* {@link GenericIndexed} by using default implementations of "writeToXXX" methods in
* {@link org.apache.druid.segment.serde.ComplexColumnSerializer}
*/
public class GenericIndexedBasedComplexColumn implements ComplexColumn
{
private final GenericIndexed<?> index;
private final String typeName;
public GenericIndexedBasedComplexColumn(String typeName, GenericIndexed<?> index)
{
this.index = index;
this.typeName = typeName;
}
@Override
public Class<?> getClazz()
{
return index.getClazz();
}
@Override
public String getTypeName()
{
return typeName;
}
@Override
public Object getRowValue(int rowNum)
{
return index.get(rowNum);
}
@Override
public int getLength()
{
return index.size();
}
@Override
public void close()
{
}
}

View File

@ -21,6 +21,7 @@ package org.apache.druid.segment.serde;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import org.apache.druid.segment.column.ComplexColumn; import org.apache.druid.segment.column.ComplexColumn;
import org.apache.druid.segment.column.GenericIndexedBasedComplexColumn;
import org.apache.druid.segment.data.GenericIndexed; import org.apache.druid.segment.data.GenericIndexed;
/** /**
@ -39,6 +40,6 @@ public class ComplexColumnPartSupplier implements Supplier<ComplexColumn>
@Override @Override
public ComplexColumn get() public ComplexColumn get()
{ {
return new ComplexColumn(typeName, complexType); return new GenericIndexedBasedComplexColumn(typeName, complexType);
} }
} }