Skip to content

Commit

Permalink
Fix #527 - Use NVarchar(max) db type for tags in SQL Server (#530)
Browse files Browse the repository at this point in the history
## Motivation and Context (Why the change? What's the scenario?)

Resolve the issue #527 by removing size limit for tags field.

## High level description (Approach, Design)

the merge command used nvarchar(256) field for tags management but it
requires to remove this limit.
  • Loading branch information
kbeaugrand authored Jun 1, 2024
1 parent b64f7f8 commit 8c0ad8c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 31 additions & 0 deletions extensions/SQLServer/SQLServer.FunctionalTests/DefaultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,35 @@ public async Task ItSupportsTags()
{
await DocumentUploadTest.ItSupportsTags(this._memory, this.Log);
}

[Fact]
[Trait("Category", "SQLServer")]
public async Task ItCanImportDocumentWithManyTagsAtATime()
{
const string Id = "ItCanImportDocumentWithManyTagsAtATime-file1-NASA-news.pdf";

var tags = new TagCollection
{
{ "type", "news" },
{ "type", "test" },
{ "ext", "pdf" }
};

for (int i = 0; i < 100; i++)
{
tags.AddSyntheticTag($"tagTest{i}");
}

await this._memory.ImportDocumentAsync(
"file1-NASA-news.pdf",
documentId: Id,
tags: tags,
steps: Constants.PipelineWithoutSummary);

while (!await this._memory.IsDocumentReadyAsync(documentId: Id))
{
this.Log("Waiting for memory ingestion to complete...");
await Task.Delay(TimeSpan.FromSeconds(2));
}
}
}
4 changes: 2 additions & 2 deletions extensions/SQLServer/SQLServer/SqlServerMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ DELETE FROM [tgt]
USING (
SELECT
{this.GetFullTableName(this._config.MemoryTableName)}.[id],
cast([tags].[key] AS NVARCHAR(256)) COLLATE SQL_Latin1_General_CP1_CI_AS AS [tag_name],
cast([tags].[key] AS NVARCHAR(MAX)) COLLATE SQL_Latin1_General_CP1_CI_AS AS [tag_name],
[tag_value].[value] AS [value]
FROM {this.GetFullTableName(this._config.MemoryTableName)}
CROSS APPLY openjson(@tags) [tags]
CROSS APPLY openjson(cast([tags].[value] AS NVARCHAR(256)) COLLATE SQL_Latin1_General_CP1_CI_AS) [tag_value]
CROSS APPLY openjson(cast([tags].[value] AS NVARCHAR(MAX)) COLLATE SQL_Latin1_General_CP1_CI_AS) [tag_value]
WHERE {this.GetFullTableName(this._config.MemoryTableName)}.[key] = @key
AND {this.GetFullTableName(this._config.MemoryTableName)}.[collection] = @index
) AS [src]
Expand Down

0 comments on commit 8c0ad8c

Please sign in to comment.