Skip to content

Commit

Permalink
builtins: use IdentityReturnType when possible
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
rafiss committed Sep 21, 2021
1 parent 16ea3e8 commit 7857b72
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
8 changes: 4 additions & 4 deletions docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,9 @@ the locality flag on node startup. Returns an error if no region is set.</p>
</span></td></tr>
<tr><td><a name="json_object_keys"></a><code>json_object_keys(input: jsonb) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns sorted set of keys in the outermost JSON object.</p>
</span></td></tr>
<tr><td><a name="json_populate_record"></a><code>json_populate_record(base: anyelement, from_json: jsonb) &rarr; anyelement</code></td><td><span class="funcdesc"><p>Expands the object in from_json to a row whose columns match the record type defined by base.</p>
<tr><td><a name="json_populate_record"></a><code>json_populate_record(base: tuple, from_json: jsonb) &rarr; tuple</code></td><td><span class="funcdesc"><p>Expands the object in from_json to a row whose columns match the record type defined by base.</p>
</span></td></tr>
<tr><td><a name="json_populate_recordset"></a><code>json_populate_recordset(base: anyelement, from_json: jsonb) &rarr; anyelement</code></td><td><span class="funcdesc"><p>Expands the outermost array of objects in from_json to a set of rows whose columns match the record type defined by base</p>
<tr><td><a name="json_populate_recordset"></a><code>json_populate_recordset(base: tuple, from_json: jsonb) &rarr; tuple</code></td><td><span class="funcdesc"><p>Expands the outermost array of objects in from_json to a set of rows whose columns match the record type defined by base</p>
</span></td></tr>
<tr><td><a name="jsonb_array_elements"></a><code>jsonb_array_elements(input: jsonb) &rarr; jsonb</code></td><td><span class="funcdesc"><p>Expands a JSON array to a set of JSON values.</p>
</span></td></tr>
Expand All @@ -1147,9 +1147,9 @@ the locality flag on node startup. Returns an error if no region is set.</p>
</span></td></tr>
<tr><td><a name="jsonb_object_keys"></a><code>jsonb_object_keys(input: jsonb) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns sorted set of keys in the outermost JSON object.</p>
</span></td></tr>
<tr><td><a name="jsonb_populate_record"></a><code>jsonb_populate_record(base: anyelement, from_json: jsonb) &rarr; anyelement</code></td><td><span class="funcdesc"><p>Expands the object in from_json to a row whose columns match the record type defined by base.</p>
<tr><td><a name="jsonb_populate_record"></a><code>jsonb_populate_record(base: tuple, from_json: jsonb) &rarr; tuple</code></td><td><span class="funcdesc"><p>Expands the object in from_json to a row whose columns match the record type defined by base.</p>
</span></td></tr>
<tr><td><a name="jsonb_populate_recordset"></a><code>jsonb_populate_recordset(base: anyelement, from_json: jsonb) &rarr; anyelement</code></td><td><span class="funcdesc"><p>Expands the outermost array of objects in from_json to a set of rows whose columns match the record type defined by base</p>
<tr><td><a name="jsonb_populate_recordset"></a><code>jsonb_populate_recordset(base: tuple, from_json: jsonb) &rarr; tuple</code></td><td><span class="funcdesc"><p>Expands the outermost array of objects in from_json to a set of rows whose columns match the record type defined by base</p>
</span></td></tr>
<tr><td><a name="pg_get_keywords"></a><code>pg_get_keywords() &rarr; tuple{string AS word, string AS catcode, string AS catdesc}</code></td><td><span class="funcdesc"><p>Produces a virtual table containing the keywords known to the SQL parser.</p>
</span></td></tr>
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,7 @@ value if you rely on the HLC for accuracy.`,
"array_append": setProps(arrayPropsNullableArgs(), arrayBuiltin(func(typ *types.T) tree.Overload {
return tree.Overload{
Types: tree.ArgTypes{{"array", types.MakeArray(typ)}, {"elem", typ}},
ReturnType: tree.FixedReturnType(types.MakeArray(typ)),
ReturnType: tree.IdentityReturnType(0),
Fn: func(_ *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
return tree.AppendToMaybeNullArray(typ, args[0], args[1])
},
Expand All @@ -3446,7 +3446,7 @@ value if you rely on the HLC for accuracy.`,
"array_prepend": setProps(arrayPropsNullableArgs(), arrayBuiltin(func(typ *types.T) tree.Overload {
return tree.Overload{
Types: tree.ArgTypes{{"elem", typ}, {"array", types.MakeArray(typ)}},
ReturnType: tree.FixedReturnType(types.MakeArray(typ)),
ReturnType: tree.IdentityReturnType(1),
Fn: func(_ *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
return tree.PrependToMaybeNullArray(typ, args[0], args[1])
},
Expand All @@ -3470,7 +3470,7 @@ value if you rely on the HLC for accuracy.`,
"array_remove": setProps(arrayPropsNullableArgs(), arrayBuiltin(func(typ *types.T) tree.Overload {
return tree.Overload{
Types: tree.ArgTypes{{"array", types.MakeArray(typ)}, {"elem", typ}},
ReturnType: tree.FixedReturnType(types.MakeArray(typ)),
ReturnType: tree.IdentityReturnType(0),
Fn: func(ctx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
if args[0] == tree.DNull {
return tree.DNull, nil
Expand All @@ -3493,7 +3493,7 @@ value if you rely on the HLC for accuracy.`,
"array_replace": setProps(arrayPropsNullableArgs(), arrayBuiltin(func(typ *types.T) tree.Overload {
return tree.Overload{
Types: tree.ArgTypes{{"array", types.MakeArray(typ)}, {"toreplace", typ}, {"replacewith", typ}},
ReturnType: tree.FixedReturnType(types.MakeArray(typ)),
ReturnType: tree.IdentityReturnType(0),
Fn: func(ctx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
if args[0] == tree.DNull {
return tree.DNull, nil
Expand Down
9 changes: 2 additions & 7 deletions pkg/sql/sem/builtins/generator_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,13 +1261,8 @@ func makeJSONPopulateImpl(gen tree.GeneratorWithExprsFactory, info string) tree.
// the default values of each field will be NULL.
// The second argument can also be null, in which case the first argument
// is returned as-is.
Types: tree.ArgTypes{{"base", types.Any}, {"from_json", types.Jsonb}},
ReturnType: func(args []tree.TypedExpr) *types.T {
if len(args) != 2 {
return tree.UnknownReturnType
}
return args[0].ResolvedType()
},
Types: tree.ArgTypes{{"base", types.AnyTuple}, {"from_json", types.Jsonb}},
ReturnType: tree.IdentityReturnType(0),
GeneratorWithExprs: gen,
Info: info,
Volatility: tree.VolatilityStable,
Expand Down

0 comments on commit 7857b72

Please sign in to comment.