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:5154–5227  ·  view source on GitHub ↗
(s3_server)

Source from the content-addressed store, hash-verified

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