Repository: snowflakedb/gosnowflake
Pull request #1208 (2024-09-11 16:19:02)

SNOW-1660331 export SnowflakeFileTransferOptions.GetFileToStream
### Description

SNOW-1660331 // https://github.com/snowflakedb/gosnowflake/issues/1207

 attempt to fix
```
unknown field getFileToStream in struct literal of type gosnowflake.SnowflakeFileTransferOptions
```

which happens when trying to download a file into an in-memory stream (rather than a file) per docs:
```go
ctx := WithFileTransferOptions(context.Background(), &SnowflakeFileTransferOptions{getFileToStream: true})
ctx = WithFileGetStream(ctx, &streamBuf)
```

`getFileToStream` being unexported, it is not really accessible from outside of the module. 

### Checklist
- [ ] Created tests which fail without the change (if possible)
- [x] Extended the README / documentation, if necessary


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1208?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 82.46%. Comparing base [(`099708d`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/099708d318689634a558f705ccc19b3b7b278972?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) to head [(`4c28228`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/4c28228c08aa971956f3b955d5b1e858ff775223?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1208      +/-   ##
==========================================
- Coverage   82.52%   82.46%   -0.07%     
==========================================
  Files          54       54              
  Lines       12916    12916              
==========================================
- Hits        10659    10651       -8     
- Misses       2257     2265       +8     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1208?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).


Patch:
diff --git a/azure_storage_client.go b/azure_storage_client.go
index 307c7b2..b0626eb 100644
--- a/azure_storage_client.go
+++ b/azure_storage_client.go
@@ -277,7 +277,7 @@ func (util *snowflakeAzureClient) nativeDownloadFile(
 	if meta.mockAzureClient != nil {
 		blobClient = meta.mockAzureClient
 	}
-	if meta.options.getFileToStream {
+	if meta.options.GetFileToStream {
 		blobDownloadResponse, err := blobClient.DownloadStream(context.Background(), &azblob.DownloadStreamOptions{})
 		if err != nil {
 			return err
diff --git a/connection_util.go b/connection_util.go
index 78ea9d1..52e4817 100644
--- a/connection_util.go
+++ b/connection_util.go
@@ -115,7 +115,7 @@ func (sc *snowflakeConn) processFileTransfer(
 	if err != nil {
 		return nil, err
 	}
-	if sfa.options.getFileToStream {
+	if sfa.options.GetFileToStream {
 		if err := writeFileStream(ctx, sfa.streamBuffer); err != nil {
 			return nil, err
 		}
diff --git a/doc.go b/doc.go
index ec18651..f1214f2 100644
--- a/doc.go
+++ b/doc.go
@@ -1257,7 +1257,7 @@ an absolute path rather than a relative path. For example:
 To download a file into an in-memory stream (rather than a file) use code similar to the code below.
 
 	var streamBuf bytes.Buffer
-	ctx := WithFileTransferOptions(context.Background(), &SnowflakeFileTransferOptions{getFileToStream: true})
+	ctx := WithFileTransferOptions(context.Background(), &SnowflakeFileTransferOptions{GetFileToStream: true})
 	ctx = WithFileGetStream(ctx, &streamBuf)
 
 	sql := "get @~/data1.txt.gz file:///tmp/testData"
diff --git a/file_transfer_agent.go b/file_transfer_agent.go
index c22d748..fe341cd 100644
--- a/file_transfer_agent.go
+++ b/file_transfer_agent.go
@@ -92,7 +92,7 @@ type SnowflakeFileTransferOptions struct {
 	compressSourceFromStream bool
 
 	/* streaming GET */
-	getFileToStream bool
+	GetFileToStream bool
 
 	/* PUT */
 	putCallback             *snowflakeProgressPercentage
diff --git a/gcs_storage_client.go b/gcs_storage_client.go
index b59708c..c39376d 100644
--- a/gcs_storage_client.go
+++ b/gcs_storage_client.go
@@ -322,7 +322,7 @@ func (util *snowflakeGcsClient) nativeDownloadFile(
 		return meta.lastError
 	}
 
-	if meta.options.getFileToStream {
+	if meta.options.GetFileToStream {
 		if _, err := io.Copy(meta.dstStream, resp.Body); err != nil {
 			return err
 		}
diff --git a/s3_storage_client.go b/s3_storage_client.go
index 342d0c9..7cd1e33 100644
--- a/s3_storage_client.go
+++ b/s3_storage_client.go
@@ -248,7 +248,7 @@ func (util *snowflakeS3Client) nativeDownloadFile(
 		downloader = meta.mockDownloader
 	}
 
-	if meta.options.getFileToStream {
+	if meta.options.GetFileToStream {
 		buf := manager.NewWriteAtBuffer([]byte{})
 		_, err = downloader.Download(context.Background(), buf, &s3.GetObjectInput{
 			Bucket: s3Obj.Bucket,
diff --git a/storage_client.go b/storage_client.go
index 550be0d..2079fa8 100644
--- a/storage_client.go
+++ b/storage_client.go
@@ -218,7 +218,7 @@ func (rsu *remoteStorageUtil) downloadOneFile(meta *fileMetadata) error {
 						return err
 					}
 				}
-				if meta.options.getFileToStream {
+				if meta.options.GetFileToStream {
 					totalFileSize, err := decryptStream(header.encryptionMetadata,
 						meta.encryptionMaterial, 0, meta.dstStream, meta.sfa.streamBuffer)
 					if err != nil {
@@ -238,7 +238,7 @@ func (rsu *remoteStorageUtil) downloadOneFile(meta *fileMetadata) error {
 				}
 
 			}
-			if !meta.options.getFileToStream {
+			if !meta.options.GetFileToStream {
 				if fi, err := os.Stat(fullDstFileName); err == nil {
 					meta.dstFileSize = fi.Size()
 				}


Test patch:
diff --git a/put_get_test.go b/put_get_test.go
index 8a4322a..f0722ee 100644
--- a/put_get_test.go
+++ b/put_get_test.go
@@ -272,7 +272,7 @@ func TestPutGetWithAutoCompressFalse(t *testing.T) {
 
 		// GET test
 		var streamBuf bytes.Buffer
-		ctx := WithFileTransferOptions(context.Background(), &SnowflakeFileTransferOptions{getFileToStream: true})
+		ctx := WithFileTransferOptions(context.Background(), &SnowflakeFileTransferOptions{GetFileToStream: true})
 		ctx = WithFileGetStream(ctx, &streamBuf)
 		sql := fmt.Sprintf("get @~/test_put_uncompress_file/data.txt 'file://%v'", tmpDir)
 		sqlText = strings.ReplaceAll(sql, "\\", "\\\\")
@@ -468,7 +468,7 @@ func testPutGet(t *testing.T, isStream bool) {
 
 		var streamBuf bytes.Buffer
 		if isStream {
-			ctx = WithFileTransferOptions(ctx, &SnowflakeFileTransferOptions{getFileToStream: true})
+			ctx = WithFileTransferOptions(ctx, &SnowflakeFileTransferOptions{GetFileToStream: true})
 			ctx = WithFileGetStream(ctx, &streamBuf)
 		}
 		sql = fmt.Sprintf("get @%%%v 'file://%v'", tableName, tmpDir)
@@ -686,7 +686,7 @@ func TestPutGetLargeFile(t *testing.T) {
 
 		// GET test with stream
 		var streamBuf bytes.Buffer
-		ctx := WithFileTransferOptions(context.Background(), &SnowflakeFileTransferOptions{getFileToStream: true})
+		ctx := WithFileTransferOptions(context.Background(), &SnowflakeFileTransferOptions{GetFileToStream: true})
 		ctx = WithFileGetStream(ctx, &streamBuf)
 		sql := fmt.Sprintf("get @%v 'file://%v'", "~/test_put_largefile/largefile.txt.gz", t.TempDir())
 		sqlText = strings.ReplaceAll(sql, "\\", "\\\\")