io.deephaven.engine.table.impl.sources.aggregate.AggregateColumnSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.table.impl.sources.aggregate;
import io.deephaven.vector.Vector;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.table.impl.MutableColumnSourceGetDefaults;
import io.deephaven.engine.table.impl.sources.UngroupableColumnSource;
import io.deephaven.engine.table.impl.sources.UngroupedColumnSource;
import io.deephaven.util.SimpleTypeMap;
import io.deephaven.engine.rowset.RowSet;
import org.jetbrains.annotations.NotNull;
import java.util.function.BiFunction;
/**
* {@link ColumnSource} and {@link UngroupableColumnSource} interface for aggregation result columns.
*/
public interface AggregateColumnSource, COMPONENT_TYPE>
extends UngroupableColumnSource, MutableColumnSourceGetDefaults.ForObject {
UngroupedColumnSource ungrouped();
static , DATA_TYPE> AggregateColumnSource make(
@NotNull final ColumnSource aggregatedSource,
@NotNull final ColumnSource extends RowSet> groupRowSetSource) {
// noinspection unchecked
return (AggregateColumnSource) FactoryHelper.TYPE_TO_CONSTRUCTOR
.get(aggregatedSource.getType()).apply(aggregatedSource, groupRowSetSource);
}
/**
* Returns a sliced aggregate ColumnSource from the provided sources.
*
* @param aggregatedSource the value column source for the aggregation
* @param groupRowSetSource the column source that maps rows to group row sets
* @param startPosSource the column source that maps rows to starting position offsets
* @param endPosSource the column source that maps rows to ending position offsets (exclusive)
*/
static , DATA_TYPE> AggregateColumnSource makeSliced(
@NotNull final ColumnSource aggregatedSource,
@NotNull final ColumnSource extends RowSet> groupRowSetSource,
@NotNull final ColumnSource startPosSource,
@NotNull final ColumnSource endPosSource) {
// noinspection unchecked
return (AggregateColumnSource) FactoryHelper.TYPE_TO_SLICED_CONSTRUCTOR
.get(aggregatedSource.getType())
.apply(aggregatedSource, groupRowSetSource, startPosSource, endPosSource);
}
/**
* Returns a sliced aggregate ColumnSource from the provided sources.
*
* @param aggregatedSource the value column source for the aggregation
* @param groupRowSetSource the column source that maps rows to group row sets
* @param startPosOffset the fixed starting position offset for every row
* @param endPosOffset the fixed ending position offset for every row (exclusive)
*/
static , DATA_TYPE> AggregateColumnSource makeSliced(
@NotNull final ColumnSource aggregatedSource,
@NotNull final ColumnSource extends RowSet> groupRowSetSource,
final long startPosOffset,
final long endPosOffset) {
// noinspection unchecked
return (AggregateColumnSource) FactoryHelper.TYPE_TO_SLICED_CONSTRUCTOR_FIXED
.get(aggregatedSource.getType())
.apply(aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset);
}
/**
* Returns a range aggregated ColumnSource from the provided sources.
*
* @param aggregatedSource The input value ColumnSource for the aggregation, in input row key space
* @param groupRowSetSource ColumnSource of grouped input row sets, in output row key space
* @param startPositionInclusiveSource ColumnSource of starting positions (inclusive), in output row key space
* @param endPositionExclusiveSource ColumnSource of ending positions (exclusive), in output row key space
*/
static , DATA_TYPE> AggregateColumnSource forRangeJoin(
@NotNull final ColumnSource> aggregatedSource,
@NotNull final ColumnSource extends RowSet> groupRowSetSource,
@NotNull final ColumnSource startPositionInclusiveSource,
@NotNull final ColumnSource endPositionExclusiveSource) {
// noinspection unchecked
return (AggregateColumnSource) FactoryHelper.TYPE_TO_RANGE_CONSTRUCTOR
.get(aggregatedSource.getType())
.apply(aggregatedSource, groupRowSetSource, startPositionInclusiveSource, endPositionExclusiveSource);
}
final class FactoryHelper {
private FactoryHelper() {}
@SuppressWarnings({"unchecked", "AutoUnboxing"})
private static final SimpleTypeMap, ColumnSource extends RowSet>, AggregateColumnSource, ?>>> TYPE_TO_CONSTRUCTOR =
SimpleTypeMap.create(
// @formatter:off
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> {
throw new UnsupportedOperationException("Cannot create a primitive boolean ColumnSource");
},
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> new CharAggregateColumnSource((ColumnSource) aggregatedSource, groupRowSetSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> new ByteAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> new ShortAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> new IntAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> new LongAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> new FloatAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> new DoubleAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource) -> new ObjectAggregateColumnSource<>((ColumnSource> ) aggregatedSource, groupRowSetSource)
// @formatter:on
);
@FunctionalInterface
private interface SlicedConstructor {
AggregateColumnSource, ?> apply(
@NotNull ColumnSource> aggregatedSource,
@NotNull ColumnSource extends RowSet> groupRowSetSource,
@NotNull ColumnSource startPosSource,
@NotNull ColumnSource endPosSource);
}
@SuppressWarnings({"unchecked", "AutoUnboxing"})
private static final SimpleTypeMap TYPE_TO_SLICED_CONSTRUCTOR =
SimpleTypeMap.create(
// @formatter:off
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> {
throw new UnsupportedOperationException("Cannot create a primitive boolean ColumnSource");
},
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> new SlicedCharAggregateColumnSource((ColumnSource) aggregatedSource, groupRowSetSource, startPosSource, endPosSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> new SlicedByteAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosSource, endPosSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> new SlicedShortAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosSource, endPosSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> new SlicedIntAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosSource, endPosSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> new SlicedLongAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosSource, endPosSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> new SlicedFloatAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosSource, endPosSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> new SlicedDoubleAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosSource, endPosSource),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final ColumnSource startPosSource, final ColumnSource endPosSource) -> new SlicedObjectAggregateColumnSource<>((ColumnSource> ) aggregatedSource, groupRowSetSource, startPosSource, endPosSource)
// @formatter:on
);
@FunctionalInterface
private interface SlicedConstructorFixedOffset {
AggregateColumnSource, ?> apply(
@NotNull ColumnSource> aggregatedSource,
@NotNull ColumnSource extends RowSet> groupRowSetSource,
long startPosOffset,
long endPosOffset);
}
@SuppressWarnings({"unchecked", "AutoUnboxing"})
private static final SimpleTypeMap TYPE_TO_SLICED_CONSTRUCTOR_FIXED =
SimpleTypeMap.create(
// @formatter:off
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> {
throw new UnsupportedOperationException("Cannot create a primitive boolean ColumnSource");
},
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> new SlicedCharAggregateColumnSource((ColumnSource) aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> new SlicedByteAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> new SlicedShortAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> new SlicedIntAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> new SlicedLongAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> new SlicedFloatAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> new SlicedDoubleAggregateColumnSource((ColumnSource ) aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset),
(final ColumnSource> aggregatedSource, final ColumnSource extends RowSet> groupRowSetSource, final long startPosOffset, final long endPosOffset) -> new SlicedObjectAggregateColumnSource<>((ColumnSource> ) aggregatedSource, groupRowSetSource, startPosOffset, endPosOffset)
// @formatter:on
);
@FunctionalInterface
private interface RangeAggregatedColumnSourceConstructor {
AggregateColumnSource, ?> apply(
@NotNull ColumnSource> aggregatedSource,
@NotNull ColumnSource extends RowSet> groupRowSetSource,
@NotNull ColumnSource startPositionInclusiveSource,
@NotNull ColumnSource endPositionExclusiveSource);
}
@SuppressWarnings({"unchecked", "AutoUnboxing"})
private static final SimpleTypeMap TYPE_TO_RANGE_CONSTRUCTOR =
SimpleTypeMap.create(
// @formatter:off
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> {
throw new UnsupportedOperationException("Cannot create a primitive boolean ColumnSource");
},
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> new RangeAggregateColumnSourceChar((ColumnSource) as, grss, spis, epes),
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> new RangeAggregateColumnSourceByte((ColumnSource ) as, grss, spis, epes),
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> new RangeAggregateColumnSourceShort((ColumnSource ) as, grss, spis, epes),
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> new RangeAggregateColumnSourceInt((ColumnSource ) as, grss, spis, epes),
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> new RangeAggregateColumnSourceLong((ColumnSource ) as, grss, spis, epes),
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> new RangeAggregateColumnSourceFloat((ColumnSource ) as, grss, spis, epes),
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> new RangeAggregateColumnSourceDouble((ColumnSource ) as, grss, spis, epes),
(final ColumnSource> as, final ColumnSource extends RowSet> grss, final ColumnSource spis, final ColumnSource epes) -> new RangeAggregateColumnSourceObject<>((ColumnSource> ) as, grss, spis, epes)
// @formatter:on
);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy