-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
ARROW-17475: [Go] Function interface and Registry impl #13924
Changes from 2 commits
6454917
ad58638
70e66b9
3cfacfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package compute is a native-go implementation of an Acero-like | ||
// arrow compute engine. | ||
// | ||
// While consumers of Arrow that are able to use CGO could utilize the | ||
// C Data API (using the cdata package) and could link against the | ||
// acero library directly, there are consumers who cannot use CGO. This | ||
// is an attempt to provide for those users, and in general create a | ||
// native-go arrow compute engine. | ||
// | ||
// Everything in this package should be considered Experimental for now. | ||
package compute | ||
|
||
//go:generate stringer -type=FuncKind -linecomment |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package compute | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type Function interface { | ||
Name() string | ||
Kind() FuncKind | ||
Arity() Arity | ||
Doc() FunctionDoc | ||
NumKernels() int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth exposing this without also having a public concept of Kernels? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a setup concept for Kernels, just haven't placed the interface in here yet (for the sake of keeping the size of this PR down) but they will almost certainly make into the 10.0.0 release so I'm okay with leaving this. |
||
Execute(context.Context, FunctionOptions, ...Datum) (Datum, error) | ||
DefaultOptions() FunctionOptions | ||
Validate() error | ||
} | ||
|
||
type Arity struct { | ||
NArgs int | ||
IsVarArgs bool | ||
} | ||
|
||
func Nullary() Arity { return Arity{0, false} } | ||
func Unary() Arity { return Arity{1, false} } | ||
func Binary() Arity { return Arity{2, false} } | ||
func Ternary() Arity { return Arity{3, false} } | ||
func VarArgs(minArgs int) Arity { return Arity{minArgs, true} } | ||
|
||
type FunctionDoc struct { | ||
Summary string | ||
Description string | ||
ArgNames []string | ||
OptionsClass string | ||
OptionsRequired bool | ||
} | ||
|
||
var EmptyFuncDoc FunctionDoc | ||
|
||
type FuncKind int8 | ||
|
||
const ( | ||
FuncScalar FuncKind = iota // Scalar | ||
FuncVector // Vector | ||
FuncScalarAgg // ScalarAggregate | ||
FuncHashAgg // HashAggregate | ||
FuncMeta // Meta | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package compute_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/apache/arrow/go/v10/arrow/compute" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestArityBasics(t *testing.T) { | ||
nullary := compute.Nullary() | ||
assert.Equal(t, 0, nullary.NArgs) | ||
assert.False(t, nullary.IsVarArgs) | ||
|
||
unary := compute.Unary() | ||
assert.Equal(t, 1, unary.NArgs) | ||
assert.False(t, unary.IsVarArgs) | ||
|
||
binary := compute.Binary() | ||
assert.Equal(t, 2, binary.NArgs) | ||
assert.False(t, binary.IsVarArgs) | ||
|
||
ternary := compute.Ternary() | ||
assert.Equal(t, 3, ternary.NArgs) | ||
assert.False(t, ternary.IsVarArgs) | ||
|
||
varargs := compute.VarArgs(2) | ||
assert.Equal(t, 2, varargs.NArgs) | ||
assert.True(t, varargs.IsVarArgs) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so not just arrow::compute, but Acero itself is the goal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the goal yup. But it's a lofty goal. The first milestone is just simple scalar function execution...