@@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets.UTF_8
22
22
import java .util .UUID
23
23
24
24
import scala .collection .mutable .{ArrayBuffer , ListBuffer }
25
+ import scala .util .control .NonFatal
25
26
26
27
import org .apache .commons .io .IOUtils
27
28
import org .apache .commons .io .input .BoundedInputStream
@@ -1034,48 +1035,10 @@ class DeltaSharingRestClient(
1034
1035
response
1035
1036
}
1036
1037
1037
- private def checkEndStreamAction (
1038
- capabilities : Option [String ],
1039
- capabilitiesMap : Map [String , String ],
1040
- lines : Seq [String ]): Unit = {
1041
- val includeEndStreamActionHeader = getRespondedIncludeEndStreamActionHeader(capabilitiesMap)
1042
- includeEndStreamActionHeader match {
1043
- case Some (true ) =>
1044
- val lastLine = lines.last
1045
- val lastLineAction = JsonUtils .fromJson[SingleAction ](lastLine)
1046
- if (lastLineAction.endStreamAction == null ) {
1047
- throw new MissingEndStreamActionException (" Client sets " +
1048
- s " ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true " + getDsQueryIdForLogging +
1049
- s " , server responded with the header set to true( ${capabilities}) " +
1050
- s " and ${lines.size} lines, and last line as [ ${lastLine}]. " )
1051
- }
1052
- logInfo(
1053
- s " Successfully verified endStreamAction in the response " + getDsQueryIdForLogging
1054
- )
1055
- case Some (false ) =>
1056
- logWarning(s " Client sets ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true in the " +
1057
- s " header, but the server responded with the header set to false( " +
1058
- s " ${capabilities}), " + getDsQueryIdForLogging
1059
- )
1060
- case None =>
1061
- logWarning(s " Client sets ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true in the " +
1062
- s " header, but server didn't respond with the header( ${capabilities}), " +
1063
- getDsQueryIdForLogging
1064
- )
1065
- }
1066
- }
1067
-
1068
1038
private def getRespondedFormat (capabilitiesMap : Map [String , String ]): String = {
1069
1039
capabilitiesMap.get(RESPONSE_FORMAT ).getOrElse(RESPONSE_FORMAT_PARQUET )
1070
1040
}
1071
1041
1072
- // includeEndStreamActionHeader indicates whether the last line is required to be an
1073
- // EndStreamAction, parsed from the response header.
1074
- private def getRespondedIncludeEndStreamActionHeader (
1075
- capabilitiesMap : Map [String , String ]): Option [Boolean ] = {
1076
- capabilitiesMap.get(DELTA_SHARING_INCLUDE_END_STREAM_ACTION ).map(_.toBoolean)
1077
- }
1078
-
1079
1042
private def parseDeltaSharingCapabilities (capabilities : Option [String ]): Map [String , String ] = {
1080
1043
if (capabilities.isEmpty) {
1081
1044
return Map .empty[String , String ]
@@ -1229,7 +1192,7 @@ class DeltaSharingRestClient(
1229
1192
).map(_.getValue)
1230
1193
val capabilitiesMap = parseDeltaSharingCapabilities(capabilities)
1231
1194
if (setIncludeEndStreamAction) {
1232
- checkEndStreamAction(capabilities, capabilitiesMap, lines)
1195
+ checkEndStreamAction(capabilities, capabilitiesMap, lines, getDsQueryIdForLogging )
1233
1196
}
1234
1197
(
1235
1198
Option (
@@ -1364,6 +1327,55 @@ object DeltaSharingRestClient extends Logging {
1364
1327
)
1365
1328
}
1366
1329
1330
+ private def tryParseEndStreamAction (line : String ): EndStreamAction = {
1331
+ try {
1332
+ JsonUtils .fromJson[SingleAction ](line).endStreamAction
1333
+ } catch {
1334
+ case NonFatal (_) =>
1335
+ logError(s " Failed to parse last line in response as EndStreamAction: $line" )
1336
+ null
1337
+ }
1338
+ }
1339
+
1340
+ // includeEndStreamActionHeader indicates whether the last line is required to be an
1341
+ // EndStreamAction, parsed from the response header.
1342
+ private def getRespondedIncludeEndStreamActionHeader (
1343
+ capabilitiesMap : Map [String , String ]): Option [Boolean ] = {
1344
+ capabilitiesMap.get(DELTA_SHARING_INCLUDE_END_STREAM_ACTION ).map(_.toBoolean)
1345
+ }
1346
+
1347
+ def checkEndStreamAction (
1348
+ capabilities : Option [String ],
1349
+ capabilitiesMap : Map [String , String ],
1350
+ lines : Seq [String ],
1351
+ queryIdForLogging : String ): Unit = {
1352
+ val includeEndStreamActionHeader = getRespondedIncludeEndStreamActionHeader(capabilitiesMap)
1353
+ includeEndStreamActionHeader match {
1354
+ case Some (true ) =>
1355
+ val lastLine = lines.lastOption.getOrElse(" Empty_Seq_in_checkEndStreamAction" )
1356
+ val lastEndStreamAction = tryParseEndStreamAction(lastLine)
1357
+ if (lastEndStreamAction == null ) {
1358
+ throw new MissingEndStreamActionException (" Client sets " +
1359
+ s " ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true " + queryIdForLogging +
1360
+ s " , server responded with the header set to true( ${capabilities}) " +
1361
+ s " and ${lines.size} lines, and last line as [ ${lastLine}]. " )
1362
+ }
1363
+ logInfo(
1364
+ s " Successfully verified endStreamAction in the response " + queryIdForLogging
1365
+ )
1366
+ case Some (false ) =>
1367
+ logWarning(s " Client sets ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true in the " +
1368
+ s " header, but the server responded with the header set to false( " +
1369
+ s " ${capabilities}), " + queryIdForLogging
1370
+ )
1371
+ case None =>
1372
+ logWarning(s " Client sets ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true in the " +
1373
+ s " header, but server didn't respond with the header( ${capabilities}), " +
1374
+ queryIdForLogging
1375
+ )
1376
+ }
1377
+ }
1378
+
1367
1379
def apply (
1368
1380
profileFile : String ,
1369
1381
forStreaming : Boolean = false ,
0 commit comments