All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.engine.table.impl.sources.regioned.RegionedColumnSourceObject Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl.sources.regioned;

import io.deephaven.engine.rowset.RowSequence;
import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.engine.table.impl.locations.ColumnLocation;
import io.deephaven.engine.table.impl.locations.TableDataException;
import io.deephaven.engine.table.impl.locations.TableLocationKey;
import io.deephaven.engine.table.impl.ColumnSourceGetDefaults;
import io.deephaven.chunk.attributes.Values;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

abstract class RegionedColumnSourceObject
        extends RegionedColumnSourceArray>
        implements ColumnSourceGetDefaults.ForObject {

    private RegionedColumnSourceObject(@NotNull final ColumnRegionObject nullRegion,
                                       @NotNull final Class dataType,
                                       @Nullable final Class componentType,
                                       @NotNull final MakeDeferred> makeDeferred) {
        super(nullRegion, dataType, componentType, makeDeferred);
    }

    @Override
    public final DATA_TYPE get(final long rowKey) {
        return (rowKey == RowSequence.NULL_ROW_KEY ? getNullRegion() : lookupRegion(rowKey)).getObject(rowKey);
    }

    public static class AsValues extends RegionedColumnSourceObject {

        public AsValues(@NotNull final Class dataType) {
            this(dataType, null);
        }

        public AsValues(@NotNull final Class dataType, @Nullable final Class componentType) {
            super(ColumnRegionObject.createNull(PARAMETERS.regionMask), dataType, componentType, DeferredColumnRegionObject::new);
        }

        public ColumnRegionObject makeRegion(@NotNull final ColumnDefinition columnDefinition,
                                                                @NotNull final ColumnLocation columnLocation,
                                                                final int regionIndex) {
            if (columnLocation.exists()) {
                //noinspection unchecked
                return (ColumnRegionObject) columnLocation.makeColumnRegionObject(columnDefinition);
            }
            return null;
        }
    }

    static final class Partitioning extends RegionedColumnSourceObject {

        Partitioning(@NotNull final Class dataType) {
            super(ColumnRegionObject.createNull(PARAMETERS.regionMask), dataType, null,
                    (pm, rs) -> rs.get() // No need to interpose a deferred region in this case
            );
        }

        @Override
        public ColumnRegionObject makeRegion(@NotNull final ColumnDefinition columnDefinition,
                                                                @NotNull final ColumnLocation columnLocation,
                                                                final int regionIndex) {
            final TableLocationKey locationKey = columnLocation.getTableLocation().getKey();
            final Object partitioningColumnValue = locationKey.getPartitionValue(columnDefinition.getName());
            if (partitioningColumnValue != null && !getType().isAssignableFrom(partitioningColumnValue.getClass())) {
                throw new TableDataException("Unexpected partitioning column value type for " + columnDefinition.getName()
                        + ": " + partitioningColumnValue + " is not a " + getType() + " at location " + locationKey);
            }
            //noinspection unchecked
            return new ColumnRegionObject.Constant<>(PARAMETERS.regionMask, (DATA_TYPE) partitioningColumnValue);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy