Hopefully there wasn't a simpler way of resolving this.
Note: this PR includes a breaking change.
Currently, it isn't possible to render a non-string property into the query sent to kSSQL--the JSON serializer will wrap all string values in quotes (as expected). Thus, when setting a Boolean property such as ksql.query.pull.table.scan.enabled, the query string includes the parameter with a stringified value (ksql.query.pull.table.scan.enabled = "true"). This causes kSQL to throw an error, since it is expecting a Boolean value for this parameter.
To work around this, we altered the Properties dictionary to hold System.Text.Json.JsonValue's instead of strings, and added Get<T> and Set<T> methods to allow for setting properties of any type. When the properties are serialized, the Serializer will respect the underlying type: strings will be quoted, Booleans will be unquoted, etc.
As part of this change, we also marked the ProcessingGuarantee and AutoOffsetReset enums to be serialized using the built-in snake case JSON enum serializer. This meant the helper methods for manually marshaling between the enum and their corresponding string representation were no longer needed.
This pull request includes several changes to improve the handling of QueryStreamParameters and QueryParameters in the test files. The most important changes include replacing dictionary-style access with the Set and Get methods for better type safety and readability, and adding a new test for the JsonSnakeCaseStringEnumConverterAttribute.
Hopefully there wasn't a simpler way of resolving this.
Note: this PR includes a breaking change.
Currently, it isn't possible to render a non-string property into the query sent to kSSQL--the JSON serializer will wrap all string values in quotes (as expected). Thus, when setting a Boolean property such as
ksql.query.pull.table.scan.enabled
, the query string includes the parameter with a stringified value (ksql.query.pull.table.scan.enabled = "true"
). This causes kSQL to throw an error, since it is expecting a Boolean value for this parameter.To work around this, we altered the
Properties
dictionary to holdSystem.Text.Json.JsonValue
's instead of strings, and addedGet<T>
andSet<T>
methods to allow for setting properties of any type. When the properties are serialized, the Serializer will respect the underlying type: strings will be quoted, Booleans will be unquoted, etc.As part of this change, we also marked the
ProcessingGuarantee
andAutoOffsetReset
enums to be serialized using the built-in snake case JSON enum serializer. This meant the helper methods for manually marshaling between the enum and their corresponding string representation were no longer needed.Before:
After:
AI-generated summary of changes
This pull request includes several changes to improve the handling of
QueryStreamParameters
andQueryParameters
in the test files. The most important changes include replacing dictionary-style access with theSet
andGet
methods for better type safety and readability, and adding a new test for theJsonSnakeCaseStringEnumConverterAttribute
.Improvements to Parameter Handling:
Tests/ksqlDB.RestApi.Client.IntegrationTests/KSql/Linq/ComplexTypesTests.cs
: Replaced dictionary-style access with theSet
method forQueryStreamParameters
to setAutoOffsetResetPropertyName
toAutoOffsetReset.Earliest
. [1] [2]Tests/ksqlDB.RestApi.Client.IntegrationTests/KSql/Linq/QbservableExtensionsTests.cs
: Updated multiple test methods to use theSet
method forQueryStreamParameters
to setAutoOffsetResetPropertyName
toAutoOffsetReset.Earliest
. [1] [2] [3] [4] [5]Enhancements to Test Assertions:
Tests/ksqlDB.RestApi.Client.Tests/DependencyInjection/KSqlDbServiceCollectionExtensionsTests.cs
: Changed the assertion to use theGet
method forQueryStreamParameters
to checkProcessingGuarantee
.Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/KSqlDBContextOptionsTests.cs
: Modified multiple test methods to use theGet
method forQueryStreamParameters
to verifyProcessingGuarantee
andAutoOffsetReset
. [1] [2] [3] [4] [5]New Test Addition:
Tests/ksqlDB.RestApi.Client.Tests/Infrastructure/Attributes/JsonCamelCaseStringEnumConverterAttributeTests.cs
: Added a new test to verify the creation of theJsonSnakeCaseStringEnumConverterAttribute
.Context Options Handling:
Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/KSqlDBContextTests.cs
: Updated multiple test methods to use theSet
andGet
methods forQueryStreamParameters
to set and verifyAutoOffsetReset
andProcessingGuarantee
. [1] [2] [3] [4] [5] [6] [7] [8] [9]Options Builder Enhancements:
Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Context/Options/KSqlDbContextOptionsBuilderTests.cs
: Modified test methods to use theGet
method forQueryStreamParameters
to verifyProcessingGuarantee
andAutoOffsetReset
. [1] [2] [3] [4] [5]