copy_to_s3.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from textwrap import dedent
  10. from materialize.checks.actions import Testdrive
  11. from materialize.checks.checks import Check, externally_idempotent
  12. @externally_idempotent(False)
  13. class CopyToS3(Check):
  14. """Basic check on copy to s3"""
  15. def initialize(self) -> Testdrive:
  16. return Testdrive(
  17. dedent(
  18. """
  19. > CREATE SECRET minio AS '${arg.aws-secret-access-key}'
  20. > CREATE CONNECTION aws_conn1 TO AWS (ENDPOINT '${arg.aws-endpoint}', REGION 'us-east-1', ACCESS KEY ID '${arg.aws-access-key-id}', SECRET ACCESS KEY SECRET minio)
  21. > COPY (SELECT 1, 2, 3) TO 's3://copytos3/key1' WITH (AWS CONNECTION = aws_conn1, FORMAT = 'csv');
  22. """
  23. )
  24. )
  25. def manipulate(self) -> list[Testdrive]:
  26. return [
  27. Testdrive(dedent(s))
  28. for s in [
  29. """
  30. > CREATE CONNECTION aws_conn2 TO AWS (ENDPOINT '${arg.aws-endpoint}', REGION 'us-east-1', ACCESS KEY ID '${arg.aws-access-key-id}', SECRET ACCESS KEY SECRET minio)
  31. > COPY (SELECT 11, 12, 13) TO 's3://copytos3/key11' WITH (AWS CONNECTION = aws_conn1, FORMAT = 'csv');
  32. > COPY (SELECT 11, 12, 13) TO 's3://copytos3/key12' WITH (AWS CONNECTION = aws_conn2, FORMAT = 'csv');
  33. """,
  34. """
  35. > CREATE CONNECTION aws_conn3 TO AWS (ENDPOINT '${arg.aws-endpoint}', REGION 'us-east-1', ACCESS KEY ID '${arg.aws-access-key-id}', SECRET ACCESS KEY SECRET minio)
  36. > COPY (SELECT 21, 22, 23) TO 's3://copytos3/key21' WITH (AWS CONNECTION = aws_conn1, FORMAT = 'csv');
  37. > COPY (SELECT 21, 22, 23) TO 's3://copytos3/key22' WITH (AWS CONNECTION = aws_conn2, FORMAT = 'csv');
  38. > COPY (SELECT 21, 22, 23) TO 's3://copytos3/key23' WITH (AWS CONNECTION = aws_conn3, FORMAT = 'csv');
  39. """,
  40. ]
  41. ]
  42. def validate(self) -> Testdrive:
  43. return Testdrive(
  44. dedent(
  45. """
  46. $ s3-verify-data bucket=copytos3 key=key1
  47. 1,2,3
  48. $ s3-verify-data bucket=copytos3 key=key11
  49. 11,12,13
  50. $ s3-verify-data bucket=copytos3 key=key12
  51. 11,12,13
  52. $ s3-verify-data bucket=copytos3 key=key21
  53. 21,22,23
  54. $ s3-verify-data bucket=copytos3 key=key22
  55. 21,22,23
  56. $ s3-verify-data bucket=copytos3 key=key23
  57. 21,22,23
  58. """
  59. )
  60. )