Skip to content
Snippets Groups Projects
Unverified Commit 16ea112a authored by nnsgmsone's avatar nnsgmsone Committed by GitHub
Browse files

Add order and top operator (#2475)

parent 529f9c8f
No related branches found
No related tags found
No related merge requests found
Showing
with 965 additions and 0 deletions
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dates
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
process "github.com/matrixorigin/matrixone/pkg/vm/process2"
)
func New() *compare {
return &compare{
xs: make([][]types.Date, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2),
}
}
func (c *compare) Vector() *vector.Vector {
return c.vs[0]
}
func (c *compare) Set(idx int, v *vector.Vector) {
c.vs[idx] = v
c.ns[idx] = v.Nsp
c.xs[idx] = v.Col.([]types.Date)
}
func (c *compare) Compare(veci, vecj int, vi, vj int64) int {
if c.xs[veci][vi] == c.xs[vecj][vj] {
return 0
}
if c.xs[veci][vi] < c.xs[vecj][vj] {
return -1
}
return +1
}
func (c *compare) Copy(vecSrc, vecDst int, src, dst int64, _ *process.Process) error {
if nulls.Any(c.ns[vecSrc]) && nulls.Contains(c.ns[vecSrc], (uint64(src))) {
nulls.Add(c.ns[vecDst], (uint64(dst)))
} else {
nulls.Del(c.ns[vecDst], (uint64(dst)))
c.xs[vecDst][dst] = c.xs[vecSrc][src]
}
return nil
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dates
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/stretchr/testify/require"
"testing"
)
func TestNew(t *testing.T) {
require.Equal(t, &compare{xs: make([][]types.Date, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2)}, New())
}
func TestCompare_Vector(t *testing.T) {
c := New()
c.vs[0] = vector.New(types.Type{Oid: types.T(types.T_date)})
require.Equal(t, vector.New(types.Type{Oid: types.T(types.T_date)}), c.Vector())
}
func TestCompare_Set(t *testing.T) {
c := New()
vector := vector.New(types.Type{Oid: types.T(types.T_date)})
c.Set(1, vector)
require.Equal(t, vector, c.vs[1])
}
func TestCompare_Compare(t *testing.T) {
c := New()
c.xs[0] = []types.Date{5, 6}
c.xs[1] = []types.Date{7, 8}
result := c.Compare(0, 1, 0, 0)
require.Equal(t, -1, result)
c.xs[1] = []types.Date{5, 6}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 0, result)
c.xs[1] = []types.Date{3, 4}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 1, result)
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dates
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
)
type compare struct {
xs [][]types.Date
ns []*nulls.Nulls
vs []*vector.Vector
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package datetimes
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
process "github.com/matrixorigin/matrixone/pkg/vm/process2"
)
func New() *compare {
return &compare{
xs: make([][]types.Datetime, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2),
}
}
func (c *compare) Vector() *vector.Vector {
return c.vs[0]
}
func (c *compare) Set(idx int, v *vector.Vector) {
c.vs[idx] = v
c.ns[idx] = v.Nsp
c.xs[idx] = v.Col.([]types.Datetime)
}
func (c *compare) Compare(veci, vecj int, vi, vj int64) int {
if c.xs[veci][vi] == c.xs[vecj][vj] {
return 0
}
if c.xs[veci][vi] < c.xs[vecj][vj] {
return -1
}
return +1
}
func (c *compare) Copy(vecSrc, vecDst int, src, dst int64, _ *process.Process) error {
if nulls.Any(c.ns[vecSrc]) && nulls.Contains(c.ns[vecSrc], (uint64(src))) {
nulls.Add(c.ns[vecDst], (uint64(dst)))
} else {
nulls.Del(c.ns[vecDst], (uint64(dst)))
c.xs[vecDst][dst] = c.xs[vecSrc][src]
}
return nil
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package datetimes
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/stretchr/testify/require"
"testing"
)
func TestNew(t *testing.T) {
require.Equal(t, &compare{xs: make([][]types.Datetime, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2)}, New())
}
func TestCompare_Vector(t *testing.T) {
c := New()
c.vs[0] = vector.New(types.Type{Oid: types.T(types.T_datetime)})
require.Equal(t, vector.New(types.Type{Oid: types.T(types.T_datetime)}), c.Vector())
}
func TestCompare_Set(t *testing.T) {
c := New()
vector := vector.New(types.Type{Oid: types.T(types.T_datetime)})
c.Set(1, vector)
require.Equal(t, vector, c.vs[1])
}
func TestCompare_Compare(t *testing.T) {
c := New()
c.xs[0] = []types.Datetime{5, 6}
c.xs[1] = []types.Datetime{7, 8}
result := c.Compare(0, 1, 0, 0)
require.Equal(t, -1, result)
c.xs[1] = []types.Datetime{5, 6}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 0, result)
c.xs[1] = []types.Datetime{3, 4}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 1, result)
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package datetimes
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
)
type compare struct {
xs [][]types.Datetime
ns []*nulls.Nulls
vs []*vector.Vector
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package float32s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
process "github.com/matrixorigin/matrixone/pkg/vm/process2"
)
func New() *compare {
return &compare{
xs: make([][]float32, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2),
}
}
func (c *compare) Vector() *vector.Vector {
return c.vs[0]
}
func (c *compare) Set(idx int, v *vector.Vector) {
c.vs[idx] = v
c.ns[idx] = v.Nsp
c.xs[idx] = v.Col.([]float32)
}
func (c *compare) Compare(veci, vecj int, vi, vj int64) int {
if c.xs[veci][vi] == c.xs[vecj][vj] {
return 0
}
if c.xs[veci][vi] < c.xs[vecj][vj] {
return -1
}
return +1
}
func (c *compare) Copy(vecSrc, vecDst int, src, dst int64, _ *process.Process) error {
if nulls.Any(c.ns[vecSrc]) && nulls.Contains(c.ns[vecSrc], (uint64(src))) {
nulls.Add(c.ns[vecDst], (uint64(dst)))
} else {
nulls.Del(c.ns[vecDst], (uint64(dst)))
c.xs[vecDst][dst] = c.xs[vecSrc][src]
}
return nil
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package float32s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/stretchr/testify/require"
"testing"
)
func TestNew(t *testing.T) {
require.Equal(t, &compare{xs: make([][]float32, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2)}, New())
}
func TestCompare_Vector(t *testing.T) {
c := New()
c.vs[0] = vector.New(types.Type{Oid: types.T(types.T_float32)})
require.Equal(t, vector.New(types.Type{Oid: types.T(types.T_float32)}), c.Vector())
}
func TestCompare_Set(t *testing.T) {
c := New()
vector := vector.New(types.Type{Oid: types.T(types.T_float32)})
c.Set(1, vector)
require.Equal(t, vector, c.vs[1])
}
func TestCompare_Compare(t *testing.T) {
c := New()
c.xs[0] = []float32{5, 6}
c.xs[1] = []float32{7, 8}
result := c.Compare(0, 1, 0, 0)
require.Equal(t, -1, result)
c.xs[1] = []float32{5, 6}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 0, result)
c.xs[1] = []float32{3, 4}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 1, result)
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package float32s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
)
type compare struct {
xs [][]float32
ns []*nulls.Nulls
vs []*vector.Vector
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package float64s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
process "github.com/matrixorigin/matrixone/pkg/vm/process2"
)
func New() *compare {
return &compare{
xs: make([][]float64, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2),
}
}
func (c *compare) Vector() *vector.Vector {
return c.vs[0]
}
func (c *compare) Set(idx int, v *vector.Vector) {
c.vs[idx] = v
c.ns[idx] = v.Nsp
c.xs[idx] = v.Col.([]float64)
}
func (c *compare) Compare(veci, vecj int, vi, vj int64) int {
if c.xs[veci][vi] == c.xs[vecj][vj] {
return 0
}
if c.xs[veci][vi] < c.xs[vecj][vj] {
return -1
}
return +1
}
func (c *compare) Copy(vecSrc, vecDst int, src, dst int64, _ *process.Process) error {
if nulls.Any(c.ns[vecSrc]) && nulls.Contains(c.ns[vecSrc], (uint64(src))) {
nulls.Add(c.ns[vecDst], (uint64(dst)))
} else {
nulls.Del(c.ns[vecDst], (uint64(dst)))
c.xs[vecDst][dst] = c.xs[vecSrc][src]
}
return nil
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package float64s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/stretchr/testify/require"
"testing"
)
func TestNew(t *testing.T) {
require.Equal(t, &compare{xs: make([][]float64, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2)}, New())
}
func TestCompare_Vector(t *testing.T) {
c := New()
c.vs[0] = vector.New(types.Type{Oid: types.T(types.T_float64)})
require.Equal(t, vector.New(types.Type{Oid: types.T(types.T_float64)}), c.Vector())
}
func TestCompare_Set(t *testing.T) {
c := New()
vector := vector.New(types.Type{Oid: types.T(types.T_float64)})
c.Set(1, vector)
require.Equal(t, vector, c.vs[1])
}
func TestCompare_Compare(t *testing.T) {
c := New()
c.xs[0] = []float64{5, 6}
c.xs[1] = []float64{7, 8}
result := c.Compare(0, 1, 0, 0)
require.Equal(t, -1, result)
c.xs[1] = []float64{5, 6}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 0, result)
c.xs[1] = []float64{3, 4}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 1, result)
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package float64s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
)
type compare struct {
xs [][]float64
ns []*nulls.Nulls
vs []*vector.Vector
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package int16s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
process "github.com/matrixorigin/matrixone/pkg/vm/process2"
)
func New() *compare {
return &compare{
xs: make([][]int16, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2),
}
}
func (c *compare) Vector() *vector.Vector {
return c.vs[0]
}
func (c *compare) Set(idx int, v *vector.Vector) {
c.vs[idx] = v
c.ns[idx] = v.Nsp
c.xs[idx] = v.Col.([]int16)
}
func (c *compare) Compare(veci, vecj int, vi, vj int64) int {
if c.xs[veci][vi] == c.xs[vecj][vj] {
return 0
}
if c.xs[veci][vi] < c.xs[vecj][vj] {
return -1
}
return +1
}
func (c *compare) Copy(vecSrc, vecDst int, src, dst int64, _ *process.Process) error {
if nulls.Any(c.ns[vecSrc]) && nulls.Contains(c.ns[vecSrc], (uint64(src))) {
nulls.Add(c.ns[vecDst], (uint64(dst)))
} else {
nulls.Del(c.ns[vecDst], (uint64(dst)))
c.xs[vecDst][dst] = c.xs[vecSrc][src]
}
return nil
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package int16s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/stretchr/testify/require"
"testing"
)
func TestNew(t *testing.T) {
require.Equal(t, &compare{xs: make([][]int16, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2)}, New())
}
func TestCompare_Vector(t *testing.T) {
c := New()
c.vs[0] = vector.New(types.Type{Oid: types.T(types.T_int16)})
require.Equal(t, vector.New(types.Type{Oid: types.T(types.T_int16)}), c.Vector())
}
func TestCompare_Set(t *testing.T) {
c := New()
vector := vector.New(types.Type{Oid: types.T(types.T_int16)})
c.Set(1, vector)
require.Equal(t, vector, c.vs[1])
}
func TestCompare_Compare(t *testing.T) {
c := New()
c.xs[0] = []int16{5, 6}
c.xs[1] = []int16{7, 8}
result := c.Compare(0, 1, 0, 0)
require.Equal(t, -1, result)
c.xs[1] = []int16{5, 6}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 0, result)
c.xs[1] = []int16{3, 4}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 1, result)
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package int16s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
)
type compare struct {
xs [][]int16
ns []*nulls.Nulls
vs []*vector.Vector
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package int32s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
process "github.com/matrixorigin/matrixone/pkg/vm/process2"
)
func New() *compare {
return &compare{
xs: make([][]int32, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2),
}
}
func (c *compare) Vector() *vector.Vector {
return c.vs[0]
}
func (c *compare) Set(idx int, v *vector.Vector) {
c.vs[idx] = v
c.ns[idx] = v.Nsp
c.xs[idx] = v.Col.([]int32)
}
func (c *compare) Compare(veci, vecj int, vi, vj int64) int {
if c.xs[veci][vi] == c.xs[vecj][vj] {
return 0
}
if c.xs[veci][vi] < c.xs[vecj][vj] {
return -1
}
return +1
}
func (c *compare) Copy(vecSrc, vecDst int, src, dst int64, _ *process.Process) error {
if nulls.Any(c.ns[vecSrc]) && nulls.Contains(c.ns[vecSrc], (uint64(src))) {
nulls.Add(c.ns[vecDst], (uint64(dst)))
} else {
nulls.Del(c.ns[vecDst], (uint64(dst)))
c.xs[vecDst][dst] = c.xs[vecSrc][src]
}
return nil
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package int32s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/stretchr/testify/require"
"testing"
)
func TestNew(t *testing.T) {
require.Equal(t, &compare{xs: make([][]int32, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2)}, New())
}
func TestCompare_Vector(t *testing.T) {
c := New()
c.vs[0] = vector.New(types.Type{Oid: types.T(types.T_int32)})
require.Equal(t, vector.New(types.Type{Oid: types.T(types.T_int32)}), c.Vector())
}
func TestCompare_Set(t *testing.T) {
c := New()
vector := vector.New(types.Type{Oid: types.T(types.T_int32)})
c.Set(1, vector)
require.Equal(t, vector, c.vs[1])
}
func TestCompare_Compare(t *testing.T) {
c := New()
c.xs[0] = []int32{5, 6}
c.xs[1] = []int32{7, 8}
result := c.Compare(0, 1, 0, 0)
require.Equal(t, -1, result)
c.xs[1] = []int32{5, 6}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 0, result)
c.xs[1] = []int32{3, 4}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 1, result)
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package int32s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
)
type compare struct {
xs [][]int32
ns []*nulls.Nulls
vs []*vector.Vector
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package int64s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/vector"
process "github.com/matrixorigin/matrixone/pkg/vm/process2"
)
func New() *compare {
return &compare{
xs: make([][]int64, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2),
}
}
func (c *compare) Vector() *vector.Vector {
return c.vs[0]
}
func (c *compare) Set(idx int, v *vector.Vector) {
c.vs[idx] = v
c.ns[idx] = v.Nsp
c.xs[idx] = v.Col.([]int64)
}
func (c *compare) Compare(veci, vecj int, vi, vj int64) int {
if c.xs[veci][vi] == c.xs[vecj][vj] {
return 0
}
if c.xs[veci][vi] < c.xs[vecj][vj] {
return -1
}
return +1
}
func (c *compare) Copy(vecSrc, vecDst int, src, dst int64, _ *process.Process) error {
if nulls.Any(c.ns[vecSrc]) && nulls.Contains(c.ns[vecSrc], (uint64(src))) {
nulls.Add(c.ns[vecDst], (uint64(dst)))
} else {
nulls.Del(c.ns[vecDst], (uint64(dst)))
c.xs[vecDst][dst] = c.xs[vecSrc][src]
}
return nil
}
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package int64s
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/stretchr/testify/require"
"testing"
)
func TestNew(t *testing.T) {
require.Equal(t, &compare{xs: make([][]int64, 2),
ns: make([]*nulls.Nulls, 2),
vs: make([]*vector.Vector, 2)}, New())
}
func TestCompare_Vector(t *testing.T) {
c := New()
c.vs[0] = vector.New(types.Type{Oid: types.T(types.T_int64)})
require.Equal(t, vector.New(types.Type{Oid: types.T(types.T_int64)}), c.Vector())
}
func TestCompare_Set(t *testing.T) {
c := New()
vector := vector.New(types.Type{Oid: types.T(types.T_int64)})
c.Set(1, vector)
require.Equal(t, vector, c.vs[1])
}
func TestCompare_Compare(t *testing.T) {
c := New()
c.xs[0] = []int64{5, 6}
c.xs[1] = []int64{7, 8}
result := c.Compare(0, 1, 0, 0)
require.Equal(t, -1, result)
c.xs[1] = []int64{5, 6}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 0, result)
c.xs[1] = []int64{3, 4}
result = c.Compare(0, 1, 0, 0)
require.Equal(t, 1, result)
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment