Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
112975: sql: make `jsonb_array_to_string_array` return NULL elements r=maryliag a=maryliag

This commit makes the builtin `jsonb_array_to_string_array` return NULL elements, which were previously being removed. It also adds more testing for different types of elements on the array.

Followup from #112865 (review)

Epic: none

Release note (sql change): The newly added builting jsonb_array_to_string_array no longer removes NULL objects and includes them into the resulting array.

113165: roachtest: use QPS instead of TPS in disk-stall r=jbowens a=itsbilal

Previously, we'd see sporadic failures when the
count for TPS would fall more than the count of QPS before/after one node is stalled. This change moves to tracking QPS instead as that's what the workload binary is reporting too.

Fixes #112181.

Epic: none

Release note: None

Co-authored-by: maryliag <marylia@cockroachlabs.com>
Co-authored-by: Bilal Akhtar <bilal@cockroachlabs.com>
  • Loading branch information
3 people committed Oct 27, 2023
3 parents 39ea7d8 + acbd14f + 1e2e7db commit 385fd5e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
</span></td><td>Immutable</td></tr>
<tr><td><a name="cardinality"></a><code>cardinality(input: anyelement[]) &rarr; <a href="int.html">int</a></code></td><td><span class="funcdesc"><p>Calculates the number of elements contained in <code>input</code></p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="jsonb_array_to_string_array"></a><code>jsonb_array_to_string_array(input: jsonb) &rarr; <a href="string.html">string</a>[]</code></td><td><span class="funcdesc"><p>Convert a JSONB array into a string array, removing ‘null’ elements.</p>
<tr><td><a name="jsonb_array_to_string_array"></a><code>jsonb_array_to_string_array(input: jsonb) &rarr; <a href="string.html">string</a>[]</code></td><td><span class="funcdesc"><p>Convert a JSONB array into a string array.</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="string_to_array"></a><code>string_to_array(str: <a href="string.html">string</a>, delimiter: <a href="string.html">string</a>) &rarr; <a href="string.html">string</a>[]</code></td><td><span class="funcdesc"><p>Split a string into components on a delimiter.</p>
</span></td><td>Immutable</td></tr>
Expand Down
22 changes: 11 additions & 11 deletions pkg/cmd/roachtest/tests/disk_stall.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ func runDiskStalledDetection(

stallAt := timeutil.Now()
response := mustGetMetrics(t, adminURL, workloadStartAt, stallAt, []tsQuery{
{name: "cr.node.txn.commits", queryType: total},
{name: "cr.node.sql.query.count", queryType: total},
})
cum := response.Results[0].Datapoints
totalTxnsPreStall := cum[len(cum)-1].Value - cum[0].Value
t.L().PrintfCtx(ctx, "%.2f transactions completed before stall", totalTxnsPreStall)
totalQueriesPreStall := cum[len(cum)-1].Value - cum[0].Value
t.L().PrintfCtx(ctx, "%.2f queries completed before stall", totalQueriesPreStall)

t.Status("inducing write stall")
if doStall {
Expand Down Expand Up @@ -202,16 +202,16 @@ func runDiskStalledDetection(
{
now := timeutil.Now()
response := mustGetMetrics(t, adminURL, workloadStartAt, now, []tsQuery{
{name: "cr.node.txn.commits", queryType: total},
{name: "cr.node.sql.query.count", queryType: total},
})
cum := response.Results[0].Datapoints
totalTxnsPostStall := cum[len(cum)-1].Value - totalTxnsPreStall
preStallTPS := totalTxnsPreStall / stallAt.Sub(workloadStartAt).Seconds()
postStallTPS := totalTxnsPostStall / workloadAfterDur.Seconds()
t.L().PrintfCtx(ctx, "%.2f total transactions committed after stall\n", totalTxnsPostStall)
t.L().PrintfCtx(ctx, "pre-stall tps: %.2f, post-stall tps: %.2f\n", preStallTPS, postStallTPS)
if postStallTPS < preStallTPS/2 {
t.Fatalf("post-stall TPS %.2f is less than 50%% of pre-stall TPS %.2f", postStallTPS, preStallTPS)
totalQueriesPostStall := cum[len(cum)-1].Value - totalQueriesPreStall
preStallQPS := totalQueriesPreStall / stallAt.Sub(workloadStartAt).Seconds()
postStallQPS := totalQueriesPostStall / workloadAfterDur.Seconds()
t.L().PrintfCtx(ctx, "%.2f total queries committed after stall\n", totalQueriesPostStall)
t.L().PrintfCtx(ctx, "pre-stall qps: %.2f, post-stall qps: %.2f\n", preStallQPS, postStallQPS)
if postStallQPS < preStallQPS/2 {
t.Fatalf("post-stall QPS %.2f is less than 50%% of pre-stall QPS %.2f", postStallQPS, preStallQPS)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/array
Original file line number Diff line number Diff line change
Expand Up @@ -1228,12 +1228,12 @@ SELECT jsonb_array_to_string_array('[true, false, false, true]':::JSONB)
query T
SELECT jsonb_array_to_string_array('[null]':::JSONB)
----
{}
{NULL}

query T
SELECT jsonb_array_to_string_array('["foo", null]':::JSONB)
SELECT jsonb_array_to_string_array('[1, "abc", true, ["a", "b"], {"b": "foo"}, null]':::JSONB)
----
{foo}
{1,abc,true,"[\"a\", \"b\"]","{\"b\": \"foo\"}",NULL}

# Regression test for #23429.

Expand Down
7 changes: 6 additions & 1 deletion pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -3571,11 +3571,16 @@ value if you rely on the HLC for accuracy.`,
if err != nil {
return nil, err
}
} else {
err = strArray.Append(tree.DNull)
if err != nil {
return nil, err
}
}
}
return strArray, nil
},
Info: "Convert a JSONB array into a string array, removing 'null' elements.",
Info: "Convert a JSONB array into a string array.",
Volatility: volatility.Immutable,
CalledOnNullInput: true,
}),
Expand Down

0 comments on commit 385fd5e

Please sign in to comment.