Sha256: e6969603ef29ff40e5463e832b5a7e1e75ac54addc711b135064b8c9052fc235

Contents?: true

Size: 1.83 KB

Versions: 16

Compression:

Stored size: 1.83 KB

Contents

// Copyright (c) 2017-2022 Snowflake Computing Inc. All rights reserved.

package gosnowflake

type queryStatus string

const (
	// QueryStatusInProgress denotes a query execution in progress
	QueryStatusInProgress queryStatus = "queryStatusInProgress"
	// QueryStatusComplete denotes a completed query execution
	QueryStatusComplete queryStatus = "queryStatusComplete"
	// QueryFailed denotes a failed query
	QueryFailed queryStatus = "queryFailed"
)

// SnowflakeResult provides an API for methods exposed to the clients
type SnowflakeResult interface {
	GetQueryID() string
	GetStatus() queryStatus
	GetArrowBatches() ([]*ArrowBatch, error)
}

type snowflakeResult struct {
	affectedRows int64
	insertID     int64 // Snowflake doesn't support last insert id
	queryID      string
	status       queryStatus
	err          error
	errChannel   chan error
}

func (res *snowflakeResult) LastInsertId() (int64, error) {
	if err := res.waitForAsyncExecStatus(); err != nil {
		return -1, err
	}
	return res.insertID, nil
}

func (res *snowflakeResult) RowsAffected() (int64, error) {
	if err := res.waitForAsyncExecStatus(); err != nil {
		return -1, err
	}
	return res.affectedRows, nil
}

func (res *snowflakeResult) GetQueryID() string {
	return res.queryID
}

func (res *snowflakeResult) GetStatus() queryStatus {
	return res.status
}

func (res *snowflakeResult) GetArrowBatches() ([]*ArrowBatch, error) {
	return nil, &SnowflakeError{
		Number:  ErrNotImplemented,
		Message: errMsgNotImplemented,
	}
}

func (res *snowflakeResult) waitForAsyncExecStatus() error {
	// if async exec, block until execution is finished
	if res.status == QueryStatusInProgress {
		err := <-res.errChannel
		res.status = QueryStatusComplete
		if err != nil {
			res.status = QueryFailed
			res.err = err
			return err
		}
	} else if res.status == QueryFailed {
		return res.err
	}
	return nil
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_snowflake_client-1.3.7 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.3.6 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.3.5 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.3.4 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.3.4.pre.debug ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.3.3.pre.debug ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.3.2 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.3.1 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.3.0 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.2.1 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.2.0 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.1.1 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.1.0 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.0.2 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.0.1 ext/vendor/github.com/snowflakedb/gosnowflake/result.go
ruby_snowflake_client-1.0.0 ext/vendor/github.com/snowflakedb/gosnowflake/result.go