Skip to content

Commit

Permalink
feat: Add a way to get an expr.ExprBuilder from a plan.Builder (#81)
Browse files Browse the repository at this point in the history
By creating an`expr.ExprBuilder` directly from the `plan.Builder` the
two can share the same extension registry.
  • Loading branch information
EpsilonPrime authored Dec 4, 2024
1 parent 82d4922 commit fd3415c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit fd3415c

Please sign in to comment.