From abca1c7fb4f3d9030410cf4ae3059f7921871e39 Mon Sep 17 00:00:00 2001 From: Dongwei Wang Date: Fri, 20 Nov 2020 04:58:29 -0800 Subject: [PATCH] [Synapse][Spark] - Fix null reference exception due to some nullable properties --- .../CHANGELOG.md | 2 +- .../SparkBatchJobState.Serialization.cs | 28 +++++++-------- .../Models/SparkScheduler.Serialization.cs | 12 +++---- .../SparkServicePlugin.Serialization.cs | 20 +++++------ .../Models/SparkSession.Serialization.cs | 9 +++-- .../Models/SparkSessionState.Serialization.cs | 36 +++++++++---------- .../src/autorest.md | 18 ++-------- 7 files changed, 58 insertions(+), 67 deletions(-) diff --git a/sdk/synapse/Azure.Analytics.Synapse.Spark/CHANGELOG.md b/sdk/synapse/Azure.Analytics.Synapse.Spark/CHANGELOG.md index cff01e26ff42..27ca9ec59342 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.Spark/CHANGELOG.md +++ b/sdk/synapse/Azure.Analytics.Synapse.Spark/CHANGELOG.md @@ -1,7 +1,7 @@ # Release History ## 1.0.0-beta.1 (Unreleased) - +- This release contains bug fixes to improve quality. ## 1.0.0-preview.2 (2020-09-01) - This release contains bug fixes to improve quality. diff --git a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkBatchJobState.Serialization.cs b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkBatchJobState.Serialization.cs index 61498f369819..2f8366181910 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkBatchJobState.Serialization.cs +++ b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkBatchJobState.Serialization.cs @@ -15,13 +15,13 @@ public partial class SparkBatchJobState { internal static SparkBatchJobState DeserializeSparkBatchJobState(JsonElement element) { - Optional notStartedAt = default; - Optional startingAt = default; - Optional runningAt = default; - Optional deadAt = default; - Optional successAt = default; - Optional killedAt = default; - Optional recoveringAt = default; + Optional notStartedAt = default; + Optional startingAt = default; + Optional runningAt = default; + Optional deadAt = default; + Optional successAt = default; + Optional killedAt = default; + Optional recoveringAt = default; Optional currentState = default; Optional jobCreationRequest = default; foreach (var property in element.EnumerateObject()) @@ -30,7 +30,7 @@ internal static SparkBatchJobState DeserializeSparkBatchJobState(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + notStartedAt = null; continue; } notStartedAt = property.Value.GetDateTimeOffset("O"); @@ -40,7 +40,7 @@ internal static SparkBatchJobState DeserializeSparkBatchJobState(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + startingAt = null; continue; } startingAt = property.Value.GetDateTimeOffset("O"); @@ -50,7 +50,7 @@ internal static SparkBatchJobState DeserializeSparkBatchJobState(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + runningAt = null; continue; } runningAt = property.Value.GetDateTimeOffset("O"); @@ -60,7 +60,7 @@ internal static SparkBatchJobState DeserializeSparkBatchJobState(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + deadAt = null; continue; } deadAt = property.Value.GetDateTimeOffset("O"); @@ -70,7 +70,7 @@ internal static SparkBatchJobState DeserializeSparkBatchJobState(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + successAt = null; continue; } successAt = property.Value.GetDateTimeOffset("O"); @@ -80,7 +80,7 @@ internal static SparkBatchJobState DeserializeSparkBatchJobState(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + killedAt = null; continue; } killedAt = property.Value.GetDateTimeOffset("O"); @@ -90,7 +90,7 @@ internal static SparkBatchJobState DeserializeSparkBatchJobState(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + recoveringAt = null; continue; } recoveringAt = property.Value.GetDateTimeOffset("O"); diff --git a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkScheduler.Serialization.cs b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkScheduler.Serialization.cs index 63352cca64f4..d273859c98f9 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkScheduler.Serialization.cs +++ b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkScheduler.Serialization.cs @@ -15,9 +15,9 @@ public partial class SparkScheduler { internal static SparkScheduler DeserializeSparkScheduler(JsonElement element) { - Optional submittedAt = default; - Optional scheduledAt = default; - Optional endedAt = default; + Optional submittedAt = default; + Optional scheduledAt = default; + Optional endedAt = default; Optional cancellationRequestedAt = default; Optional currentState = default; foreach (var property in element.EnumerateObject()) @@ -26,7 +26,7 @@ internal static SparkScheduler DeserializeSparkScheduler(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + submittedAt = null; continue; } submittedAt = property.Value.GetDateTimeOffset("O"); @@ -36,7 +36,7 @@ internal static SparkScheduler DeserializeSparkScheduler(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + scheduledAt = null; continue; } scheduledAt = property.Value.GetDateTimeOffset("O"); @@ -46,7 +46,7 @@ internal static SparkScheduler DeserializeSparkScheduler(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + endedAt = null; continue; } endedAt = property.Value.GetDateTimeOffset("O"); diff --git a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkServicePlugin.Serialization.cs b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkServicePlugin.Serialization.cs index ea1d932de9ab..aa9f42c6b089 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkServicePlugin.Serialization.cs +++ b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkServicePlugin.Serialization.cs @@ -15,11 +15,11 @@ public partial class SparkServicePlugin { internal static SparkServicePlugin DeserializeSparkServicePlugin(JsonElement element) { - Optional preparationStartedAt = default; - Optional resourceAcquisitionStartedAt = default; - Optional submissionStartedAt = default; - Optional monitoringStartedAt = default; - Optional cleanupStartedAt = default; + Optional preparationStartedAt = default; + Optional resourceAcquisitionStartedAt = default; + Optional submissionStartedAt = default; + Optional monitoringStartedAt = default; + Optional cleanupStartedAt = default; Optional currentState = default; foreach (var property in element.EnumerateObject()) { @@ -27,7 +27,7 @@ internal static SparkServicePlugin DeserializeSparkServicePlugin(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + preparationStartedAt = null; continue; } preparationStartedAt = property.Value.GetDateTimeOffset("O"); @@ -37,7 +37,7 @@ internal static SparkServicePlugin DeserializeSparkServicePlugin(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + resourceAcquisitionStartedAt = null; continue; } resourceAcquisitionStartedAt = property.Value.GetDateTimeOffset("O"); @@ -47,7 +47,7 @@ internal static SparkServicePlugin DeserializeSparkServicePlugin(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + submissionStartedAt = null; continue; } submissionStartedAt = property.Value.GetDateTimeOffset("O"); @@ -57,7 +57,7 @@ internal static SparkServicePlugin DeserializeSparkServicePlugin(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + monitoringStartedAt = null; continue; } monitoringStartedAt = property.Value.GetDateTimeOffset("O"); @@ -67,7 +67,7 @@ internal static SparkServicePlugin DeserializeSparkServicePlugin(JsonElement ele { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + cleanupStartedAt = null; continue; } cleanupStartedAt = property.Value.GetDateTimeOffset("O"); diff --git a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkSession.Serialization.cs b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkSession.Serialization.cs index da3efea12aee..b0c5f6807536 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkSession.Serialization.cs +++ b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkSession.Serialization.cs @@ -152,6 +152,11 @@ internal static SparkSession DeserializeSparkSession(JsonElement element) } if (property.NameEquals("appId")) { + if (property.Value.ValueKind == JsonValueKind.Null) + { + appId = null; + continue; + } appId = property.Value.GetString(); continue; } @@ -159,7 +164,7 @@ internal static SparkSession DeserializeSparkSession(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + appInfo = null; continue; } Dictionary dictionary = new Dictionary(); @@ -179,7 +184,7 @@ internal static SparkSession DeserializeSparkSession(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + log = null; continue; } List array = new List(); diff --git a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkSessionState.Serialization.cs b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkSessionState.Serialization.cs index 55fe6c022454..690c186fa199 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkSessionState.Serialization.cs +++ b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/Generated/Models/SparkSessionState.Serialization.cs @@ -15,15 +15,15 @@ public partial class SparkSessionState { internal static SparkSessionState DeserializeSparkSessionState(JsonElement element) { - Optional notStartedAt = default; - Optional startingAt = default; - Optional idleAt = default; - Optional deadAt = default; - Optional shuttingDownAt = default; - Optional killedAt = default; - Optional recoveringAt = default; - Optional busyAt = default; - Optional errorAt = default; + Optional notStartedAt = default; + Optional startingAt = default; + Optional idleAt = default; + Optional deadAt = default; + Optional shuttingDownAt = default; + Optional killedAt = default; + Optional recoveringAt = default; + Optional busyAt = default; + Optional errorAt = default; Optional currentState = default; Optional jobCreationRequest = default; foreach (var property in element.EnumerateObject()) @@ -32,7 +32,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + notStartedAt = null; continue; } notStartedAt = property.Value.GetDateTimeOffset("O"); @@ -42,7 +42,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + startingAt = null; continue; } startingAt = property.Value.GetDateTimeOffset("O"); @@ -52,7 +52,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + idleAt = null; continue; } idleAt = property.Value.GetDateTimeOffset("O"); @@ -62,7 +62,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + deadAt = null; continue; } deadAt = property.Value.GetDateTimeOffset("O"); @@ -72,7 +72,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + shuttingDownAt = null; continue; } shuttingDownAt = property.Value.GetDateTimeOffset("O"); @@ -82,7 +82,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + killedAt = null; continue; } killedAt = property.Value.GetDateTimeOffset("O"); @@ -92,7 +92,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + recoveringAt = null; continue; } recoveringAt = property.Value.GetDateTimeOffset("O"); @@ -102,7 +102,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + busyAt = null; continue; } busyAt = property.Value.GetDateTimeOffset("O"); @@ -112,7 +112,7 @@ internal static SparkSessionState DeserializeSparkSessionState(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); + errorAt = null; continue; } errorAt = property.Value.GetDateTimeOffset("O"); diff --git a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/autorest.md b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/autorest.md index 5e0bbb52f9f7..4b47e95cb7de 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.Spark/src/autorest.md +++ b/sdk/synapse/Azure.Analytics.Synapse.Spark/src/autorest.md @@ -6,25 +6,11 @@ Run `dotnet build /t:GenerateCode` to generate code. > see https://aka.ms/autorest ```yaml -repo: https://github.com/Azure/azure-rest-api-specs/blob/fdf4bbfd7a73b28960d3a62490440345d6f2e8e3 +repo: https://github.com/Azure/azure-rest-api-specs/blob/a213469a74fff7aba237849bde2de7dffbdf970f ``` ``` yaml public-clients: true input-file: - $(repo)/specification/synapse/data-plane/Microsoft.Synapse/preview/2019-11-01-preview/sparkJob.json -``` - -## Swagger workarounds - -### Add nullable annotations - -``` yaml -directive: - from: swagger-document - where: $.definitions.SparkBatchJob - transform: > - $.properties.appId["x-nullable"] = true; - $.properties.appInfo["x-nullable"] = true; - $.properties.log["x-nullable"] = true; -```` +``` \ No newline at end of file