Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
93011: tree: convert TSVECTOR and TSQUERY to JSON elements as strings r=rytaft,jordanlewis a=msirek

Fixes cockroachdb#92998

This adds support for converting TSVECTOR and TSQUERY data types to JSON elements via functions such as json_build_array.

Release note: None

93042: opt: update GenerateLookupJoinsWithVirtualCols comment r=mgartner a=mgartner

Epic: None

Release note: None

Co-authored-by: Mark Sirek <sirek@cockroachlabs.com>
Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com>
  • Loading branch information
3 people committed Dec 5, 2022
3 parents 14abdbf + 5506cf8 + 7e4b668 commit 969e6aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
13 changes: 13 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/tsvector
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ SELECT repeat('a', 1<<20)::tsvector

query error string is too long for tsquery
SELECT repeat('a', 1<<20)::tsquery

# TSVECTOR should convert to a JSON element as a string.
query T
VALUES ( json_build_array('''D'':236A,377C,622A ''SDfdZ'' ''aIjQScIT'':213A,418A,827A ''pHhJoarX'':106C,486C ''pjApqSC'' ''qXLpyjUM'':547C ''uWSPY'':10A,822B':::TSVECTOR)::JSONB
)
----
["'D':236A,377C,622A 'SDfdZ' 'aIjQScIT':213A,418A,827A 'pHhJoarX':106C,486C 'pjApqSC' 'qXLpyjUM':547C 'uWSPY':10A,822B"]

# TSQUERY should convert to a JSON element as a string.
query T
VALUES ( json_build_array($$'cat' & 'rat'$$:::TSQUERY)::JSONB)
----
["'cat' & 'rat'"]
12 changes: 3 additions & 9 deletions pkg/sql/opt/xform/join_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,9 @@ func (c *CustomFuncs) GenerateLookupJoins(
// |
// Scan(t)
//
// This function and its associated rule currently require that:
//
// 1. The join is an inner join.
// 2. The right side projects only virtual computed columns.
// 3. All the projected virtual columns are covered by a single index.
//
// It should be possible to support semi- and anti- joins. Left joins may be
// possible with additional complexity.
// TODO(mgartner): update this comment.
// This function and its associated rule currently require that the right side
// projects only virtual computed columns and all those columns are covered by a
// single index.
//
// It should also be possible to support cases where all the virtual columns are
// not covered by a single index by wrapping the lookup join in a Project that
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/sem/tree/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3712,7 +3712,8 @@ func AsJSON(
case *DTimestamp:
// This is RFC3339Nano, but without the TZ fields.
return json.FromString(formatTime(t.UTC(), "2006-01-02T15:04:05.999999999")), nil
case *DDate, *DUuid, *DOid, *DInterval, *DBytes, *DIPAddr, *DTime, *DTimeTZ, *DBitArray, *DBox2D:
case *DDate, *DUuid, *DOid, *DInterval, *DBytes, *DIPAddr, *DTime, *DTimeTZ, *DBitArray, *DBox2D,
*DTSVector, *DTSQuery:
return json.FromString(AsStringWithFlags(t, FmtBareStrings, FmtDataConversionConfig(dcc))), nil
case *DGeometry:
return json.FromSpatialObject(t.Geometry.SpatialObject(), geo.DefaultGeoJSONDecimalDigits)
Expand Down

0 comments on commit 969e6aa

Please sign in to comment.