MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / workflow_copy_to_s3

Function workflow_copy_to_s3

test/aws-localstack/mzcompose.py:244–304  ·  view source on GitHub ↗
(c: Composition)

Source from the content-addressed store, hash-verified

242
243
244def workflow_copy_to_s3(c: Composition) -> None:
245 with c.override(
246 Materialized(
247 depends_on=["localstack"],
248 environment_extra=[
249 f"AWS_ENDPOINT_URL={AWS_ENDPOINT_URL_MZ}",
250 f"AWS_ACCESS_KEY_ID={AWS_ACCESS_KEY_ID}",
251 f"AWS_SECRET_ACCESS_KEY={AWS_SECRET_ACCESS_KEY}",
252 ],
253 )
254 ):
255 c.up("localstack", "materialized")
256 localhost_aws_endpoint_url = f"http://localhost:{c.port('localstack', 4566)}"
257 s3_client = boto3.client(
258 "s3",
259 endpoint_url=localhost_aws_endpoint_url,
260 region_name=DEFAULT_CLOUD_REGION,
261 aws_access_key_id=AWS_ACCESS_KEY_ID,
262 aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
263 )
264 bucket_name = "copy-to-s3"
265 s3_client.create_bucket(Bucket=bucket_name)
266 path_prefix = str(uuid.uuid4())
267 c.run_testdrive_files(
268 f"--var=endpoint={AWS_ENDPOINT_URL_MZ}",
269 f"--var=access-key={AWS_ACCESS_KEY_ID}",
270 f"--var=secret-key={AWS_SECRET_ACCESS_KEY}",
271 f"--var=s3-prefix={bucket_name}/{path_prefix}",
272 f"--var=region={DEFAULT_CLOUD_REGION}",
273 "--default-timeout=300s",
274 "copy-to-s3/copy-to-s3.td",
275 )
276
277 def validate_upload(upload, expected_output_set):
278 assert len(upload["Contents"]) > 0
279 output_lines = set()
280 for obj in upload["Contents"]:
281 assert obj["Key"].endswith(".csv")
282 key = obj["Key"]
283 object_response = s3_client.get_object(Bucket=bucket_name, Key=key)
284 body = object_response["Body"].read().decode("utf-8")
285 output_lines.update(body.splitlines())
286 assert output_lines == expected_output_set
287
288 # asserting the uploaded files
289 date = c.sql_query("SELECT TO_CHAR(now(), 'YYYY-MM-DD')")[0][0]
290 expected_output = set(map(lambda x: str(x), range(10)))
291 first_upload = s3_client.list_objects_v2(
292 Bucket=bucket_name, Prefix=f"{path_prefix}/1/{date}/"
293 )
294 validate_upload(first_upload, expected_output)
295
296 second_upload = s3_client.list_objects_v2(
297 Bucket=bucket_name, Prefix=f"{path_prefix}/2/"
298 )
299 validate_upload(second_upload, expected_output)
300
301 third_upload = s3_client.list_objects_v2(

Callers

nothing calls this directly

Calls 9

MaterializedClass · 0.90
validate_uploadFunction · 0.85
overrideMethod · 0.80
run_testdrive_filesMethod · 0.80
setFunction · 0.50
upMethod · 0.45
portMethod · 0.45
clientMethod · 0.45
sql_queryMethod · 0.45

Tested by

no test coverage detected