Skip to content
Closed
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
26 changes: 17 additions & 9 deletions go/bulk_ingestion.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ type ingestOptions struct {
//
// Default is true.
vectorizedScanner bool
// Snowflake type to use for geoarrow columns (geoarrow.wkb, geoarrow.wkt).
//
// Valid values are "geography" (default) and "geometry".
// GEOGRAPHY is always WGS84 (SRID 4326). GEOMETRY supports any SRID;
// the SRID is extracted from geoarrow extension metadata and applied
// via ST_SETSRID after COPY INTO.
geoType string
}

func DefaultIngestOptions() ingestOptions {
Expand All @@ -133,6 +140,7 @@ func DefaultIngestOptions() ingestOptions {
compressionCodec: defaultCompressionCodec,
compressionLevel: defaultCompressionLevel,
vectorizedScanner: defaultVectorizedScanner,
geoType: "geography",
}
}

Expand All @@ -141,7 +149,7 @@ func DefaultIngestOptions() ingestOptions {
//
// The Record must already be bound by calling stmt.Bind(), and will be released
// and reset upon completion.
func (st *statement) ingestRecord(ctx context.Context) (nrows int64, err error) {
func (st *statement) ingestRecord(ctx context.Context, copyQ string) (nrows int64, err error) {
defer func() {
// Record already released by writeParquet()
st.bound = nil
Expand Down Expand Up @@ -209,7 +217,7 @@ func (st *statement) ingestRecord(ctx context.Context) (nrows int64, err error)
}

// Load the uploaded file into the target table
_, err = st.cnxn.cn.ExecContext(ctx, copyQuery, []driver.NamedValue{{Value: target}})
_, err = st.cnxn.cn.ExecContext(ctx, copyQ, []driver.NamedValue{{Value: target}})
if err != nil {
return
}
Expand All @@ -225,7 +233,7 @@ func (st *statement) ingestRecord(ctx context.Context) (nrows int64, err error)
//
// The RecordReader must already be bound by calling stmt.BindStream(), and will
// be released and reset upon completion.
func (st *statement) ingestStream(ctx context.Context) (nrows int64, err error) {
func (st *statement) ingestStream(ctx context.Context, copyQ string) (nrows int64, err error) {
defer func() {
st.streamBind.Release()
st.streamBind = nil
Expand Down Expand Up @@ -298,7 +306,7 @@ func (st *statement) ingestStream(ctx context.Context) (nrows int64, err error)
}

// Kickoff background tasks to COPY Parquet files into Snowflake table as they are uploaded
fileReady, finishCopy, cancelCopy := runCopyTasks(ctx, st.cnxn.cn, target, int(st.ingestOptions.copyConcurrency))
fileReady, finishCopy, cancelCopy := runCopyTasks(ctx, st.cnxn.cn, copyQ, target, int(st.ingestOptions.copyConcurrency))

// Read Parquet files from buffer pool and upload to Snowflake stage in parallel
g.Go(func() error {
Expand Down Expand Up @@ -532,8 +540,8 @@ func uploadAllStreams(
return g.Wait()
}

func executeCopyQuery(ctx context.Context, cn snowflakeConn, tableName string, filesToCopy *fileSet) (err error) {
rows, err := cn.QueryContext(ctx, copyQuery, []driver.NamedValue{{Value: tableName}})
func executeCopyQuery(ctx context.Context, cn snowflakeConn, copyQ string, tableName string, filesToCopy *fileSet) (err error) {
rows, err := cn.QueryContext(ctx, copyQ, []driver.NamedValue{{Value: tableName}})
if err != nil {
return err
}
Expand Down Expand Up @@ -566,7 +574,7 @@ func executeCopyQuery(ctx context.Context, cn snowflakeConn, tableName string, f
return nil
}

func runCopyTasks(ctx context.Context, cn snowflakeConn, tableName string, concurrency int) (func(string), func() error, func()) {
func runCopyTasks(ctx context.Context, cn snowflakeConn, copyQ string, tableName string, concurrency int) (func(string), func() error, func()) {
var filesToCopy fileSet

ctx, cancel := context.WithCancel(ctx)
Expand Down Expand Up @@ -631,7 +639,7 @@ func runCopyTasks(ctx context.Context, cn snowflakeConn, tableName string, concu
time.Sleep(backoff)
}

if err := executeCopyQuery(ctx, cn, tableName, &filesToCopy); err != nil {
if err := executeCopyQuery(ctx, cn, copyQ, tableName, &filesToCopy); err != nil {
return err
}

Expand Down Expand Up @@ -670,7 +678,7 @@ func runCopyTasks(ctx context.Context, cn snowflakeConn, tableName string, concu
}

g.Go(func() error {
return executeCopyQuery(ctx, cn, tableName, &filesToCopy)
return executeCopyQuery(ctx, cn, copyQ, tableName, &filesToCopy)
})
}
}()
Expand Down
Loading
Loading