Skip to content
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

feat: Add a way to get an expr.ExprBuilder from a plan.Builder #81

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plan/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ type Builder interface {
// that may be in use with this plan for advanced extensions, optimizations,
// and so on.
PlanWithTypes(root Rel, rootNames []string, expectedTypeURLs []string, others ...Rel) (*Plan, error)

// GetExprBuilder returns an expr.ExprBuilder that shares the extension
// registry that this Builder uses.
GetExprBuilder() *expr.ExprBuilder
}

const FETCH_COUNT_ALL_RECORDS = -1
Expand Down Expand Up @@ -152,6 +156,13 @@ type builder struct {
reg expr.ExtensionRegistry
}

func (b *builder) GetExprBuilder() *expr.ExprBuilder {
return &expr.ExprBuilder{
Reg: b.reg,
BaseSchema: nil,
}
}

func (b *builder) GetFunctionRef(nameSpace, key string) types.FunctionRef {
return types.FunctionRef(b.extSet.GetFuncAnchor(extensions.ID{URI: nameSpace, Name: key}))
}
Expand Down
8 changes: 7 additions & 1 deletion plan/plan_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,9 @@ func TestProjectExpressions(t *testing.T) {
}
}
],
"options": [
{}
],
"outputType": {
"fp32": {
"nullability": "NULLABILITY_REQUIRED"
Expand Down Expand Up @@ -1144,7 +1147,10 @@ func TestProjectExpressions(t *testing.T) {
abs, err := b.ScalarFn(arithmeticURI, "abs", nil, ref)
require.NoError(t, err)

add, err := b.ScalarFn(arithmeticURI, "add", nil, abs, ref)
add, err := b.GetExprBuilder().ScalarFunc(
extensions.ID{URI: arithmeticURI, Name: "add"}, nil).Args(
b.GetExprBuilder().Expression(abs),
b.GetExprBuilder().Expression(ref)).Build()
require.NoError(t, err)

project, err := b.Project(scan, add)
Expand Down
Loading