Skip to content

Commit

Permalink
feat: Add TableDataService#getRawTableLocationProvider (#5966)
Browse files Browse the repository at this point in the history
Satisfies #6001.

---------

Co-authored-by: Ryan Caudy <[email protected]>
Co-authored-by: Darin Petty <[email protected]>
  • Loading branch information
3 people authored Sep 5, 2024
1 parent ea0dcb2 commit b748158
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ public interface TableDataService {
@NotNull
TableLocationProvider getTableLocationProvider(@NotNull TableKey tableKey);

/**
* Request the single raw {@link TableLocationProvider} from this service that has the {@link TableLocation} for
* {@code tableKey} and {@code tableLocationKey}. A raw {@link TableLocationProvider} does not compose multiple
* {@link TableLocationProvider TableLocationProviders} or delegate to other implementations.
*
* @param tableKey The {@link TableKey} to lookup
* @param tableLocationKey The {@link TableLocationKey} to lookup
* @return The raw {@link TableLocationProvider} that has the {@link TableLocation} for {@code tableKey} and
* {@code tableLocationKey}, or {@code null} if there is none
* @throws TableDataException If more than one {@link TableLocationProvider} has the {@link TableLocation}
*
*/
@Nullable
TableLocationProvider getRawTableLocationProvider(@NotNull final TableKey tableKey,
@NotNull final TableLocationKey tableLocationKey);

/**
* Forget all state for subsequent requests for all tables.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.deephaven.engine.table.impl.locations.TableDataService;
import io.deephaven.engine.table.impl.locations.TableKey;
import io.deephaven.engine.table.impl.locations.TableLocationKey;
import io.deephaven.engine.table.impl.locations.TableLocationProvider;
import io.deephaven.hash.KeyedObjectHashMap;
import io.deephaven.hash.KeyedObjectKey;
Expand Down Expand Up @@ -41,6 +42,18 @@ public final TableLocationProvider getTableLocationProvider(@NotNull final Table
return tableLocationProviders.putIfAbsent(tableKey, this::makeTableLocationProvider);
}

@Override
@Nullable
public TableLocationProvider getRawTableLocationProvider(@NotNull TableKey tableKey,
@NotNull TableLocationKey tableLocationKey) {
final TableLocationProvider tableLocationProvider = tableLocationProviders.get(tableKey);
if (tableLocationProvider == null || !tableLocationProvider.hasTableLocationKey(tableLocationKey)) {
return null;
}

return tableLocationProvider;
}

@Override
public void reset() {
tableLocationProviders.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ public CompositeTableDataService(@NotNull String name, @NotNull final ServiceSel
this.serviceSelector = Require.neqNull(serviceSelector, "serviceSelector");
}

@Override
@Nullable
public TableLocationProvider getRawTableLocationProvider(@NotNull final TableKey tableKey,
@NotNull final TableLocationKey tableLocationKey) {
final TableDataService[] services = serviceSelector.call(tableKey);

if (services == null || services.length == 0) {
return null;
}

TableLocationProvider tlp = null;
for (final TableDataService service : services) {
final TableLocationProvider tlpCandidate = service.getRawTableLocationProvider(tableKey, tableLocationKey);
if (tlpCandidate == null) {
continue;
}

if (tlp != null) {
throw new TableDataException(
"TableDataService elements " + tlpCandidate.getName() + " and " + tlp.getName()
+ " both contain " + tableLocationKey + ". Full TableDataService configuration:\n"
+ Formatter.formatTableDataService(CompositeTableDataService.this.toString()));
}

tlp = tlpCandidate;
}

return tlp;
}

@Override
public void reset() {
super.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public FilteredTableDataService(@NotNull final TableDataService serviceToFilter,
this.locationKeyFilter = Require.neqNull(locationKeyFilter, "locationKeyFilter");
}

@Override
@Nullable
public TableLocationProvider getRawTableLocationProvider(@NotNull final TableKey tableKey,
@NotNull final TableLocationKey tableLocationKey) {
if (!locationKeyFilter.accept(tableLocationKey)) {
return null;
}

return serviceToFilter.getRawTableLocationProvider(tableKey, tableLocationKey);
}

@Override
public void reset() {
super.reset();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.engine.table.impl;

import io.deephaven.api.SortColumn;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.table.BasicDataIndex;
import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.engine.table.impl.locations.ColumnLocation;
import io.deephaven.engine.table.impl.locations.TableKey;
import io.deephaven.engine.table.impl.locations.TableLocation;
import io.deephaven.engine.table.impl.locations.TableLocationKey;
import io.deephaven.engine.table.impl.locations.impl.AbstractTableLocation;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionByte;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionChar;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionDouble;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionFloat;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionInt;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionLong;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionObject;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionShort;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public final class DummyTableLocation extends AbstractTableLocation {

public DummyTableLocation(@NotNull final TableKey tableKey,
@NotNull final TableLocationKey tableLocationKey) {
super(tableKey, tableLocationKey, false);
}

@Override
public void refresh() {}

@Override
public @NotNull List<SortColumn> getSortedColumns() {
return List.of();
}

@Override
@NotNull
public List<String[]> getDataIndexColumns() {
return List.of();
}

@Override
public boolean hasDataIndex(@NotNull final String... columns) {
return false;
}

@NotNull
@Override
protected ColumnLocation makeColumnLocation(@NotNull final String name) {
return new ColumnLocation() {
@NotNull
@Override
public TableLocation getTableLocation() {
return DummyTableLocation.this;
}

@NotNull
@Override
public String getName() {
return name;
}

@Override
public boolean exists() {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionChar<Values> makeColumnRegionChar(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionByte<Values> makeColumnRegionByte(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionShort<Values> makeColumnRegionShort(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionInt<Values> makeColumnRegionInt(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionLong<Values> makeColumnRegionLong(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionFloat<Values> makeColumnRegionFloat(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionDouble<Values> makeColumnRegionDouble(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public <TYPE> ColumnRegionObject<TYPE, Values> makeColumnRegionObject(
@NotNull final ColumnDefinition<TYPE> columnDefinition) {
throw new UnsupportedOperationException();
}

};
}

@Override
@Nullable
public BasicDataIndex loadDataIndex(@NotNull final String... columns) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
//
package io.deephaven.engine.table.impl;

import io.deephaven.api.SortColumn;
import io.deephaven.api.filter.Filter;
import io.deephaven.base.verify.Assert;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.primitive.iterator.CloseableIterator;
import io.deephaven.engine.rowset.RowSet;
import io.deephaven.engine.table.*;
Expand All @@ -17,17 +15,11 @@
import io.deephaven.engine.testutil.TstUtils;
import io.deephaven.engine.testutil.junit4.EngineCleanup;
import io.deephaven.time.DateTimeUtils;
import io.deephaven.engine.table.impl.locations.ColumnLocation;
import io.deephaven.engine.table.impl.locations.TableKey;
import io.deephaven.engine.table.impl.locations.TableLocation;
import io.deephaven.engine.table.impl.locations.TableLocationKey;
import io.deephaven.engine.table.impl.locations.impl.*;
import io.deephaven.engine.table.impl.select.MatchFilter;
import io.deephaven.engine.table.impl.select.WhereFilter;
import io.deephaven.engine.table.impl.sources.regioned.*;
import io.deephaven.engine.rowset.RowSetFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Rule;
import org.junit.Test;

Expand Down Expand Up @@ -135,109 +127,4 @@ public void testEverything() {

TstUtils.assertTableEquals(expected.selectDistinct(), result.selectDistinct());
}

private static final class DummyTableLocation extends AbstractTableLocation {

private DummyTableLocation(@NotNull final TableKey tableKey,
@NotNull final TableLocationKey tableLocationKey) {
super(tableKey, tableLocationKey, false);
}

@Override
public void refresh() {}

@Override
public @NotNull List<SortColumn> getSortedColumns() {
return List.of();
}

@Override
@NotNull
public List<String[]> getDataIndexColumns() {
return List.of();
}

@Override
public boolean hasDataIndex(@NotNull final String... columns) {
return false;
}

@NotNull
@Override
protected ColumnLocation makeColumnLocation(@NotNull final String name) {
return new ColumnLocation() {
@NotNull
@Override
public TableLocation getTableLocation() {
return DummyTableLocation.this;
}

@NotNull
@Override
public String getName() {
return name;
}

@Override
public boolean exists() {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionChar<Values> makeColumnRegionChar(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionByte<Values> makeColumnRegionByte(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionShort<Values> makeColumnRegionShort(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionInt<Values> makeColumnRegionInt(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionLong<Values> makeColumnRegionLong(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionFloat<Values> makeColumnRegionFloat(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionDouble<Values> makeColumnRegionDouble(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public <TYPE> ColumnRegionObject<TYPE, Values> makeColumnRegionObject(
@NotNull final ColumnDefinition<TYPE> columnDefinition) {
throw new UnsupportedOperationException();
}

};
}

@Override
@Nullable
public BasicDataIndex loadDataIndex(@NotNull final String... columns) {
throw new UnsupportedOperationException();
}
}
}
Loading

0 comments on commit b748158

Please sign in to comment.