Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -19,6 +19,8 @@ public enum ResponseFormat {

public static final String HEADER = "delta-sharing-capabilities";

private static final String COLUMN_MAPPING_MODE = "delta.columnMapping.mode";

private static final Set<String> KEYS =
Set.of("responseformat", "readerfeatures", "includeendstreamaction");

Expand Down Expand Up @@ -84,6 +86,22 @@ public static void requireReaderFeatures(
}
}

/**
* A table with column mapping on cannot be served to a client that did not advertise the {@code
* columnmapping} reader feature, whatever its protocol lists: the property decides. {@code
* version} is the table version {@code configuration} is of.
*/
public static void requireColumnMappingSupport(
String header, Map<String, String> configuration, long version) {
String mode = configuration == null ? null : configuration.get(COLUMN_MAPPING_MODE);
if (mode != null
&& !mode.equals("none")
&& !advertisedReaderFeatures(header).contains("columnmapping")) {
throw ApiException.invalidParameter(
"Table features " + COLUMN_MAPPING_MODE + " are found in table version: " + version + ".");
}
}

/**
* The capabilities this server knows. Clients advertise ones it does not, such as asyncquery,
* and may send parts without a value; both are ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public void read(
ResponseWriter out = new ResponseWriter(session, table, options, sink)) {
Snapshot snapshot = DeltaSnapshots.open(session, version, timestamp);
SnapshotImpl impl = (SnapshotImpl) snapshot;
DeltaSharingCapabilities.requireColumnMappingSupport(
options.capabilities(), impl.getMetadata().getConfiguration(), snapshot.getVersion());
Comment thread
littlegrasscao marked this conversation as resolved.
Resolved
out.requireReaderFeatures(impl.getProtocol());
Long fileVersion = historical ? snapshot.getVersion() : null;
Long fileTimestamp = historical ? snapshot.getTimestamp(session.engine()) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.delta.kernel.internal.actions.Protocol;
import io.opensharing.asset.table.DeltaSharingCapabilities.ResponseFormat;
import io.opensharing.http.ApiException;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -123,4 +124,33 @@ void queryRequiresReaderFeaturesOnlyFromClientsThatAcceptDelta() {
ResponseFormat.DELTA,
advanced));
}

@Test
void refusesColumnMappingToClientsThatDidNotAdvertiseIt() {
Map<String, String> mapped = Map.of("delta.columnMapping.mode", "name");
ApiException refused =
assertThrows(
ApiException.class,
() ->
DeltaSharingCapabilities.requireColumnMappingSupport(
"responseformat=parquet", mapped, 3));
assertEquals(
"Table features delta.columnMapping.mode are found in table version: 3.",
refused.getMessage());
assertThrows(
ApiException.class,
() ->
DeltaSharingCapabilities.requireColumnMappingSupport(
"responseformat=delta;readerfeatures=deletionVectors", mapped, 3));
assertDoesNotThrow(
() ->
DeltaSharingCapabilities.requireColumnMappingSupport(
"responseformat=delta;readerfeatures=columnMapping", mapped, 3));
assertDoesNotThrow(
() ->
DeltaSharingCapabilities.requireColumnMappingSupport(
"responseformat=parquet", Map.of("delta.columnMapping.mode", "none"), 3));
assertDoesNotThrow(
() -> DeltaSharingCapabilities.requireColumnMappingSupport(null, Map.of(), 3));
}
}