GoogleCloudPlatform / GoogleCloudPlatform/cloud-spanner-emulator

Discrepancy in json returned by fts `SNIPPET` function

Open
#355 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
334
Forks
77
Avg merge
8m
Merged PRs (30d)
2

Description

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
```sql
SELECT
SNIPPET(content, "test"),
FROM
test_table
WHERE
SEARCH(content_tokens, "test")
```

Production spanner returns

```json
{
"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
```json
{
"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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.