-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add lambda expression support #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
benbellick
merged 112 commits into
substrait-io:main
from
Slimsammylim:slim/adding-lambda-support
Feb 6, 2026
Merged
Changes from 55 commits
Commits
Show all changes
112 commits
Select commit
Hold shift + click to select a range
29ebf33
First try at lambda support
Slimsammylim 86704d5
Changing code to use the builder pattern
Slimsammylim bdae181
Adding an extra guard for invalid plans when we try to resolve types
Slimsammylim 4b6ef3b
Changing the builder struct to not use interface{}
Slimsammylim 941b5a5
Adding clarifying comments
Slimsammylim c63aca6
Making visitors recursive
Slimsammylim a76e2ac
Handling when a body is a lambda when resolving param types
Slimsammylim 9b64203
Adding tests for basic functions
Slimsammylim 2d8ac51
More test coverage
Slimsammylim 86b2046
Validation Error test cases
Slimsammylim 49ce3d2
Update expr/field_reference.go
Slimsammylim e77547b
Update expr/lambda_test.go
Slimsammylim 1c283a7
Update expr/lambda_test.go
Slimsammylim b787bb3
Update expr/lambda_test.go
Slimsammylim 6db3eb1
Update expr/lambda_test.go
Slimsammylim 9aa140d
Using URNs not URIs
Slimsammylim 30b650e
Using the builder interface in builder.go
Slimsammylim 0966f42
Using a full plan for TestLambdaWithFunctionExprFromProto
Slimsammylim b05f2e0
Removing redundant getters and unnecessary tests
Slimsammylim c639da5
Editing tests and comments to make it clear that a lambda can have no…
Slimsammylim 87590bd
Removing unnecessary comments
Slimsammylim 153cdae
Fixing inconsistent testcase
Slimsammylim 3f908c7
Adding coverage for Equals() for field references
Slimsammylim 4384248
Adding basic validation checks for lambdas in ExprFromProto
Slimsammylim fc1e121
Update expr/builder.go
Slimsammylim 816b375
Update expr/builder.go
Slimsammylim d4b0ee5
Update expr/builder.go
Slimsammylim 122ff0c
Update expr/builder.go
Slimsammylim 70af94a
Making body an input to constructor
Slimsammylim e311de6
Merge branch 'slim/adding-lambda-support' of github.com:Slimsammylim/…
Slimsammylim dddb8b7
Adding functions for pushing and popping lambda context
Slimsammylim 3d63665
Adding a lambdaParamRefBuilder
Slimsammylim b53d6e3
Adding a comment to tell users that only the builders guarentee valid…
Slimsammylim 61676b1
Adding todo comments for issue #189
Slimsammylim 1ef7d48
Removing lambda validation from ExprFromProto
Slimsammylim 5e79979
Moving LambdaParamRef for clarity
Slimsammylim cf7f196
Fixing incorrect comment
Slimsammylim 5428ccb
Update expr/builder.go
Slimsammylim 372262b
Update expr/builder.go
Slimsammylim 1b6409d
Removing mention of private lambda context in ExprBuilder
Slimsammylim 81737e4
Merge branch 'slim/adding-lambda-support' of github.com:Slimsammylim/…
Slimsammylim bd32484
Adding comments for pushLambdaContext and popLambdaContext
Slimsammylim 0ff2e44
Adding a helper for getting params in Build()
Slimsammylim dfab2c9
Adding a comment for parameter nullability requirement
Slimsammylim 4cc2b39
removing unused code
Slimsammylim 9132eeb
Moving JSONs used for tests into seperate test data folder
Slimsammylim a9dd781
Adding a test for a lambda as a parameter with outside references
Slimsammylim 2bc6d62
Using two spaces instead of tabs in JSON files
Slimsammylim fbf73a2
Update expr/lambda.go
Slimsammylim 628ee37
Update expr/builder.go
Slimsammylim 08f3d29
Update expr/lambda.go
Slimsammylim 884fad0
Adding FuncType as the type for lambda bodies
Slimsammylim 0b5805b
Adding FuncType as the type for lambda bodies
Slimsammylim e1a53f0
Adding FuncType as the type for lambda bodies
Slimsammylim cfe657c
Realized we can assume that all lambdaParamRefBuilder refs are Struct…
Slimsammylim 5c08270
Update expr/builder.go
Slimsammylim a2e003c
Only using full plans for lambda tests
Slimsammylim 03c6ab6
Merge branch 'slim/adding-lambda-support' of github.com:Slimsammylim/…
Slimsammylim c35ae76
lambdaParamRefs only use StructFieldRef
Slimsammylim c8ee7d7
Update expr/lambda_test.go
Slimsammylim 41422d1
Update expr/lambda_test.go
Slimsammylim e9c27a8
Update expr/lambda_test.go
Slimsammylim f56ba94
Update expr/lambda_test.go
Slimsammylim 51dd93e
Adding literal package to lambda tests
Slimsammylim cd63be4
Merge branch 'slim/adding-lambda-support' of github.com:Slimsammylim/…
Slimsammylim 9fd7d68
Adding comments to clarify the desired lambda in tests
Slimsammylim 7a58a30
Better error message for getting lambda param types
Slimsammylim 05e9370
Updating lambda tests
Slimsammylim d1e76bf
Update expr/builder.go
Slimsammylim a75b372
Update expr/builder.go
Slimsammylim 3717967
Update expr/builder.go
Slimsammylim 2b898a8
Update expr/builder.go
Slimsammylim 6e04873
Update expr/builder.go
Slimsammylim 17b813c
Moving func type tests to types_test.go
Slimsammylim b3fe321
Merge branch 'slim/adding-lambda-support' of github.com:Slimsammylim/…
Slimsammylim 1becf60
Update go.mod
Slimsammylim 8835174
Updating substrait version
Slimsammylim e299dab
Merge branch 'main' of github.com:substrait-io/substrait-go into slim…
Slimsammylim 01e9339
chore: update substrait-protobuf and grammars
vbarua e5ad38f
chore: regenerate ANTLR parsers
vbarua 8ab57c1
refactor: remove non-existent type visitor methods
vbarua 72381cc
refactor: nullability is no longer attached to Arg Context
vbarua 8f1a7c2
refactor: re-use and improve int and float type handling
vbarua a6eec4b
refactor: nullability is now attached to type
vbarua 02b5dc0
refactor: more robust DataTypeVisitor
vbarua d658430
test: update error messages from new grammar
vbarua eb5ee31
chore: go fmt
vbarua 84c3897
Merge vbarua/v0.79.0-update into slim/adding-lambda-support
Slimsammylim 7c44877
Updating extension parser to support FuncType
Slimsammylim e5ffbdf
Merge branch 'main' of github.com:substrait-io/substrait-go into slim…
Slimsammylim eb6db27
Updated failing test
Slimsammylim 2cf1e0b
new test cases that use transform func
Slimsammylim c2facbf
Adding a comment pointing out inconsistent representation of OuterRef…
Slimsammylim d835915
JSONs use 2 spaces not tabs. Reordering switch case in feield_referen…
Slimsammylim 0ab1910
Update expr/lambda_test.go
benbellick e6069f9
Update expr/lambda_test.go
benbellick c5dd308
Update expr/field_reference.go
benbellick fbcbac6
Update expr/builder.go
benbellick 1129979
Update expr/lambda_test.go
benbellick 4e3b3b2
Update expr/lambda_test.go
benbellick 478a2a8
Apply suggestion from @benbellick
benbellick bd58944
Update expr/lambda_test.go
Slimsammylim 5968f91
Update expr/lambda_test.go
Slimsammylim 8a8677f
Update expr/lambda_test.go
Slimsammylim 6c4dcba
Update expr/lambda_test.go
Slimsammylim 2a36a79
Modifying testcases to include uris and urns
Slimsammylim be9a260
Merge branch 'slim/adding-lambda-support' of github.com:Slimsammylim/…
Slimsammylim 06ad1c7
Apply suggestions from code review
benbellick 59c3cb3
Removing unecessary JSON tests
Slimsammylim ed2b93d
Merge branch 'slim/adding-lambda-support' of github.com:Slimsammylim/…
Slimsammylim e871e2d
New types test
Slimsammylim bfe987b
Using types in type resolution test
Slimsammylim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
benbellick marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package expr | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/substrait-io/substrait-go/v7/types" | ||
| proto "github.com/substrait-io/substrait-protobuf/go/substraitpb" | ||
| ) | ||
|
|
||
| // Lambda represents a lambda expression with parameters and a body. | ||
| type Lambda struct { | ||
| Parameters *types.StructType // The formal lambda parameters, required to have NULLABILITY_REQUIRED | ||
| Body Expression | ||
| } | ||
Slimsammylim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| func (l *Lambda) String() string { | ||
| var b strings.Builder | ||
| b.WriteString("(") | ||
| for i, t := range l.Parameters.Types { | ||
| if i > 0 { | ||
| b.WriteString(", ") | ||
| } | ||
| fmt.Fprintf(&b, "$%d: %s", i, t) | ||
| } | ||
| b.WriteString(") -> ") | ||
| b.WriteString(l.Body.String()) | ||
| return b.String() | ||
| } | ||
|
|
||
| func (l *Lambda) isRootRef() {} | ||
|
|
||
| func (l *Lambda) IsScalar() bool { | ||
| return false | ||
| } | ||
|
|
||
| func (l *Lambda) GetType() types.Type { | ||
| return &types.FuncType{ | ||
| Nullability: types.NullabilityRequired, | ||
| ParameterTypes: l.Parameters.Types, | ||
| ReturnType: l.Body.GetType(), | ||
| } | ||
| } | ||
|
|
||
| func (l *Lambda) Equals(other Expression) bool { | ||
| rhs, ok := other.(*Lambda) | ||
| if !ok { | ||
| return false | ||
| } | ||
| return l.Parameters.Equals(rhs.Parameters) && l.Body.Equals(rhs.Body) | ||
| } | ||
|
|
||
| func (l *Lambda) ToProto() *proto.Expression { | ||
| children := make([]*proto.Type, len(l.Parameters.Types)) | ||
| for i, c := range l.Parameters.Types { | ||
| children[i] = types.TypeToProto(c) | ||
| } | ||
| paramsProto := &proto.Type_Struct{ | ||
| Types: children, | ||
| TypeVariationReference: l.Parameters.TypeVariationRef, | ||
| Nullability: l.Parameters.Nullability, | ||
| } | ||
|
|
||
| return &proto.Expression{ | ||
| RexType: &proto.Expression_Lambda_{ | ||
| Lambda: &proto.Expression_Lambda{ | ||
| Parameters: paramsProto, | ||
| Body: l.Body.ToProto(), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (l *Lambda) ToProtoFuncArg() *proto.FunctionArgument { | ||
| return &proto.FunctionArgument{ | ||
| ArgType: &proto.FunctionArgument_Value{Value: l.ToProto()}, | ||
| } | ||
| } | ||
|
|
||
| func (l *Lambda) Visit(visit VisitFunc) Expression { | ||
| newBody := visit(l.Body) | ||
| if newBody == l.Body { | ||
| return l | ||
| } | ||
| return &Lambda{Parameters: l.Parameters, Body: newBody} | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.