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 11 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,24 @@ public interface TableDataService {
@NotNull
TableLocationProvider getTableLocationProvider(@NotNull TableKey tableKey);

/**
* Request the raw {@link TableLocationProvider} from this service that will provide the {@link TableLocation} for
* {@code tableKey} and {@code tableLocationKey} if the location may exist. A raw {@link TableLocationProvider} does
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
* 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 A raw {@link TableLocationProvider} for the specified {@link TableKey} and {@link TableLocationKey}, or
* {@code null} if either key is not present
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
* @implSpec Non-raw {@link TableDataService TableDataServices} must implement this method.
* @throws TableDataException if the TableLocationKey is provided by more than one TableLocationProvider
*/
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
@Nullable
default TableLocationProvider getRawTableLocationProvider(@NotNull TableKey tableKey,
@NotNull 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 TableKey tableKey,
@NotNull TableLocationKey tableLocationKey) {
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
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 TableKey tableKey,
@NotNull 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