Skip to content

Commit 588418e

Browse files
committed
feat: add EmptyVirtualTable to Builder interface
BREAKING CHANGE: Builder interface has new EmptyVirtualTable method
1 parent 19df42f commit 588418e

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

plan/builders.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ type Builder interface {
124124
// Deprecated: Use VirtualTableFromExpr(...).Remap() instead.
125125
VirtualTableFromExprRemap(fieldNames []string, remap []int32, values ...expr.VirtualTableExpressionValue) (*VirtualTableReadRel, error)
126126
VirtualTableFromExpr(fieldNames []string, values ...expr.VirtualTableExpressionValue) (*VirtualTableReadRel, error)
127+
EmptyVirtualTable(fieldNames []string, types []types.Type) (*VirtualTableReadRel, error)
127128
IcebergTableFromMetadataFile(metadataURI string, snapshot IcebergSnapshot, schema types.NamedStruct) (*IcebergTableReadRel, error)
128129
// Deprecated: Use Sort(...).Remap() instead.
129130
SortRemap(input Rel, remap []int32, sorts ...expr.SortField) (*SortRel, error)
@@ -619,6 +620,21 @@ func (b *builder) VirtualTable(fields []string, values ...expr.StructLiteralValu
619620
return b.VirtualTableRemap(fields, nil, values...)
620621
}
621622

623+
func (b *builder) EmptyVirtualTable(fieldNames []string, typeList []types.Type) (*VirtualTableReadRel, error) {
624+
baseSchema := types.NamedStruct{
625+
Names: fieldNames,
626+
Struct: types.StructType{
627+
Nullability: types.NullabilityRequired,
628+
Types: typeList,
629+
},
630+
}
631+
return &VirtualTableReadRel{
632+
baseReadRel: baseReadRel{
633+
baseSchema: baseSchema,
634+
},
635+
}, nil
636+
}
637+
622638
func (b *builder) IcebergTableFromMetadataFile(metadataURI string, snapshot IcebergSnapshot, schema types.NamedStruct) (*IcebergTableReadRel, error) {
623639
tableType := &Direct{}
624640
tableType.MetadataUri = metadataURI

plan/plan_builder_test.go

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ func TestSetRelations(t *testing.T) {
16291629
checkRoundTrip(t, expectedJSON, p)
16301630
}
16311631

1632-
func TestEmptyVirtualTable(t *testing.T) {
1632+
func TestColumnlessVirtualTable(t *testing.T) {
16331633
const expectedJSON = `{
16341634
` + versionStruct + `,
16351635
"relations": [
@@ -1647,24 +1647,7 @@ func TestEmptyVirtualTable(t *testing.T) {
16471647
"expressions": [
16481648
{},
16491649
{},
1650-
{},
1651-
{},
1652-
{},
1653-
{},
1654-
{},
1655-
{},
1656-
{},
1657-
{},
1658-
{},
1659-
{},
1660-
{},
1661-
{},
1662-
{},
1663-
{},
1664-
{},
1665-
{},
1666-
{},
1667-
{}
1650+
{}
16681651
]
16691652
}
16701653
}
@@ -1676,7 +1659,7 @@ func TestEmptyVirtualTable(t *testing.T) {
16761659

16771660
b := plan.NewBuilderDefault()
16781661

1679-
virtual, err := b.VirtualTable(nil, make([]expr.StructLiteralValue, 20)...)
1662+
virtual, err := b.VirtualTable(nil, make([]expr.StructLiteralValue, 3)...)
16801663
require.NoError(t, err)
16811664

16821665
p, err := b.Plan(virtual, []string{})
@@ -1685,6 +1668,45 @@ func TestEmptyVirtualTable(t *testing.T) {
16851668
checkRoundTrip(t, expectedJSON, p)
16861669
}
16871670

1671+
func TestEmptyVirtualTable(t *testing.T) {
1672+
const expectedJSON = `{
1673+
` + versionStruct + `,
1674+
"relations": [
1675+
{
1676+
"root": {
1677+
"input": {
1678+
"read": {
1679+
"common": {"direct":{}},
1680+
"baseSchema": {
1681+
"names": ["i"],
1682+
"struct": {
1683+
"types": [
1684+
{"i32": {"nullability": "NULLABILITY_REQUIRED"}}
1685+
],
1686+
"nullability": "NULLABILITY_REQUIRED"
1687+
}
1688+
},
1689+
"virtualTable": {}
1690+
}
1691+
},
1692+
"names": ["i"]
1693+
}
1694+
}
1695+
]
1696+
}`
1697+
1698+
b := plan.NewBuilderDefault()
1699+
1700+
i32Type := types.Int32Type{Nullability: types.NullabilityRequired}
1701+
virtual, err := b.EmptyVirtualTable([]string{"i"}, []types.Type{&i32Type})
1702+
require.NoError(t, err)
1703+
1704+
p, err := b.Plan(virtual, []string{"i"})
1705+
require.NoError(t, err)
1706+
1707+
checkRoundTrip(t, expectedJSON, p)
1708+
}
1709+
16881710
func TestSetRelErrors(t *testing.T) {
16891711
b := plan.NewBuilderDefault()
16901712

0 commit comments

Comments
 (0)