Skip to content

Commit 2dda5fd

Browse files
committed
sql: add jsonpath type support
As part of work to implement jsonpath queries, this PR implements the `jsonpath` type within CockroachDB. There is no parsing or evaluation added, and the `jsonpath` will currently accept any non-empty string. Table creation with jsonpath columns are not supported as of now until an encoding and decoding schema is determined. Indexes are not supported for `jsonpath` columns when they will be introduced. Part of: #22513 Release note (sql change): Adding jsonpath type, without parsing, evaluation, or table creation. Currently accepts any non-empty string.
1 parent fc06a34 commit 2dda5fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+835
-45
lines changed

docs/generated/sql/operators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@
479479
<tr><td><a href="interval.html">interval</a> <code>IS NOT DISTINCT FROM</code> <a href="interval.html">interval</a></td><td><a href="bool.html">bool</a></td></tr>
480480
<tr><td><a href="interval.html">interval[]</a> <code>IS NOT DISTINCT FROM</code> <a href="interval.html">interval[]</a></td><td><a href="bool.html">bool</a></td></tr>
481481
<tr><td>jsonb <code>IS NOT DISTINCT FROM</code> jsonb</td><td><a href="bool.html">bool</a></td></tr>
482+
<tr><td>jsonpath <code>IS NOT DISTINCT FROM</code> jsonpath</td><td><a href="bool.html">bool</a></td></tr>
482483
<tr><td>oid <code>IS NOT DISTINCT FROM</code> <a href="int.html">int</a></td><td><a href="bool.html">bool</a></td></tr>
483484
<tr><td>oid <code>IS NOT DISTINCT FROM</code> oid</td><td><a href="bool.html">bool</a></td></tr>
484485
<tr><td>pg_lsn <code>IS NOT DISTINCT FROM</code> pg_lsn</td><td><a href="bool.html">bool</a></td></tr>

pkg/ccl/changefeedccl/avro/avro.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ func typeToSchema(typ *types.T) (*SchemaField, error) {
644644
return tree.ParseDJSON(x.(string))
645645
},
646646
)
647+
// case types.JsonpathFamily:
648+
// We do not support Jsonpath yet, but should be able to support it easily.
647649
case types.TSQueryFamily:
648650
setNullable(
649651
SchemaTypeString,

pkg/ccl/changefeedccl/avro/avro_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ func TestAvroSchema(t *testing.T) {
318318
case types.AnyFamily, types.OidFamily, types.TupleFamily:
319319
// These aren't expected to be needed for changefeeds.
320320
return true
321-
case types.PGVectorFamily:
322-
// We don't support PGVector in Avro yet.
321+
case types.PGVectorFamily, types.JsonpathFamily:
322+
// We don't support PGVector and Jsonpath in Avro yet.
323323
return true
324324
case types.ArrayFamily:
325325
if !randgen.IsAllowedForArray(typ.ArrayContents()) {

pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local-read-committed/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local-repeatable-read/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/catalog/colinfo/col_type_info.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,19 @@ func ValidateColumnDefType(ctx context.Context, st *cluster.Settings, t *types.T
129129
// column in a regular FORWARD index.
130130
func ColumnTypeIsIndexable(t *types.T) bool {
131131
// NB: .IsAmbiguous checks the content type of array types.
132-
if t.IsAmbiguous() || t.Family() == types.TupleFamily || t.Family() == types.RefCursorFamily {
132+
if t.IsAmbiguous() {
133+
return false
134+
}
135+
136+
switch t.Family() {
137+
case types.TupleFamily, types.RefCursorFamily, types.JsonpathFamily:
133138
return false
134139
}
135140

136141
// If the type is an array, check its content type as well.
137142
if unwrapped := t.ArrayContents(); unwrapped != nil {
138-
if unwrapped.Family() == types.TupleFamily || unwrapped.Family() == types.RefCursorFamily {
143+
switch unwrapped.Family() {
144+
case types.TupleFamily, types.RefCursorFamily, types.JsonpathFamily:
139145
return false
140146
}
141147
}
@@ -150,7 +156,12 @@ func ColumnTypeIsIndexable(t *types.T) bool {
150156
func ColumnTypeIsInvertedIndexable(t *types.T) bool {
151157
switch t.Family() {
152158
case types.ArrayFamily:
153-
return t.ArrayContents().Family() != types.RefCursorFamily
159+
switch t.ArrayContents().Family() {
160+
case types.RefCursorFamily, types.JsonpathFamily:
161+
return false
162+
default:
163+
return true
164+
}
154165
case types.JsonFamily, types.StringFamily:
155166
return true
156167
}

pkg/sql/catalog/colinfo/column_type_properties.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ func CanHaveCompositeKeyEncoding(typ *types.T) bool {
8282
types.VoidFamily,
8383
types.EncodedKeyFamily,
8484
types.TSQueryFamily,
85-
types.TSVectorFamily:
85+
types.TSVectorFamily,
86+
types.JsonpathFamily:
8687
return false
8788
case types.UnknownFamily,
8889
types.AnyFamily:

pkg/sql/distsql_physical_planner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ func (v *distSQLExprCheckVisitor) VisitPre(expr tree.Expr) (recurse bool, newExp
356356
v.err = newQueryNotSupportedErrorf("tuple %s cannot be executed with distsql", t)
357357
return false, expr
358358
}
359+
case *tree.DJsonpath:
360+
// TODO(normanchenn): We currently do not have an encoding for jsonpath
361+
// thus do not support it within distsql
362+
v.err = newQueryNotSupportedErrorf("jsonpath %s cannot be executed with distsql", t)
363+
return false, expr
359364
}
360365
return true, expr
361366
}

pkg/sql/exec_util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,7 @@ func checkResultType(typ *types.T, fmtCode pgwirebase.FormatCode) error {
21542154
case types.TSVectorFamily:
21552155
case types.IntervalFamily:
21562156
case types.JsonFamily:
2157+
case types.JsonpathFamily:
21572158
case types.UuidFamily:
21582159
case types.INetFamily:
21592160
case types.OidFamily:

0 commit comments

Comments
 (0)