@@ -25,6 +25,7 @@ import java.time.format.DateTimeFormatter.{ISO_DATE, ISO_DATE_TIME}
25
25
import java .util .UUID
26
26
27
27
import scala .collection .mutable .{ArrayBuffer , ListBuffer }
28
+ import scala .util .control .NonFatal
28
29
29
30
import org .apache .commons .io .IOUtils
30
31
import org .apache .commons .io .input .BoundedInputStream
@@ -970,48 +971,10 @@ class DeltaSharingRestClient(
970
971
)
971
972
}
972
973
973
- private def checkEndStreamAction (
974
- capabilities : Option [String ],
975
- capabilitiesMap : Map [String , String ],
976
- lines : Seq [String ]): Unit = {
977
- val includeEndStreamActionHeader = getRespondedIncludeEndStreamActionHeader(capabilitiesMap)
978
- includeEndStreamActionHeader match {
979
- case Some (true ) =>
980
- val lastLine = lines.last
981
- val lastLineAction = JsonUtils .fromJson[SingleAction ](lastLine)
982
- if (lastLineAction.endStreamAction == null ) {
983
- throw new MissingEndStreamActionException (" Client sets " +
984
- s " ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true " + getDsQueryIdForLogging +
985
- s " , server responded with the header set to true( ${capabilities}) " +
986
- s " and ${lines.size} lines, and last line as [ ${lastLine}]. " )
987
- }
988
- logInfo(
989
- s " Successfully verified endStreamAction in the response " + getDsQueryIdForLogging
990
- )
991
- case Some (false ) =>
992
- logWarning(s " Client sets ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true in the " +
993
- s " header, but the server responded with the header set to false( " +
994
- s " ${capabilities}), " + getDsQueryIdForLogging
995
- )
996
- case None =>
997
- logWarning(s " Client sets ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true in the " +
998
- s " header, but server didn't respond with the header( ${capabilities}), " +
999
- getDsQueryIdForLogging
1000
- )
1001
- }
1002
- }
1003
-
1004
974
private def getRespondedFormat (capabilitiesMap : Map [String , String ]): String = {
1005
975
capabilitiesMap.get(RESPONSE_FORMAT ).getOrElse(RESPONSE_FORMAT_PARQUET )
1006
976
}
1007
977
1008
- // includeEndStreamActionHeader indicates whether the last line is required to be an
1009
- // EndStreamAction, parsed from the response header.
1010
- private def getRespondedIncludeEndStreamActionHeader (
1011
- capabilitiesMap : Map [String , String ]): Option [Boolean ] = {
1012
- capabilitiesMap.get(DELTA_SHARING_INCLUDE_END_STREAM_ACTION ).map(_.toBoolean)
1013
- }
1014
-
1015
978
private def parseDeltaSharingCapabilities (capabilities : Option [String ]): Map [String , String ] = {
1016
979
if (capabilities.isEmpty) {
1017
980
return Map .empty[String , String ]
@@ -1172,7 +1135,7 @@ class DeltaSharingRestClient(
1172
1135
).map(_.getValue)
1173
1136
val capabilitiesMap = parseDeltaSharingCapabilities(capabilities)
1174
1137
if (setIncludeEndStreamAction) {
1175
- checkEndStreamAction(capabilities, capabilitiesMap, lines)
1138
+ checkEndStreamAction(capabilities, capabilitiesMap, lines, getDsQueryIdForLogging )
1176
1139
}
1177
1140
(
1178
1141
Option (
@@ -1307,6 +1270,55 @@ object DeltaSharingRestClient extends Logging {
1307
1270
)
1308
1271
}
1309
1272
1273
+ private def tryParseEndStreamAction (line : String ): EndStreamAction = {
1274
+ try {
1275
+ JsonUtils .fromJson[SingleAction ](line).endStreamAction
1276
+ } catch {
1277
+ case NonFatal (_) =>
1278
+ logError(s " Failed to parse last line in response as EndStreamAction: $line" )
1279
+ null
1280
+ }
1281
+ }
1282
+
1283
+ // includeEndStreamActionHeader indicates whether the last line is required to be an
1284
+ // EndStreamAction, parsed from the response header.
1285
+ private def getRespondedIncludeEndStreamActionHeader (
1286
+ capabilitiesMap : Map [String , String ]): Option [Boolean ] = {
1287
+ capabilitiesMap.get(DELTA_SHARING_INCLUDE_END_STREAM_ACTION ).map(_.toBoolean)
1288
+ }
1289
+
1290
+ def checkEndStreamAction (
1291
+ capabilities : Option [String ],
1292
+ capabilitiesMap : Map [String , String ],
1293
+ lines : Seq [String ],
1294
+ queryIdForLogging : String ): Unit = {
1295
+ val includeEndStreamActionHeader = getRespondedIncludeEndStreamActionHeader(capabilitiesMap)
1296
+ includeEndStreamActionHeader match {
1297
+ case Some (true ) =>
1298
+ val lastLine = lines.lastOption.getOrElse(" Empty_Seq_in_checkEndStreamAction" )
1299
+ val lastEndStreamAction = tryParseEndStreamAction(lastLine)
1300
+ if (lastEndStreamAction == null ) {
1301
+ throw new MissingEndStreamActionException (" Client sets " +
1302
+ s " ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true " + queryIdForLogging +
1303
+ s " , server responded with the header set to true( ${capabilities}) " +
1304
+ s " and ${lines.size} lines, and last line as [ ${lastLine}]. " )
1305
+ }
1306
+ logInfo(
1307
+ s " Successfully verified endStreamAction in the response " + queryIdForLogging
1308
+ )
1309
+ case Some (false ) =>
1310
+ logWarning(s " Client sets ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true in the " +
1311
+ s " header, but the server responded with the header set to false( " +
1312
+ s " ${capabilities}), " + queryIdForLogging
1313
+ )
1314
+ case None =>
1315
+ logWarning(s " Client sets ${DELTA_SHARING_INCLUDE_END_STREAM_ACTION }=true in the " +
1316
+ s " header, but server didn't respond with the header( ${capabilities}), " +
1317
+ queryIdForLogging
1318
+ )
1319
+ }
1320
+ }
1321
+
1310
1322
def apply (
1311
1323
profileFile : String ,
1312
1324
forStreaming : Boolean = false ,
0 commit comments