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