Skip to content

Commit 39c5664

Browse files
committed
Merging updates from main
2 parents d850a5b + b25e819 commit 39c5664

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

Extensions/Cosmos/Cosmos.DataTransfer.CosmosExtension/CosmosDataSinkExtension.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ void ReportCount(int i)
8989
addedCount += i;
9090
if (addedCount % 500 == 0)
9191
{
92-
logger.LogInformation("{AddedCount} records added after {TotalSeconds}s", addedCount, $"{timer.ElapsedMilliseconds / 1000.0:F2}");
92+
logger.LogInformation("{AddedCount} records added after {TotalSeconds}s ({AddRate} records/s)", addedCount, $"{timer.ElapsedMilliseconds / 1000.0:F2}", $"{(int)(addedCount / (timer.ElapsedMilliseconds / 1000.0))}");
9393
}
9494
}
9595

9696
var convertedObjects = dataItems
97-
.Select(di => di.BuildDynamicObjectTree(requireStringId: true, preserveMixedCaseIds: settings.PreserveMixedCaseIds))
97+
.Select(di => di.BuildDynamicObjectTree(requireStringId: true, ignoreNullValues: settings.IgnoreNullValues, preserveMixedCaseIds: settings.PreserveMixedCaseIds))
9898
.Where(o => o != null)
9999
.OfType<ExpandoObject>();
100100
var batches = convertedObjects.Buffer(settings.BatchSize);
@@ -114,7 +114,7 @@ void ReportCount(int i)
114114
throw new Exception($"Only {addedCount} of {inputCount} records were added to Cosmos");
115115
}
116116

117-
logger.LogInformation("Added {AddedCount} total records in {TotalSeconds}s", addedCount, $"{timer.ElapsedMilliseconds / 1000.0:F2}");
117+
logger.LogInformation("Added {AddedCount} total records in {TotalSeconds}s ({AddRate} records/s)", addedCount, $"{timer.ElapsedMilliseconds / 1000.0:F2}", $"{(int)(addedCount / (timer.ElapsedMilliseconds / 1000.0))}");
118118
}
119119

120120
private static AsyncRetryPolicy GetRetryPolicy(int maxRetryCount, int initialRetryDuration)

Extensions/Cosmos/Cosmos.DataTransfer.CosmosExtension/CosmosExtensionServices.cs

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ public static CosmosClient CreateClient(CosmosSettingsBase settings, string disp
2222
AllowBulkExecution = true,
2323
EnableContentResponseOnWrite = false,
2424
};
25+
26+
if (settings is CosmosSinkSettings sinkSettings)
27+
{
28+
clientOptions.SerializerOptions = new CosmosSerializationOptions
29+
{
30+
IgnoreNullValues = sinkSettings.IgnoreNullValues
31+
};
32+
}
2533

2634
CosmosClient? cosmosClient;
2735
if (settings.UseRbacAuth)

Extensions/Cosmos/Cosmos.DataTransfer.CosmosExtension/CosmosSinkSettings.cs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class CosmosSinkSettings : CosmosSettingsBase, IDataExtensionSettings
1616
public bool UseSharedThroughput { get; set; } = false;
1717
public bool PreserveMixedCaseIds { get; set; } = false;
1818
public DataWriteMode WriteMode { get; set; } = DataWriteMode.Insert;
19+
public bool IgnoreNullValues { get; set; } = false;
1920
public List<string>? PartitionKeyPaths { get; set; }
2021

2122
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)

Interfaces/Cosmos.DataTransfer.Interfaces/DataItemExtensions.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ public static class DataItemExtensions
1212
/// <param name="preserveMixedCaseIds">If true, disregards differently cased "id" fields for purposes of required "id" and passes them through.</param>
1313
/// <returns>A dynamic object containing the entire data structure.</returns>
1414
/// <remarks>The returned ExpandoObject can be used directly as an IDictionary.</remarks>
15-
public static ExpandoObject? BuildDynamicObjectTree(this IDataItem? source, bool requireStringId = false, bool preserveMixedCaseIds = false)
15+
public static ExpandoObject? BuildDynamicObjectTree(this IDataItem? source, bool requireStringId = false, bool ignoreNullValues = false, bool preserveMixedCaseIds = false)
1616
{
17-
if (source == null)
17+
if (source == null)
18+
{
1819
return null;
20+
}
1921

2022
var fields = source.GetFieldNames().ToList();
2123
var item = new ExpandoObject();
@@ -41,6 +43,11 @@ public static class DataItemExtensions
4143
foreach (string field in fields)
4244
{
4345
object? value = source.GetValue(field);
46+
if (ignoreNullValues && value == null)
47+
{
48+
continue;
49+
}
50+
4451
var fieldName = field;
4552
if (requireStringId && string.Equals(field, "id", StringComparison.CurrentCultureIgnoreCase))
4653
{

0 commit comments

Comments
 (0)