-
Notifications
You must be signed in to change notification settings - Fork 722
Extending logic to add_csv_partitions and leveraging catalog_table_input #674
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -501,6 +501,11 @@ def to_csv( # pylint: disable=too-many-arguments,too-many-locals,too-many-state | |
| columns_types, partitions_types = _data_types.athena_types_from_pandas_partitioned( | ||
| df=df, index=index, partition_cols=partition_cols, dtype=dtype, index_left=True | ||
| ) | ||
| serde_info: Dict[str, Any] = {} | ||
| if catalog_table_input: | ||
| serde_info = catalog_table_input["StorageDescriptor"]["SerdeInfo"] | ||
| serde_library: Optional[str] = serde_info.get("SerializationLibrary", None) | ||
| serde_parameters: Optional[Dict[str, str]] = serde_info.get("Parameters", None) | ||
|
Comment on lines
+504
to
+508
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the |
||
| catalog._create_csv_table( # pylint: disable=protected-access | ||
| database=database, | ||
| table=table, | ||
|
|
@@ -525,8 +530,8 @@ def to_csv( # pylint: disable=too-many-arguments,too-many-locals,too-many-state | |
| catalog_id=catalog_id, | ||
| compression=pandas_kwargs.get("compression"), | ||
| skip_header_line_count=None, | ||
| serde_library=None, | ||
| serde_parameters=None, | ||
| serde_library=serde_library, | ||
| serde_parameters=serde_parameters, | ||
| ) | ||
| if partitions_values and (regular_partitions is True): | ||
| _logger.debug("partitions_values:\n%s", partitions_values) | ||
|
|
@@ -537,6 +542,8 @@ def to_csv( # pylint: disable=too-many-arguments,too-many-locals,too-many-state | |
| bucketing_info=bucketing_info, | ||
| boto3_session=session, | ||
| sep=sep, | ||
| serde_library=serde_library, | ||
| serde_parameters=serde_parameters, | ||
| catalog_id=catalog_id, | ||
| columns_types=columns_types, | ||
| compression=pandas_kwargs.get("compression"), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -451,15 +451,31 @@ def test_csv_compressed(path, glue_table, glue_database, use_threads, concurrent | |
| @pytest.mark.parametrize("use_threads", [True, False]) | ||
| @pytest.mark.parametrize("ctas_approach", [True, False]) | ||
| def test_opencsv_serde(path, glue_table, glue_database, use_threads, ctas_approach): | ||
| df = pd.DataFrame({"c0": ['"1"', '"2"', '"3"'], "c1": ['"4"', '"5"', '"6"'], "c2": ['"a"', '"b"', '"c"']}) | ||
| wr.s3.to_csv( | ||
| df=df, path=f"{path}0.csv", sep=",", index=False, header=False, use_threads=use_threads, quoting=csv.QUOTE_NONE | ||
| df = pd.DataFrame({"col": ["1", "2", "3"], "col2": ["A", "A", "B"]}) | ||
| response = wr.s3.to_csv( | ||
| df=df, | ||
| path=path, | ||
| dataset=True, | ||
| partition_cols=["col2"], | ||
| sep=",", | ||
| index=False, | ||
| header=False, | ||
| use_threads=use_threads, | ||
| quoting=csv.QUOTE_NONE, | ||
| ) | ||
| wr.catalog.create_csv_table( | ||
| database=glue_database, | ||
| table=glue_table, | ||
| path=path, | ||
| columns_types={"c0": "string", "c1": "string", "c2": "string"}, | ||
| columns_types={"col": "string"}, | ||
| partitions_types={"col2": "string"}, | ||
| serde_library="org.apache.hadoop.hive.serde2.OpenCSVSerde", | ||
| serde_parameters={"separatorChar": ",", "quoteChar": '"', "escapeChar": "\\"}, | ||
| ) | ||
| wr.catalog.add_csv_partitions( | ||
| database=glue_database, | ||
| table=glue_table, | ||
| partitions_values=response["partitions_values"], | ||
|
Comment on lines
+475
to
+478
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extended the test to include |
||
| serde_library="org.apache.hadoop.hive.serde2.OpenCSVSerde", | ||
| serde_parameters={"separatorChar": ",", "quoteChar": '"', "escapeChar": "\\"}, | ||
| ) | ||
|
|
||
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 believe we missed this method in the previous PR
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.
@maxispeicher, apologies, I am not sure if I already tagged you to this PR or not for review?
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'm not sure either. If so, I completely missed it 🙈
I also thought that I did include it but seems like I forgot about it eventually 😓.