Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Jan 14, 2025
1 parent 455fe86 commit 9e65644
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 23 deletions.
34 changes: 13 additions & 21 deletions go/vt/vtgate/engine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions go/vt/vtgate/engine/join_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ type ValuesJoin struct {
// of the Join. They can be any primitive.
Left, Right Primitive

Vars map[string]int
Columns []string
Vars []int
RowConstructorArg string
Cols []int
ColNames []string
}

// TryExecute performs a non-streaming exec.
Expand Down
98 changes: 98 additions & 0 deletions go/vt/vtgate/engine/join_values_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright 2025 The Vitess Authors.
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 engine

import (
"context"
"testing"

"github.com/stretchr/testify/require"
"vitess.io/vitess/go/sqltypes"
querypb "vitess.io/vitess/go/vt/proto/query"
)

func TestJoinValuesExecute(t *testing.T) {

/*
select col1, col2, col3, col4, col5, col6 from left join right on left.col1 = right.col4
LHS: select col1, col2, col3 from left
RHS: select id, col5, col6 from (values row(1,2), ...) left(id,col1) join right on left.col1 = right.col4
*/

leftPrim := &fakePrimitive{
results: []*sqltypes.Result{
sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
"col1|col2|col3",
"int64|varchar|varchar",
),
"1|a|aa",
"2|b|bb",
"3|c|cc",
"4|d|dd",
),
},
}
rightPrim := &fakePrimitive{
results: []*sqltypes.Result{
sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
"id|col5|col6",
"int64|varchar|varchar",
),
"1|d|dd",
"2|e|ee",
"3|f|ff",
"4|g|gg",
),
},
}

bv := map[string]*querypb.BindVariable{
"a": sqltypes.Int64BindVariable(10),
}

vjn := &ValuesJoin{
Left: leftPrim,
Right: rightPrim,
Vars: []int{0},
RowConstructorArg: "v",
Cols: []int{-1, -2, -3, -1, 2, 3},
ColNames: []string{"col1", "col2", "col3", "col4", "col5", "col6"},
}

r, err := vjn.TryExecute(context.Background(), &noopVCursor{}, bv, true)
require.NoError(t, err)
leftPrim.ExpectLog(t, []string{
`Execute a: type:INT64 value:"10" true`,
})
rightPrim.ExpectLog(t, []string{
`Execute a: type:INT64 value:"10" v: type:TUPLE values:{type:TUPLE value:"\x89\x02\x011\x950\x01a\x950\x02aa"} values:{type:TUPLE value:"\x89\x02\x012\x950\x01b\x950\x02bb"} values:{type:TUPLE value:"\x89\x02\x013\x950\x01c\x950\x02cc"} values:{type:TUPLE value:"\x89\x02\x014\x950\x01d\x950\x02dd"} true`,
})

result := sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
"col1|col2|col3|col4|col5|col6",
"int64|varchar|varchar|int64|varchar|varchar",
),
"1|a|aa|1|d|dd",
"2|b|bb|2|e|ee",
"3|c|cc|3|f|ff",
"4|d|dd|4|g|gg",
)
expectResult(t, r, result)
}

0 comments on commit 9e65644

Please sign in to comment.