MCPcopy Create free account
hub / github.com/apache/arrow / test_write_dataset_s3_put_only

Function test_write_dataset_s3_put_only

python/pyarrow/tests/test_dataset.py:5150–5223  ·  view source on GitHub ↗
(s3_server)

Source from the content-addressed store, hash-verified

5148@pytest.mark.parquet
5149@pytest.mark.s3
5150def test_write_dataset_s3_put_only(s3_server):
5151 # [ARROW-15892] Testing the create_dir flag which will restrict
5152 # creating a new directory for writing a dataset. This is
5153 # required while writing a dataset in s3 where we have very
5154 # limited permissions and thus we can directly write the dataset
5155 # without creating a directory.
5156 from pyarrow.fs import S3FileSystem
5157
5158 # write dataset with s3 filesystem
5159 host, port, _, _ = s3_server['connection']
5160
5161 _configure_s3_limited_user(s3_server, _minio_put_only_policy,
5162 'test_dataset_limited_user', 'limited123')
5163 fs = S3FileSystem(
5164 access_key='test_dataset_limited_user',
5165 secret_key='limited123',
5166 endpoint_override=f'{host}:{port}',
5167 scheme='http'
5168 )
5169
5170 table = pa.table([
5171 pa.array(range(20)), pa.array(random.random() for _ in range(20)),
5172 pa.array(['a']*10 + ['b'] * 10)],
5173 names=["f1", "f2", "part"]
5174 )
5175 part = ds.partitioning(pa.schema([("part", pa.string())]), flavor="hive")
5176
5177 # writing with filesystem object with create_dir flag set to false
5178 ds.write_dataset(
5179 table, "existing-bucket", filesystem=fs,
5180 format="feather", create_dir=False, partitioning=part,
5181 existing_data_behavior='overwrite_or_ignore'
5182 )
5183 # check roundtrip
5184 result = ds.dataset(
5185 "existing-bucket", filesystem=fs, format="ipc", partitioning="hive"
5186 ).to_table()
5187 assert result.equals(table)
5188
5189 # Passing create_dir is fine if the bucket already exists
5190 ds.write_dataset(
5191 table, "existing-bucket", filesystem=fs,
5192 format="feather", create_dir=True, partitioning=part,
5193 existing_data_behavior='overwrite_or_ignore'
5194 )
5195 # check roundtrip
5196 result = ds.dataset(
5197 "existing-bucket", filesystem=fs, format="ipc", partitioning="hive"
5198 ).to_table()
5199 assert result.equals(table)
5200
5201 # Error enforced by filesystem
5202 with pytest.raises(OSError,
5203 match="Bucket 'non-existing-bucket' not found"):
5204 ds.write_dataset(
5205 table, "non-existing-bucket", filesystem=fs,
5206 format="feather", create_dir=True,
5207 existing_data_behavior='overwrite_or_ignore'

Callers

nothing calls this directly

Calls 8

S3FileSystemClass · 0.85
partitioningMethod · 0.80
equalsMethod · 0.80
arrayMethod · 0.45
schemaMethod · 0.45
stringMethod · 0.45
to_tableMethod · 0.45

Tested by

no test coverage detected