Commit 1848684
authored
[Internal] Binary Encoding: Fixes
# Pull Request Template
## Description
During some of the internal binary encoding opt-in customer workload
validation, it was identified that when the cosmos .net SDK is
initialized with binary encoding, and a date time field is persisted
into a database, the value is getting converted and stored as in non-ISO
format.
Cosmos Client Creation:
```
Environment.SetEnvironmentVariable(ConfigurationManager.BinaryEncodingEnabled, "True");
string databaseName = "binary-encoding-db";
string containerName = "binary-encoding-container";
CosmosClientOptions clientOptions = new()
{
ConnectionMode = ConnectionMode.Direct,
RequestTimeout = TimeSpan.FromSeconds(5000),
};
CosmosClient client = new CosmosClient(connectionString,
clientOptions);
ItemResponse<ToDoActivity> itemResponse = await container.CreateItemAsync(item);
```
Sample Data Saved in Container, when binary encoding is **Disabled** in
the SDK:

Sample Data Saved in Container, when binary encoding is **Enabled** in
the SDK:

This PR is fixing the above parsing gap. It appears that when a stream
is sent to the backend in `Text` format, the backend does some
formatting on the incoming stream, that converts `DateTime` fields into
`ISO 8601` format and stores it.

Per my analysis, when binary encoding is enabled, and the stream sent to
backend is in Binary format, the backend doesn't do any extra formatting
on the binary stream, and stores the stream as is. Therefore, [the
round-trip ("O", "o") format
specifier](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#Roundtrip)
in the SDK layer is ideal to keep the `DateTime` field preserved in ISO
standard, when binary encoding is enabled,
## Type of change
Please delete options that are not relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
## Closing issues
To automatically close an issue: closes #5132DateTime Parsing Issue (#5133)1 parent e1ee560 commit 1848684
2 files changed
Lines changed: 2 additions & 2 deletions
File tree
- Microsoft.Azure.Cosmos
- src/Json/Interop
- tests/Microsoft.Azure.Cosmos.Tests/Json
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
325 | | - | |
| 325 | + | |
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| |||
0 commit comments