Skip to content

Commit

Permalink
col...: introduce new package and more code movement
Browse files Browse the repository at this point in the history
Move `coldata/random_testutils.go` into newly created package
`coldatatestutils`.

Move contents of `colbase/random_testutils.go` into `coldatatestutils`
package.

Rename `colbase` to `colexecbase`. Also remove templated comments from
import sections of `_tmpl` files in favor of adding vars that remove
unused warnings (those templated comments work poorly when
moving/renaming the dependencies).

Rename `vecerror` to `colexecerror`.

Move `CopyBatch` from `colexecbase` into `coldatatestutils`. Also remove
memory accounting from `CopyBatch`.

Move `typeconv` from `colexecbase` into `coltypes` folder.

Move `coldata/vec_test.go` into `coldata_test` package to prevent an
import cycle. Also move one unit test from `coldata/vec_test.go` into
`coldata/bytes_test.go`.

Move `colexecbase/allocator.go` into newly created `colmem` package.

Release note: None
  • Loading branch information
yuzefovich committed Apr 21, 2020
1 parent a051b0b commit f819fcd
Show file tree
Hide file tree
Showing 164 changed files with 1,718 additions and 1,647 deletions.
2 changes: 1 addition & 1 deletion pkg/col/coldata/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"sync/atomic"

"github.com/cockroachdb/cockroach/pkg/col/coltypes"
"github.com/cockroachdb/cockroach/pkg/sql/colbase/typeconv"
"github.com/cockroachdb/cockroach/pkg/col/coltypes/typeconv"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/col/coldata/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/col/coldata"
"github.com/cockroachdb/cockroach/pkg/col/coltypes"
"github.com/cockroachdb/cockroach/pkg/sql/colbase/typeconv"
"github.com/cockroachdb/cockroach/pkg/col/coltypes/typeconv"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/stretchr/testify/assert"
Expand Down
55 changes: 55 additions & 0 deletions pkg/col/coldata/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"testing"
"unsafe"

"github.com/cockroachdb/cockroach/pkg/col/coltypes"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/pkg/errors"
Expand Down Expand Up @@ -412,3 +414,56 @@ func TestBytes(t *testing.T) {
other.AssertOffsetsAreNonDecreasing(4)
})
}

// TestAppendBytesWithLastNull makes sure that Append handles correctly the
// case when the last element of Bytes vector is NULL.
func TestAppendBytesWithLastNull(t *testing.T) {
src := NewMemColumn(types.Bytes, 4)
sel := []int{0, 2, 3}
src.Bytes().Set(0, []byte("zero"))
src.Nulls().SetNull(1)
src.Bytes().Set(2, []byte("two"))
src.Nulls().SetNull(3)
sliceArgs := SliceArgs{
Src: src,
ColType: coltypes.Bytes,
DestIdx: 0,
SrcStartIdx: 0,
SrcEndIdx: len(sel),
}
dest := NewMemColumn(types.Bytes, 3)
expected := NewMemColumn(types.Bytes, 3)
for _, withSel := range []bool{false, true} {
t.Run(fmt.Sprintf("AppendBytesWithLastNull/sel=%t", withSel), func(t *testing.T) {
expected.Nulls().UnsetNulls()
expected.Bytes().Reset()
if withSel {
sliceArgs.Sel = sel
for expIdx, srcIdx := range sel {
if src.Nulls().NullAt(srcIdx) {
expected.Nulls().SetNull(expIdx)
} else {
expected.Bytes().Set(expIdx, src.Bytes().Get(srcIdx))
}
}
} else {
sliceArgs.Sel = nil
for expIdx := 0; expIdx < 3; expIdx++ {
if src.Nulls().NullAt(expIdx) {
expected.Nulls().SetNull(expIdx)
} else {
expected.Bytes().Set(expIdx, src.Bytes().Get(expIdx))
}
}
}
expected.Bytes().UpdateOffsetsToBeNonDecreasing(3)
// require.Equal checks the "string-ified" versions of the vectors for
// equality. Bytes uses maxSetIndex to print out "truncated"
// representation, so we manually update it (Vec.Append will use
// AppendVal function that updates maxSetIndex itself).
expected.Bytes().maxSetIndex = 2
dest.Append(sliceArgs)
require.Equal(t, expected, dest)
})
}
}
129 changes: 0 additions & 129 deletions pkg/col/coldata/random_testutils.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/col/coldata/vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/cockroachdb/apd"
"github.com/cockroachdb/cockroach/pkg/col/coltypes"
"github.com/cockroachdb/cockroach/pkg/sql/colbase/typeconv"
"github.com/cockroachdb/cockroach/pkg/col/coltypes/typeconv"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/duration"
)
Expand Down
Loading

0 comments on commit f819fcd

Please sign in to comment.