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

[Go][Format] initial attempt at wrapping adbc for database/sql #97

Merged
merged 6 commits into from
Aug 31, 2022
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
64 changes: 64 additions & 0 deletions adbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,70 @@ AdbcStatusCode AdbcConnectionReadPartition(struct AdbcConnection* connection,
/// enabled.
#define ADBC_CONNECTION_OPTION_AUTOCOMMIT "adbc.connection.autocommit"

/// \brief The name of the canonical option for whether the current
/// connection should be restricted to being read-only.
#define ADBC_CONNECTION_OPTION_READ_ONLY "adbc.connection.readonly"

/// \brief The name of the canonical option for setting the isolation
/// level of a transaction.
///
/// Should only be used in conjunction with autocommit and
/// AdbcConnectionCommit / AdbcConnectionRollback. If the desired
/// isolation level is not supported by a driver, it should return
/// appropriate error.
#define ADBC_CONNECTION_OPTION_ISOLATION_LEVEL \
"adbc.connection.transaction.isolation_level"

/// \brief Use database or driver default Isolation level
#define ADBC_OPTION_ISOLATION_LEVEL_DEFAULT \
"adbc.connection.transaction.isolation.default"
/// \brief The lowest isolation level. Dirty reads are allowed, so one
/// transaction may see not-yet-committed changes made by others.
#define ADBC_OPTION_ISOLATION_LEVEL_READ_UNCOMMITTED \
"adbc.connection.transaction.isolation.read_uncommitted"
/// \brief Lock-based concurrency control keeps write locks until the
/// end of the transaction, but read locks are released as soon as a
/// SELECT is performed. Non-repeatable reads can occur in this
/// isolation level.
///
/// More simply put, Read Committed is an isolation level that guarantees
/// that any data read is committed at the moment it is read. It simply
/// restricts the reader from seeing any intermediate, uncommitted,
/// 'dirty' reads. It makes no promise whatsoever that if the transaction
/// re-issues the read, it will find the same data; data is free to change
/// after it is read.
#define ADBC_OPTION_ISOLATION_LEVEL_READ_COMMITTED \
"adbc.connection.transaction.isolation.read_committed"
/// \brief Lock-based concurrency control keeps read AND write locks
/// (acquired on selection data) until the end of the transaction.
///
/// However, range-locks are not managed, so phantom reads can occur.
/// Write skew is possible at this isolation level in some systems.
#define ADBC_OPTION_ISOLATION_LEVEL_REPEATABLE_READ \
"adbc.connection.transaction.isolation.repeatable_read"
/// \brief This isolation guarantees that all reads in the transaction
/// will see a consistent snapshot of the database and the transaction
/// should only successfully commit if no updates conflict with any
/// concurrent updates made since that snapshot.
#define ADBC_OPTION_ISOLATION_LEVEL_SNAPSHOT \
"adbc.connection.transaction.isolation.snapshot"
/// \brief Serializability requires read and write locks to be released
/// only at the end of the transaction. This includes acquiring range-
/// locks when a select query uses a ranged WHERE clause to avoid
/// phantom reads.
#define ADBC_OPTION_ISOLATION_LEVEL_SERIALIZABLE \
"adbc.connection.transaction.isolation.serializable"
/// \brief The central distinction between serializability and linearizability
/// is that serializability is a global property; a property of an entire
/// history of operations and transactions. Linearizability is a local
/// property; a property of a single operation/transaction.
///
/// Linearizability can be viewed as a special case of strict serializability
/// where transactions are restricted to consist of a single operation applied
/// to a single object.
#define ADBC_OPTION_ISOLATION_LEVEL_LINEARIZABLE \
"adbc.connection.transaction.isolation.linearizable"

/// \brief Commit any pending transactions. Only used if autocommit is
/// disabled.
///
Expand Down
32 changes: 28 additions & 4 deletions go/adbc/adbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import (
"context"
"fmt"

"github.com/apache/arrow/go/v9/arrow"
"github.com/apache/arrow/go/v9/arrow/array"
"github.com/apache/arrow/go/v10/arrow"
"github.com/apache/arrow/go/v10/arrow/array"
)

//go:generate go run golang.org/x/tools/cmd/stringer -type Status -linecomment
Expand Down Expand Up @@ -148,19 +148,43 @@ const (
OptionKeyAutoCommit = "adbc.connection.autocommit"
OptionKeyIngestTargetTable = "adbc.ingest.target_table"
OptionKeyIngestMode = "adbc.ingest.mode"
OptionKeyIsolationLevel = "adbc.connection.transaction.isolation_level"
OptionKeyReadOnly = "adbc.connection.readonly"
OptionValueIngestModeCreate = "adbc.ingest.mode.create"
OptionValueIngestModeAppend = "adbc.ingest.mode.append"
)

type OptionIsolationLevel string

const (
LevelDefault OptionIsolationLevel = "adbc.connection.transaction.isolation.default"
LevelReadUncommitted OptionIsolationLevel = "adbc.connection.transaction.isolation.read_uncommitted"
LevelReadCommitted OptionIsolationLevel = "adbc.connection.transaction.isolation.read_committed"
LevelRepeatableRead OptionIsolationLevel = "adbc.connection.transaction.isolation.repeatable_read"
LevelSnapshot OptionIsolationLevel = "adbc.connection.transaction.isolation.snapshot"
LevelSerializable OptionIsolationLevel = "adbc.connection.transaction.isolation.serializable"
LevelLinearizable OptionIsolationLevel = "adbc.connection.transaction.isolation.linearizable"
)

// Driver is the entry point for the interface. It is similar to
// database/sql.Driver taking a map of keys and values as options
// to initialize a Connection to the database. Any common connection
// state can live in the Driver itself, for example an in-memory database
// can place ownership of the actual database in this driver.
//
// Any connection specific options should be passed to the Open method.
// Any connection specific options should be set using SetOptions before
// calling Open.
//
// The provided context.Context is for dialing purposes only
// (see net.DialContext) and should not be stored or used for other purposes.
// A default timeout should still be used when dialing as a connection
// pool may call Connect asynchronously to any query.
//
// A driver can also optionally implement io.Closer if there is a need
// or desire for it.
type Driver interface {
Open(options map[string]string) (Connection, error)
SetOptions(map[string]string) error
Open(ctx context.Context) (Connection, error)
}

type InfoCode uint32
Expand Down
17 changes: 9 additions & 8 deletions go/adbc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ module github.com/apache/arrow-adbc/go/adbc
go 1.18

require (
github.com/apache/arrow/go/v9 v9.0.0
github.com/apache/arrow/go/v10 v10.0.0-20220830153009-74dae618ed8d
golang.org/x/tools v0.1.12
)

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/apache/thrift v0.15.0 // indirect
github.com/goccy/go-json v0.9.6 // indirect
github.com/apache/thrift v0.16.0 // indirect
github.com/goccy/go-json v0.9.10 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/asmfmt v1.3.1 // indirect
github.com/klauspost/compress v1.14.2 // indirect
github.com/google/flatbuffers v2.0.6+incompatible // indirect
github.com/klauspost/asmfmt v1.3.2 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/zeebo/xxh3 v1.0.1 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
)
Loading