Skip to content

Commit

Permalink
feat(builders): Remove requirement for VirtualTableReadRel having col…
Browse files Browse the repository at this point in the history
…umns (#31)

* feat(builders): Remove requirement for VirtualTableReadRel having columns

* remove commented out code
  • Loading branch information
zeroshade authored Jul 18, 2024
1 parent ddc550e commit 1c9dd98
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
github.com/alecthomas/assert/v2 v2.0.3 h1:WKqJODfOiQG0nEJKFKzDIG3E29CN2/4zR9XGJzKIkbg=
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
github.com/alecthomas/participle/v2 v2.0.0-beta.5 h1:y6dsSYVb1G5eK6mgmy+BgI3Mw35a3WghArZ/Hbebrjo=
github.com/alecthomas/participle/v2 v2.0.0-beta.5/go.mod h1:RC764t6n4L8D8ITAJv0qdokritYSNR3wV5cVwmIEaMM=
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=
github.com/alecthomas/participle/v2 v2.0.0/go.mod h1:rAKZdJldHu8084ojcWevWAL8KmEU+AT+Olodb+WoN2Y=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
4 changes: 0 additions & 4 deletions plan/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,6 @@ func (b *builder) VirtualTableRemap(fieldNames []string, remap []int32, values .
}

nfields := len(fieldNames)
if nfields == 0 {
return nil, fmt.Errorf("%w: must provide at least 1 field for virtual table", substraitgo.ErrInvalidRel)
}

if len(values[0]) != nfields {
return nil, fmt.Errorf("%w: mismatched number of fields (%d) and literal values (%d) in virtual table",
substraitgo.ErrInvalidRel, nfields, len(values[0]))
Expand Down
56 changes: 56 additions & 0 deletions plan/plan_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,62 @@ func TestSetRelations(t *testing.T) {
checkRoundTrip(t, expectedJSON, p)
}

func TestEmptyVirtualTable(t *testing.T) {
const expectedJSON = `{
` + versionStruct + `,
"relations": [
{
"root": {
"input": {
"read": {
"common": {"direct":{}},
"baseSchema": {
"struct": {
"nullability": "NULLABILITY_REQUIRED"
}
},
"virtualTable": {
"values": [
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{}
]
}
}
}
}
}
]
}`

b := plan.NewBuilderDefault()

virtual, err := b.VirtualTable(nil, make([]expr.StructLiteralValue, 20)...)
require.NoError(t, err)

p, err := b.Plan(virtual, []string{})
require.NoError(t, err)

checkRoundTrip(t, expectedJSON, p)
}

func TestSetRelErrors(t *testing.T) {
b := plan.NewBuilderDefault()

Expand Down

0 comments on commit 1c9dd98

Please sign in to comment.