-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AIRFLOW-5726] Delete table as file name in RedshiftToS3Transfer #6396
Conversation
I have a problem here with a part of the documentation, the one defining the param s3_key. If I leave it's definition as a single line ':param s3_key: reference to a specific S3 key. If table_as_file_name is set to False, this param must include the desired file name', If I split it in two lines as: Any idea on how to handle this? Thank you very much |
@JavierLopezT I'm not really sure I'm following. You can have more than one row example: |
Codecov Report
@@ Coverage Diff @@
## master #6396 +/- ##
==========================================
+ Coverage 80.59% 83.51% +2.91%
==========================================
Files 626 672 +46
Lines 36243 37594 +1351
==========================================
+ Hits 29211 31396 +2185
+ Misses 7032 6198 -834
Continue to review full report at Codecov.
|
Solving errors More errors Trying to pass documentation test indendation comment Delete table as file name in RedshiftToS3Transfer
I was missing the indentation on the 2nd row, thanks. Everything seems fine now |
It looks good but can you please add tests or update the current tests ! |
How can I do that? I thought that passing the TRAVIS CI checks was enough and I don't really find any documentation in Airflow contributing guiding through the process to add tests. Could you help me please? |
Thanks for the clarification @kaxil I have already added the test (I think) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you need to add a test covering table_as_file_name=False
case.
@JavierLopezT
|
assert mock_run.call_count == 1 | ||
assertEqualIgnoreMultipleSpaces(self, mock_run.call_args[0][0], unload_query) | ||
|
||
def test_execute_false(self, mock_run, mock_session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use parameterized in def test_execute
instead of creating new test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example:
@parameterized([
(2, 2, 4),
(2, 3, 8),
(1, 9, 1),
(0, 9, 0),
])
def test_pow(base, exponent, expected):
assert_equal(math.pow(base, exponent), expected)
@@ -31,7 +32,8 @@ class TestRedshiftToS3Transfer(unittest.TestCase): | |||
|
|||
@mock.patch("boto3.session.Session") | |||
@mock.patch("airflow.hooks.postgres_hook.PostgresHook.run") | |||
def test_execute(self, mock_run, mock_session): | |||
@parameterized([(True), (False)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parameterized([(True), (False)]) | |
@parameterized([(True, ), (False, )]) |
@@ -31,7 +32,8 @@ class TestRedshiftToS3Transfer(unittest.TestCase): | |||
|
|||
@mock.patch("boto3.session.Session") | |||
@mock.patch("airflow.hooks.postgres_hook.PostgresHook.run") | |||
def test_execute(self, mock_run, mock_session): | |||
@parameterized([(True, ), (False, )]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parameterized([(True, ), (False, )]) | |
@parameterized.expand([(True, ), (False, )]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should hopefully fix the failing test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it is still failing =(
@@ -31,7 +32,8 @@ class TestRedshiftToS3Transfer(unittest.TestCase): | |||
|
|||
@mock.patch("boto3.session.Session") | |||
@mock.patch("airflow.hooks.postgres_hook.PostgresHook.run") | |||
def test_execute(self, mock_run, mock_session): | |||
@parameterized.expand([(True, ), (False, )]) | |||
def test_execute(self, mock_run, mock_session, boolean_value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to try and run this my test on my machine and let you know
@JavierLopezT Apply the following code and the test will pass. Passes on my local machine: diff --git a/tests/operators/test_redshift_to_s3_operator.py b/tests/operators/test_redshift_to_s3_operator.py
index 5fd8d46e3..baa4aad32 100644
--- a/tests/operators/test_redshift_to_s3_operator.py
+++ b/tests/operators/test_redshift_to_s3_operator.py
@@ -30,10 +30,13 @@ from airflow.utils.tests import assertEqualIgnoreMultipleSpaces
class TestRedshiftToS3Transfer(unittest.TestCase):
+ @parameterized.expand([
+ [True, "key/table_"],
+ [False, "key"],
+ ])
@mock.patch("boto3.session.Session")
@mock.patch("airflow.hooks.postgres_hook.PostgresHook.run")
- @parameterized.expand([(True, ), (False, )])
- def test_execute(self, mock_run, mock_session, boolean_value):
+ def test_execute(self, table_as_file_name, expected_s3_key, mock_run, mock_session,):
access_key = "aws_access_key_id"
secret_key = "aws_secret_access_key"
mock_session.return_value = Session(access_key, secret_key)
@@ -42,7 +45,6 @@ class TestRedshiftToS3Transfer(unittest.TestCase):
s3_bucket = "bucket"
s3_key = "key"
unload_options = ['HEADER', ]
- table_as_file_name = boolean_value
RedshiftToS3Transfer(
schema=schema,
@@ -62,14 +64,14 @@ class TestRedshiftToS3Transfer(unittest.TestCase):
select_query = "SELECT * FROM {schema}.{table}".format(schema=schema, table=table)
unload_query = """
UNLOAD ('{select_query}')
- TO 's3://{s3_bucket}/{s3_key}/{table}_'
+ TO 's3://{s3_bucket}/{s3_key}'
with credentials
'aws_access_key_id={access_key};aws_secret_access_key={secret_key}'
{unload_options};
""".format(select_query=select_query,
- table=table,
s3_bucket=s3_bucket,
- s3_key=s3_key,
+ s3_key=expected_s3_key,
access_key=access_key,
secret_key=secret_key,
unload_options=unload_options) |
@@ -31,7 +32,11 @@ class TestRedshiftToS3Transfer(unittest.TestCase): | |||
|
|||
@mock.patch("boto3.session.Session") | |||
@mock.patch("airflow.hooks.postgres_hook.PostgresHook.run") | |||
def test_execute(self, mock_run, mock_session): | |||
@parameterized.expand([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have applied this to the wrong place, please check the diff #6396 (comment) I suggested 4 days back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be the following:
@parameterized.expand([
[True, "key/table_"],
[False, "key"],
])
@mock.patch("boto3.session.Session")
@mock.patch("airflow.hooks.postgres_hook.PostgresHook.run")
def test_execute(self, table_as_file_name, expected_s3_key, mock_run, mock_session,):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the position of @parameterized.expand([
Make sure you have checked all steps below.
Jira
Description
Now it is possible to have whatever file name for the file that will be stored in S3 and there is no limitation for table name. There is still the possibility to keep this choice though.
Tests
Commits
Documentation