Skip to content

Commit

Permalink
feat(go/adbc/pkg): catch panics at interface boundary (#730)
Browse files Browse the repository at this point in the history
Fixes #718.
  • Loading branch information
lidavidm authored Jun 7, 2023
1 parent ed2b280 commit 0d9d9b2
Show file tree
Hide file tree
Showing 12 changed files with 2,142 additions and 91 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/native-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ jobs:
--file ci/conda_env_cpp.txt \
--file ci/conda_env_docs.txt \
--file ci/conda_env_python.txt
- uses: actions/setup-go@v3
with:
go-version: 1.18.6
check-latest: true
cache: true
cache-dependency-path: go/adbc/go.sum

- uses: actions/download-artifact@v3
with:
Expand All @@ -411,9 +417,22 @@ jobs:
shell: bash -l {0}
run: |
env BUILD_ALL=0 BUILD_DRIVER_MANAGER=1 ./ci/scripts/python_build.sh "$(pwd)" "$(pwd)/build" "$HOME/local"
- name: Build Panic Dummy
shell: bash -l {0}
run: |
if [[ $(uname) = "Darwin" ]]; then
make -C ./go/adbc/pkg libadbc_driver_panicdummy.dylib
else
make -C ./go/adbc/pkg libadbc_driver_panicdummy.so
fi
- name: Test Python Driver Manager
shell: bash -l {0}
run: |
if [[ $(uname) = "Darwin" ]]; then
export PANICDUMMY_LIBRARY_PATH=$(pwd)/go/adbc/pkg/libadbc_driver_panicdummy.dylib
else
export PANICDUMMY_LIBRARY_PATH=$(pwd)/go/adbc/pkg/libadbc_driver_panicdummy.so
fi
env BUILD_ALL=0 BUILD_DRIVER_MANAGER=1 ./ci/scripts/python_test.sh "$(pwd)" "$(pwd)/build" "$HOME/local"
- name: Build Python Driver Flight SQL
shell: bash -l {0}
Expand Down
174 changes: 174 additions & 0 deletions go/adbc/driver/panicdummy/panicdummy_adbc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// 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 panicdummy implements a simple ADBC driver that just
// panics, which is intended only for use in automated testing.
package panicdummy

import (
"context"
"fmt"
"os"

"github.com/apache/arrow-adbc/go/adbc"
"github.com/apache/arrow/go/v12/arrow"
"github.com/apache/arrow/go/v12/arrow/array"
"github.com/apache/arrow/go/v12/arrow/memory"
)

func maybePanic(fname string) {
if fname == os.Getenv("PANICDUMMY_FUNC") {
message := os.Getenv("PANICDUMMY_MESSAGE")
if len(message) == 0 {
message = fmt.Sprintf("We panicked in %s!", fname)
}
panic(message)
}
}

type Driver struct {
Alloc memory.Allocator
}

func (d Driver) NewDatabase(opts map[string]string) (adbc.Database, error) {
maybePanic("NewDatabase")
return &database{}, nil
}

type database struct{}

func (d *database) SetOptions(cnOptions map[string]string) error {
maybePanic("DatabaseSetOptions")
return nil
}

func (d *database) Open(ctx context.Context) (adbc.Connection, error) {
maybePanic("DatabaseOpen")
return &cnxn{}, nil
}

type cnxn struct{}

func (c *cnxn) SetOption(key, value string) error {
maybePanic("ConnectionSetOption")
return nil
}

func (c *cnxn) GetInfo(ctx context.Context, infoCodes []adbc.InfoCode) (array.RecordReader, error) {
maybePanic("ConnectionGetInfo")
return nil, adbc.Error{Code: adbc.StatusNotImplemented}
}

func (c *cnxn) GetObjects(ctx context.Context, depth adbc.ObjectDepth, catalog *string, dbSchema *string, tableName *string, columnName *string, tableType []string) (array.RecordReader, error) {
maybePanic("ConnectionGetObjects")
return nil, adbc.Error{Code: adbc.StatusNotImplemented}
}

func (c *cnxn) GetTableSchema(ctx context.Context, catalog *string, dbSchema *string, tableName string) (*arrow.Schema, error) {
maybePanic("ConnectionGetTableSchema")
return nil, adbc.Error{Code: adbc.StatusNotImplemented}
}

func (c *cnxn) GetTableTypes(ctx context.Context) (array.RecordReader, error) {
maybePanic("ConnectionGetTableTypes")
return nil, adbc.Error{Code: adbc.StatusNotImplemented}
}

func (c *cnxn) Commit(ctx context.Context) error {
maybePanic("ConnectionCommit")
return adbc.Error{Code: adbc.StatusNotImplemented}
}

func (c *cnxn) Rollback(ctx context.Context) error {
maybePanic("ConnectionRollback")
return adbc.Error{Code: adbc.StatusNotImplemented}
}

func (c *cnxn) NewStatement() (adbc.Statement, error) {
maybePanic("ConnectionNewStatement")
return &statement{}, nil
}

// Close closes this connection and releases any associated resources.
func (c *cnxn) Close() error {
maybePanic("ConnectionClose")
return nil
}

func (c *cnxn) ReadPartition(ctx context.Context, serializedPartition []byte) (rdr array.RecordReader, err error) {
maybePanic("ConnectionReadPartition")
return nil, adbc.Error{Code: adbc.StatusNotImplemented}
}

type statement struct{}

func (s *statement) Close() error {
maybePanic("StatementClose")
return nil
}

func (s *statement) SetOption(key string, val string) error {
maybePanic("StatementSetOption")
return nil
}

func (s *statement) SetSqlQuery(query string) error {
maybePanic("StatementSetSqlQuery")
return nil
}

func (s *statement) ExecuteQuery(ctx context.Context) (rdr array.RecordReader, nrec int64, err error) {
maybePanic("StatementExecuteQuery")
return nil, -1, adbc.Error{Code: adbc.StatusNotImplemented}
}

func (s *statement) ExecuteUpdate(ctx context.Context) (n int64, err error) {
maybePanic("StatementExecuteUpdate")
return -1, adbc.Error{Code: adbc.StatusNotImplemented}
}

func (s *statement) Prepare(ctx context.Context) error {
maybePanic("StatementPrepare")
return nil
}

func (s *statement) SetSubstraitPlan(plan []byte) error {
maybePanic("StatementSetSubstraitPlan")
return nil
}

func (s *statement) Bind(_ context.Context, values arrow.Record) error {
maybePanic("StatementBind")
values.Release()
return nil
}

func (s *statement) BindStream(_ context.Context, stream array.RecordReader) error {
maybePanic("StatementBindStream")
stream.Release()
return nil
}

func (s *statement) GetParameterSchema() (*arrow.Schema, error) {
maybePanic("StatementGetParameterSchema")
return nil, adbc.Error{Code: adbc.StatusNotImplemented}
}

func (s *statement) ExecutePartitions(ctx context.Context) (*arrow.Schema, adbc.Partitions, int64, error) {
maybePanic("StatementExecutePartitions")
return nil, adbc.Partitions{}, -1, adbc.Error{Code: adbc.StatusNotImplemented}
}
8 changes: 7 additions & 1 deletion go/adbc/pkg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ endif

DRIVERS := \
libadbc_driver_flightsql.$(SUFFIX) \
libadbc_driver_panicdummy.$(SUFFIX) \
libadbc_driver_snowflake.$(SUFFIX)

.PHONY: all
.PHONY: all regenerate
all: $(DRIVERS)

libadbc_driver_%.$(SUFFIX): %
$(GO_BUILD) -tags driverlib -o $@ -buildmode=c-shared -ldflags "-s -w" ./$<
rm $(basename $@).h

regenerate:
go run gen/main.go -prefix FlightSQL -o ./flightsql/ -driver ../driver/flightsql
go run gen/main.go -prefix PanicDummy -o ./panicdummy/ -driver ../driver/panicdummy
go run gen/main.go -prefix Snowflake -o ./snowflake/ -driver ../driver/snowflake

clean:
rm $(DRIVERS)
Loading

0 comments on commit 0d9d9b2

Please sign in to comment.