5
5
import io .whitefox .core .*;
6
6
import io .whitefox .core .Schema ;
7
7
import io .whitefox .core .Share ;
8
+ import io .whitefox .core .services .DeltaSharingCapabilities ;
8
9
import java .util .*;
9
10
import java .util .stream .Collectors ;
10
11
@@ -60,44 +61,44 @@ public static TableQueryResponseObject readTableResult2api(ReadTableResult readT
60
61
61
62
private static ParquetMetadataObject metadata2Api (Metadata metadata ) {
62
63
return new ParquetMetadataObject ()
63
- .metaData (new ParquetMetadataObjectMetaData ()
64
- .numFiles (metadata .numFiles ().orElse (null ))
65
- .version (metadata .version (). orElse ( null ))
66
- .size (metadata .size ().orElse (null ))
67
- .id (metadata .id ())
68
- .name (metadata .name ().orElse (null ))
69
- .description (metadata .description ().orElse (null ))
70
- .format (new ParquetFormatObject ().provider (metadata .format ().provider ()))
71
- .schemaString (metadata .tableSchema ().structType ().toJson ())
72
- .partitionColumns (metadata .partitionColumns ())
73
- ._configuration (metadata .configuration ()));
64
+ .metaData (new ParquetMetadataObjectMetaData ()
65
+ .numFiles (metadata .numFiles ().orElse (null ))
66
+ .version (metadata .version ())
67
+ .size (metadata .size ().orElse (null ))
68
+ .id (metadata .id ())
69
+ .name (metadata .name ().orElse (null ))
70
+ .description (metadata .description ().orElse (null ))
71
+ .format (new ParquetFormatObject ().provider (metadata .format ().provider ()))
72
+ .schemaString (metadata .tableSchema ().structType ().toJson ())
73
+ .partitionColumns (metadata .partitionColumns ())
74
+ ._configuration (metadata .configuration ()));
74
75
}
75
76
76
77
private static DeltaProtocolObject protocol2Api (Protocol protocol ) {
77
78
return new DeltaProtocolObject ()
78
- .protocol (new DeltaProtocolObjectProtocol ()
79
- .deltaProtocol (new DeltaProtocolObjectProtocolDeltaProtocol ()
80
- .minReaderVersion (protocol .minReaderVersion ().orElse (1 ))
81
- .minWriterVersion (protocol .minWriterVersion ().orElse (1 ))));
79
+ .protocol (new DeltaProtocolObjectProtocol ()
80
+ .deltaProtocol (new DeltaProtocolObjectProtocolDeltaProtocol ()
81
+ .minReaderVersion (protocol .minReaderVersion ().orElse (1 ))
82
+ .minWriterVersion (protocol .minWriterVersion ().orElse (1 ))));
82
83
}
83
84
84
85
private static DeltaFileObject file2Api (TableFile f ) {
85
86
return new DeltaFileObject ()
86
- .id (f .id ())
87
- .version (f .version ().orElse (null ))
88
- .deletionVectorFileId (null ) // TODO
89
- .timestamp (f .timestamp ().orElse (null ))
90
- .expirationTimestamp (f .expirationTimestamp ())
91
- .deltaSingleAction (new DeltaSingleAction ()
92
- ._file (new DeltaAddFileAction ()
93
- .id (f .id ())
94
- .url (f .url ())
95
- .partitionValues (f .partitionValues ())
96
- .size (f .size ())
97
- .stats (f .stats ().orElse (null ))
98
- .version (f .version ().orElse (null ))
99
- .timestamp (f .timestamp ().orElse (null ))
100
- .expirationTimestamp (f .expirationTimestamp ())));
87
+ .id (f .id ())
88
+ .version (f .version ().orElse (null ))
89
+ .deletionVectorFileId (null ) // TODO
90
+ .timestamp (f .timestamp ().orElse (null ))
91
+ .expirationTimestamp (f .expirationTimestamp ())
92
+ .deltaSingleAction (new DeltaSingleAction ()
93
+ ._file (new DeltaAddFileAction ()
94
+ .id (f .id ())
95
+ .url (f .url ())
96
+ .partitionValues (f .partitionValues ())
97
+ .size (f .size ())
98
+ .stats (f .stats ().orElse (null ))
99
+ .version (f .version ().orElse (null ))
100
+ .timestamp (f .timestamp ().orElse (null ))
101
+ .expirationTimestamp (f .expirationTimestamp ())));
101
102
}
102
103
103
104
public static TableReferenceAndReadRequest api2TableReferenceAndReadRequest (
@@ -113,28 +114,16 @@ public static io.whitefox.api.deltasharing.model.v1.generated.Table table2api(
113
114
.schema (sharedTable .schema ());
114
115
}
115
116
116
- /**
117
- * NOTE: this is an undocumented feature of the reference impl of delta-sharing, it's not part of the
118
- * protocol
119
- * ----
120
- * Return the [[io.whitefox.api.server.DeltaHeaders.DELTA_SHARE_CAPABILITIES_HEADER]] header
121
- * that will be set in the response w/r/t the one received in the request.
122
- * If the request did not contain any, we will return an empty one.
123
- */
124
- public static Map <String , String > toHeaderCapabilitiesMap (String headerCapabilities ) {
125
- if (headerCapabilities == null ) {
126
- return Map .of ();
127
- }
128
- return Arrays .stream (headerCapabilities .toLowerCase ().split (";" ))
129
- .map (h -> h .split ("=" ))
130
- .filter (h -> h .length == 2 )
131
- .map (splits -> Map .entry (splits [0 ], splits [1 ]))
132
- .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
133
- }
134
-
135
117
public static TableMetadataResponseObject toTableResponseMetadata (Metadata m ) {
136
118
return new TableMetadataResponseObject ()
137
- .protocol (new ParquetProtocolObject ().protocol (new ParquetProtocolObjectProtocol ().minReaderVersion (1 )))
119
+ .protocol (new ParquetProtocolObject ()
120
+ .protocol (new ParquetProtocolObjectProtocol ().minReaderVersion (1 )))
138
121
.metadata (metadata2Api (m ));
139
122
}
123
+
124
+ public static String toCapabilitiesHeader (DeltaSharingCapabilities deltaSharingCapabilities ) {
125
+ return deltaSharingCapabilities .values ().entrySet ().stream ()
126
+ .map (entry -> entry .getKey () + "=" + String .join ("," , entry .getValue ()))
127
+ .collect (Collectors .joining (";" ));
128
+ }
140
129
}
0 commit comments