Skip to content

Commit ff4b113

Browse files
SNOW-1258702:SnowSQL File Upload support for China (#1912)
1 parent 4426e1f commit ff4b113

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

DESCRIPTION.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
88

99
# Release Notes
1010

11+
- v3.9.1(TBD)
12+
13+
- Improved s3 acceleration logic when connecting to China endpoint.
14+
1115
- v3.8.1(April 09, 2024)
1216

1317
- Reverted the change "Updated `write_pandas` to skip TABLE IF NOT EXISTS in truncate mode." introduced in v3.8.0 (yanked) as it's a breaking change. `write_pandas` will be fixed in the future in a non-breaking way.

src/snowflake/connector/s3_storage_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def __init__(
8080
)
8181
)
8282
self.use_s3_regional_url = use_s3_regional_url
83+
self.location_type = stage_info.get("locationType")
8384

8485
# if GS sends us an endpoint, it's likely for FIPS. Use it.
8586
self.endpoint: str | None = None
@@ -92,6 +93,9 @@ def __init__(
9293
def transfer_accelerate_config(
9394
self, use_accelerate_endpoint: bool | None = None
9495
) -> bool:
96+
# accelerate cannot be used in China and us government
97+
if self.location_type and "S3China" in self.location_type:
98+
return False
9599
# if self.endpoint has been set, e.g. by metadata, no more config is needed.
96100
if self.endpoint is not None:
97101
return self.endpoint.find("s3-accelerate.amazonaws.com") >= 0

test/unit/test_s3_util.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,36 @@ def test_download_retry_exceeded_error():
448448
match=r"GET with url .* failed for exceeding maximum retries",
449449
):
450450
rest_client.download_chunk(0)
451+
452+
453+
def test_accelerate_in_china_endpoint():
454+
meta_info = {
455+
"name": "data1.txt.gz",
456+
"stage_location_type": "S3",
457+
"no_sleeping_time": True,
458+
"put_callback": None,
459+
"put_callback_output_stream": None,
460+
SHA256_DIGEST: "123456789abcdef",
461+
"dst_file_name": "data1.txt.gz",
462+
"src_file_name": "path/to/put_get_1.txt",
463+
"overwrite": True,
464+
}
465+
meta = SnowflakeFileMeta(**meta_info)
466+
creds = {"AWS_SECRET_KEY": "", "AWS_KEY_ID": "", "AWS_TOKEN": ""}
467+
rest_client = SnowflakeS3RestClient(
468+
meta,
469+
StorageCredential(
470+
creds,
471+
MagicMock(autospec=SnowflakeConnection),
472+
"GET file:/tmp/file.txt @~",
473+
),
474+
{
475+
"locationType": "S3China",
476+
"location": "bucket/path",
477+
"creds": creds,
478+
"region": "test",
479+
"endPoint": None,
480+
},
481+
8 * megabyte,
482+
)
483+
assert not rest_client.transfer_accelerate_config()

0 commit comments

Comments
 (0)