-
Notifications
You must be signed in to change notification settings - Fork 301
Add include-vector-fields-by-default property to DataSource configuration #3005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
60cd76b
443fab6
7469d5d
46ddc8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,12 +51,17 @@ public DataSourceConverter(DeserializationVariableReplacementSettings? replaceme | |||||||||||||||||||||
| string connectionString = string.Empty; | ||||||||||||||||||||||
| DatasourceHealthCheckConfig? health = null; | ||||||||||||||||||||||
| Dictionary<string, object?>? datasourceOptions = null; | ||||||||||||||||||||||
| bool includeVectorFieldsByDefault = false; | ||||||||||||||||||||||
| bool userProvidedIncludeVectorFieldsByDefault = false; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| while (reader.Read()) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| if (reader.TokenType is JsonTokenType.EndObject) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return new DataSource(databaseType, connectionString, datasourceOptions, health); | ||||||||||||||||||||||
| return new DataSource(databaseType, connectionString, datasourceOptions, health, includeVectorFieldsByDefault) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| UserProvidedIncludeVectorFieldsByDefault = userProvidedIncludeVectorFieldsByDefault | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (reader.TokenType is JsonTokenType.PropertyName) | ||||||||||||||||||||||
|
|
@@ -136,6 +141,24 @@ public DataSourceConverter(DeserializationVariableReplacementSettings? replaceme | |||||||||||||||||||||
| datasourceOptions = optionsDict; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| break; | ||||||||||||||||||||||
| case "include-vector-fields-by-default": | ||||||||||||||||||||||
| if (reader.TokenType is JsonTokenType.True or JsonTokenType.False) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| includeVectorFieldsByDefault = reader.GetBoolean(); | ||||||||||||||||||||||
| userProvidedIncludeVectorFieldsByDefault = true; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| else if (reader.TokenType is JsonTokenType.String) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| // Support environment variable replacement | ||||||||||||||||||||||
| string stringValue = reader.DeserializeString(_replacementSettings)!; | ||||||||||||||||||||||
| if (bool.TryParse(stringValue, out bool boolValue)) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| includeVectorFieldsByDefault = boolValue; | ||||||||||||||||||||||
| userProvidedIncludeVectorFieldsByDefault = true; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| break; | ||||||||||||||||||||||
| default: | ||||||||||||||||||||||
| throw new JsonException($"Unexpected property {propertyName} while deserializing DataSource."); | ||||||||||||||||||||||
|
|
@@ -149,11 +172,37 @@ public DataSourceConverter(DeserializationVariableReplacementSettings? replaceme | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| public override void Write(Utf8JsonWriter writer, DataSource value, JsonSerializerOptions options) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| // Remove the converter so we don't recurse. | ||||||||||||||||||||||
| JsonSerializerOptions innerOptions = new(options); | ||||||||||||||||||||||
| innerOptions.Converters.Remove(innerOptions.Converters.First(c => c is DataSourceConverterFactory)); | ||||||||||||||||||||||
| writer.WriteStartObject(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Always write required properties | ||||||||||||||||||||||
| writer.WritePropertyName("database-type"); | ||||||||||||||||||||||
| JsonSerializer.Serialize(writer, value.DatabaseType, options); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| writer.WritePropertyName("connection-string"); | ||||||||||||||||||||||
| writer.WriteStringValue(value.ConnectionString); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Write options if present | ||||||||||||||||||||||
| if (value.Options is not null && value.Options.Count > 0) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| writer.WritePropertyName("options"); | ||||||||||||||||||||||
| JsonSerializer.Serialize(writer, value.Options, options); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Write health if present | ||||||||||||||||||||||
| if (value.Health is not null) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| writer.WritePropertyName("health"); | ||||||||||||||||||||||
| JsonSerializer.Serialize(writer, value.Health, options); | ||||||||||||||||||||||
|
Comment on lines
+191
to
+195
|
||||||||||||||||||||||
| // Write health if present | |
| if (value.Health is not null) | |
| { | |
| writer.WritePropertyName("health"); | |
| JsonSerializer.Serialize(writer, value.Health, options); | |
| // Write health only if user provided health configuration | |
| if (value.Health is DatasourceHealthCheckConfig healthConfig && healthConfig.UserProvidedEnabled) | |
| { | |
| writer.WritePropertyName("health"); | |
| JsonSerializer.Serialize(writer, healthConfig, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include-vector-fields-by-defaultparsing currently falls through silently for invalid inputs (e.g., non-boolean token types, or a string that doesn’t parse to bool), which can hide config mistakes and leavesUserProvidedIncludeVectorFieldsByDefaultfalse. Consider throwing aJsonExceptionwhen the value isn’t a boolean or a parseable boolean string (similar to howoptionsrejects unexpected values).