When using the fts SNIPPET function the emulator's output schema diverges from what production spanner produces.
Specifically, the emulator Returns start_position and end_position as keys inside the highlights array (https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/blob/master/backend/query/search/snippet_evaluator.cc#L59-L60), whereas production returns begin and end.
And it entirely omits the source_begin and source_end keys at the snippet level (https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/blob/master/backend/query/search/snippet_evaluator.cc#L202)
Given a query like
SELECT
SNIPPET(content, "test"),
FROM
test_table
WHERE
SEARCH(content_tokens, "test")
Production spanner returns
{
"snippets":[
{
"highlights":[
{
"begin":1,
"end":5
}
],
"snippet":"Test est",
"source_begin":1,
"source_end":9
}
]
}
This matches what is documented here https://docs.cloud.google.com/spanner/docs/reference/standard-sql/search_functions#snippet
The same query against the emulator returns
{
"snippets":[
{
"highlights":[
{
"start_position":1,
"end_position":5
}
],
"snippet":"Test est"
}
]
}
Running Spanner Emulator Version: 1.5.54
Because of this discrepancy, application code and deserializers that work in production fail during local testing against the emulator unless environment-specific workarounds are added.
It would be nice if this could be fixed so the emulator returns the snippets using the same schema as production spanner.
When using the fts
SNIPPETfunction the emulator's output schema diverges from what production spanner produces.Specifically, the emulator Returns
start_positionandend_positionas keys inside the highlights array (https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/blob/master/backend/query/search/snippet_evaluator.cc#L59-L60), whereas production returnsbeginandend.And it entirely omits the
source_beginandsource_endkeys at the snippet level (https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/blob/master/backend/query/search/snippet_evaluator.cc#L202)Given a query like
Production spanner returns
{ "snippets":[ { "highlights":[ { "begin":1, "end":5 } ], "snippet":"Test est", "source_begin":1, "source_end":9 } ] }This matches what is documented here https://docs.cloud.google.com/spanner/docs/reference/standard-sql/search_functions#snippet
The same query against the emulator returns
{ "snippets":[ { "highlights":[ { "start_position":1, "end_position":5 } ], "snippet":"Test est" } ] }Running Spanner Emulator Version: 1.5.54
Because of this discrepancy, application code and deserializers that work in production fail during local testing against the emulator unless environment-specific workarounds are added.
It would be nice if this could be fixed so the emulator returns the snippets using the same schema as production spanner.