-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
65497: sql: preliminary work for BatchReceiver introduction r=yuzefovich a=yuzefovich See individual commits for details. This PR extracts the preliminary work for the introduction of `BatchReceiver` in #65289. Co-authored-by: Yahor Yuzefovich <[email protected]>
- Loading branch information
Showing
25 changed files
with
628 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package colconv | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/col/coldata" | ||
) | ||
|
||
func init() { | ||
coldata.VecsToStringWithRowPrefix = vecsToStringWithRowPrefix | ||
} | ||
|
||
// vecsToStringWithRowPrefix returns a pretty representation of the vectors with | ||
// each row being in a separate string. | ||
func vecsToStringWithRowPrefix(vecs []coldata.Vec, length int, sel []int, prefix string) []string { | ||
var builder strings.Builder | ||
converter := NewAllVecToDatumConverter(len(vecs)) | ||
defer converter.Release() | ||
converter.ConvertVecs(vecs, length, sel) | ||
result := make([]string, length) | ||
strs := make([]string, len(vecs)) | ||
for i := 0; i < length; i++ { | ||
builder.Reset() | ||
rowIdx := i | ||
if sel != nil { | ||
rowIdx = sel[i] | ||
} | ||
builder.WriteString(prefix + "[") | ||
for colIdx := 0; colIdx < len(vecs); colIdx++ { | ||
strs[colIdx] = converter.GetDatumColumn(colIdx)[rowIdx].String() | ||
} | ||
builder.WriteString(strings.Join(strs, " ")) | ||
builder.WriteString("]") | ||
result[i] = builder.String() | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package colconv | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/col/coldata" | ||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestVecsToStringWithRowPrefix(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
vec := coldata.NewMemColumn(types.String, coldata.BatchSize(), coldata.StandardColumnFactory) | ||
input := []string{"one", "two", "three"} | ||
for i := range input { | ||
vec.Bytes().Set(i, []byte(input[i])) | ||
} | ||
getExpected := func(length int, sel []int, prefix string) []string { | ||
result := make([]string, length) | ||
for i := 0; i < length; i++ { | ||
rowIdx := i | ||
if sel != nil { | ||
rowIdx = sel[i] | ||
} | ||
result[i] = prefix + "['" + input[rowIdx] + "']" | ||
} | ||
return result | ||
} | ||
for _, tc := range []struct { | ||
length int | ||
sel []int | ||
prefix string | ||
}{ | ||
{length: 3}, | ||
{length: 2, sel: []int{0, 2}}, | ||
{length: 3, prefix: "row: "}, | ||
{length: 2, sel: []int{0, 2}, prefix: "row: "}, | ||
} { | ||
require.Equal(t, getExpected(tc.length, tc.sel, tc.prefix), vecsToStringWithRowPrefix([]coldata.Vec{vec}, tc.length, tc.sel, tc.prefix)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.