-
Notifications
You must be signed in to change notification settings - Fork 100
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(go/adbc/drivermgr): Implement SetSubstraitPlan in CGO wrapper and add DuckDB wrapper tests #1709
Draft
joellubi
wants to merge
10
commits into
apache:main
Choose a base branch
from
joellubi:impl-wrapper-substrait
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat(go/adbc/drivermgr): Implement SetSubstraitPlan in CGO wrapper and add DuckDB wrapper tests #1709
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c1d129d
add substrait to cgo wrapper and add duckdb test
joellubi 0305fb8
mamba install libduckdb
joellubi 7b126f2
remove driver extension
joellubi 6a2a14f
remove lib prefix from libduckdb
joellubi 0ad4eba
consolidate duckdb insert stmts
joellubi 3a023c6
add conda_prefix to search path
joellubi 6773d5e
empty commit
joellubi 50d46ed
don't add libs in go_build
joellubi 83a0ab9
empty commit
joellubi 026f504
bump arrow version
joellubi 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 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 |
---|---|---|
|
@@ -20,5 +20,6 @@ compilers | |
gtest>=1.10.0 | ||
libpq | ||
libsqlite | ||
libduckdb | ||
ninja | ||
pkg-config |
This file contains 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 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 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,153 @@ | ||
// 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. | ||
|
||
//go:build cgo | ||
|
||
package drivermgr_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/apache/arrow-adbc/go/adbc" | ||
"github.com/apache/arrow-adbc/go/adbc/drivermgr" | ||
"github.com/apache/arrow/go/v17/arrow" | ||
"github.com/apache/arrow/go/v17/arrow/array" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/substrait-io/substrait-go/extensions" | ||
"github.com/substrait-io/substrait-go/plan" | ||
"github.com/substrait-io/substrait-go/types" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
type DriverMgrDuckDBSuite struct { | ||
suite.Suite | ||
|
||
ctx context.Context | ||
drv adbc.Driver | ||
db adbc.Database | ||
conn adbc.Connection | ||
} | ||
|
||
func (dm *DriverMgrDuckDBSuite) SetupSuite() { | ||
dm.ctx = context.TODO() | ||
dm.drv = drivermgr.Driver{} | ||
var err error | ||
dm.db, err = dm.drv.NewDatabase(map[string]string{ | ||
"driver": "duckdb", | ||
"entrypoint": "duckdb_adbc_init", | ||
}) | ||
dm.NoError(err) | ||
|
||
cnxn, err := dm.db.Open(dm.ctx) | ||
dm.NoError(err) | ||
defer cnxn.Close() | ||
|
||
stmt, err := cnxn.NewStatement() | ||
dm.NoError(err) | ||
defer stmt.Close() | ||
|
||
// Setup substrait extension | ||
dm.NoError(stmt.SetSqlQuery("INSTALL substrait")) | ||
_, err = stmt.ExecuteUpdate(dm.ctx) | ||
dm.NoError(err) | ||
|
||
dm.NoError(stmt.SetSqlQuery("LOAD substrait")) | ||
_, err = stmt.ExecuteUpdate(dm.ctx) | ||
dm.NoError(err) | ||
|
||
dm.NoError(stmt.SetSqlQuery("CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT)")) | ||
// Don't check nrows, duckdb currently does not support it | ||
_, err = stmt.ExecuteUpdate(dm.ctx) | ||
dm.NoError(err) | ||
|
||
dm.NoError(stmt.SetSqlQuery("INSERT INTO test_table (id, name) VALUES (1, 'test'), (2, 'test'), (3, 'test')")) | ||
// Don't check nrows, duckdb currently does not support it | ||
_, err = stmt.ExecuteUpdate(dm.ctx) | ||
dm.NoError(err) | ||
} | ||
|
||
func (dm *DriverMgrDuckDBSuite) TearDownSuite() { | ||
dm.NoError(dm.db.Close()) | ||
} | ||
|
||
func (dm *DriverMgrDuckDBSuite) SetupTest() { | ||
cnxn, err := dm.db.Open(dm.ctx) | ||
dm.Require().NoError(err) | ||
dm.conn = cnxn | ||
} | ||
|
||
func (dm *DriverMgrDuckDBSuite) TearDownTest() { | ||
dm.NoError(dm.conn.Close()) | ||
} | ||
|
||
func (dm *DriverMgrDuckDBSuite) TestSubstraitExecute() { | ||
// Building Substrait plan equivalent to 'SELECT COUNT(*) AS count FROM test_table;' | ||
bldr := plan.NewBuilderDefault() | ||
scan := bldr.NamedScan( | ||
[]string{"test_table"}, | ||
types.NamedStruct{ | ||
Names: []string{"id", "names"}, | ||
Struct: types.StructType{ | ||
Nullability: types.NullabilityRequired, | ||
Types: []types.Type{ | ||
&types.Int32Type{Nullability: types.NullabilityRequired}, | ||
&types.StringType{Nullability: types.NullabilityNullable}, | ||
}, | ||
}, | ||
}, | ||
) | ||
|
||
countFn, err := bldr.AggregateFn(extensions.SubstraitDefaultURIPrefix+"functions_aggregate_generic.yaml", "count", nil) | ||
dm.Require().NoError(err) | ||
|
||
root, err := bldr.AggregateColumns(scan, []plan.AggRelMeasure{bldr.Measure(countFn, nil)}) | ||
dm.Require().NoError(err) | ||
|
||
plan, err := bldr.Plan(root, []string{"count"}) | ||
dm.Require().NoError(err) | ||
|
||
planProto, err := plan.ToProto() | ||
dm.Require().NoError(err) | ||
|
||
serialized, err := proto.Marshal(planProto) | ||
dm.Require().NoError(err) | ||
|
||
st, err := dm.conn.NewStatement() | ||
dm.Require().NoError(err) | ||
defer st.Close() | ||
|
||
dm.Require().NoError(st.SetSubstraitPlan(serialized)) | ||
rdr, _, err := st.ExecuteQuery(context.TODO()) | ||
dm.Require().NoError(err) | ||
defer rdr.Release() | ||
|
||
expectedSchema := arrow.NewSchema([]arrow.Field{{Name: "count", Type: arrow.PrimitiveTypes.Int64, Nullable: true}}, nil) | ||
dm.Require().True(rdr.Next()) | ||
rec := rdr.Record() | ||
dm.Require().Equal(expectedSchema, rec.Schema()) | ||
dm.Require().Equal(int64(1), rec.NumCols()) | ||
dm.Require().Equal(int64(1), rec.NumRows()) | ||
dm.Require().Equal(int64(3), rec.Column(0).(*array.Int64).Value(0)) | ||
|
||
// Only expected one record | ||
dm.Require().False(rdr.Next()) | ||
} | ||
|
||
func TestDriverMgrDuckDB(t *testing.T) { | ||
suite.Run(t, new(DriverMgrDuckDBSuite)) | ||
} |
This file contains 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 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
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.
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.
sigh i should really improve this in the substrait library lol