Skip to content

Commit 1a2a6ae

Browse files
authored
fix: missing args for ParameterizedListType type resolution (#126)
Pass required information when resolving the return type of the parameterized list type
1 parent e6df514 commit 1a2a6ae

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

plan/plan_builder_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ func checkRoundTrip(t *testing.T, expectedJSON string, p *plan.Plan) {
166166
var expectedProto substraitproto.Plan
167167
require.NoError(t, protojson.Unmarshal([]byte(expectedJSON), &expectedProto))
168168

169+
// Equalize producer field; it may differ between golden JSON and protoPlan
170+
// depending on which OS (GOOS, ARCH, and the like) this test runs.
171+
protoPlan.Version.Producer = expectedProto.Version.Producer
172+
169173
assert.Truef(t, proto.Equal(&expectedProto, protoPlan), "JSON expected: %s\ngot: %s",
170174
protojson.Format(&expectedProto), protojson.Format(protoPlan))
171175

types/any_type_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestAnyType(t *testing.T) {
2020
expectedString string
2121
}{
2222
{"any", "any", []FuncDefArgType{&AnyType{Name: "any"}}, []Type{decP30S9}, decP30S9, NullabilityNullable, "any?"},
23+
{"List<any>", "any", []FuncDefArgType{&AnyType{Name: "any"}}, []Type{&ListType{Type: decP30S9}}, &ListType{Type: decP30S9}, NullabilityNullable, "any?"},
2324
{"anyrequired", "any2", []FuncDefArgType{&Int16Type{}, &AnyType{Name: "any2"}}, []Type{&Int16Type{}, &Int64Type{}}, &Int64Type{}, NullabilityRequired, "any2"},
2425
{"anyOtherName", "any1", []FuncDefArgType{&AnyType{Name: "any1"}, &Int32Type{}}, []Type{varchar37, &Int32Type{}}, varchar37, NullabilityNullable, "any1?"},
2526
{"T name", "T", []FuncDefArgType{&AnyType{Name: "U"}}, []Type{varchar37}, nil, NullabilityNullable, "T?"},

types/parameterized_list_type.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ func (m *ParameterizedListType) ShortString() string {
6464
return "list"
6565
}
6666

67-
func (m *ParameterizedListType) ReturnType([]FuncDefArgType, []Type) (Type, error) {
68-
elemType, err := m.Type.ReturnType(nil, nil)
67+
func (m *ParameterizedListType) ReturnType(
68+
funcParams []FuncDefArgType, argTypes []Type,
69+
) (Type, error) {
70+
elemType, err := m.Type.ReturnType(funcParams, argTypes)
6971
if err != nil {
7072
return nil, err
7173
}

types/parameterized_list_type_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ func TestParameterizedListType(t *testing.T) {
2929
expectedParameterizedParams []interface{}
3030
expectedReturnType types.Type
3131
}{
32-
{"parameterized param", decimalType, []any{dec30PS5}, "list?<decimal<P,S>>", "list<decimal<P,S>>", true, []interface{}{decimalType}, nil},
32+
{"parameterized param", decimalType, []any{dec30PS5}, "list?<decimal<P,S>>", "list<decimal<P,S>>", true, []interface{}{decimalType}, &types.ListType{Nullability: types.NullabilityRequired, Type: dec30PS5}},
3333
{"concrete param", int8Type, []any{int8Type}, "list?<i8>", "list<i8>", false, nil, &types.ListType{Nullability: types.NullabilityRequired, Type: int8Type}},
34+
{"list<any>", &types.AnyType{Name: "any"}, []any{int8Type}, "list?<any>", "list<any>", false, nil, &types.ListType{Nullability: types.NullabilityRequired, Type: int8Type}},
3435
} {
3536
t.Run(td.name, func(t *testing.T) {
3637
pd := &types.ParameterizedListType{Type: td.param}
@@ -41,7 +42,7 @@ func TestParameterizedListType(t *testing.T) {
4142
require.Equal(t, td.expectedHasParameterizedParam, pd.HasParameterizedParam())
4243
require.Equal(t, td.expectedParameterizedParams, pd.GetParameterizedParams())
4344
assert.Equal(t, "list", pd.ShortString())
44-
retType, err := pd.ReturnType(nil, nil)
45+
retType, err := pd.ReturnType([]types.FuncDefArgType{td.param}, []types.Type{td.args[0].(types.Type)})
4546
if td.expectedReturnType == nil {
4647
assert.Error(t, err)
4748
require.True(t, pd.HasParameterizedParam())

0 commit comments

Comments
 (0)