Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add TableDataService#getRawTableLocationProvider #5966

Merged
merged 20 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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 @@ -20,6 +20,26 @@ public interface TableDataService {
@NotNull
TableLocationProvider getTableLocationProvider(@NotNull TableKey tableKey);

/**
* Request the single raw {@link TableLocationProvider} from this service that provides 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 provides the {@link TableLocation} for {@code tableKey} and
* {@code tableLocationKey}, or {@code null} if there is none
* @implSpec Non-raw {@link TableDataService TableDataServices} must implement this method to provide a single raw
* {@link TableLocationProvider} or throw a {@link TableDataException} if there is ambiguity.
* @throws TableDataException If the {@link TableLocation} is provided by more than one
* {@link TableLocationProvider}
*/
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
@Nullable
default TableLocationProvider getRawTableLocationProvider(@NotNull final TableKey tableKey,
@NotNull final TableLocationKey tableLocationKey) {
return getTableLocationProvider(tableKey);
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Forget all state for subsequent requests for all tables.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@ 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 (tlpCandidate.hasTableLocationKey(tableLocationKey)) {
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);
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void reset() {
super.reset();
Expand Down