Skip to content

Discrepancy in json returned by fts SNIPPET function #355

Description

@Zarux

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions