You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "lahariguduru (via GitHub)" <gi...@apache.org> on 2024/07/08 20:55:04 UTC
[PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
lahariguduru opened a new pull request, #31802:
URL: https://github.com/apache/beam/pull/31802
This PR closes #31719.
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "johnjcasey (via GitHub)" <gi...@apache.org>.
johnjcasey commented on code in PR #31802:
URL: https://github.com/apache/beam/pull/31802#discussion_r1670968134
##########
sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java:
##########
@@ -48,8 +50,38 @@ static List<Schema.Field> mapFieldPositions(CSVFormat format, Schema schema) {
* Parse the given {@link String} cell of the CSV record based on the given field's {@link
* Schema.FieldType}.
*/
- // TODO(https://github.com/apache/beam/issues/31719): implement method.
static Object parseCell(String cell, Schema.Field field) {
- return "";
+ Schema.FieldType fieldType = field.getType();
+ try {
+ switch (fieldType.getTypeName()) {
+ case STRING:
+ return cell;
+ case INT16:
+ return Short.parseShort(cell);
+ case INT32:
+ return Integer.parseInt(cell);
+ case INT64:
+ return Long.parseLong(cell);
+ case BOOLEAN:
+ return Boolean.parseBoolean(cell);
+ case BYTE:
+ return Byte.parseByte(cell);
+ case DECIMAL:
+ return new BigDecimal(cell);
+ case DOUBLE:
+ return Double.parseDouble(cell);
+ case FLOAT:
+ return Float.parseFloat(cell);
+ case DATETIME:
+ return Instant.parse(cell);
Review Comment:
Is the value always going to be in a format such that instant can parse it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #31802:
URL: https://github.com/apache/beam/pull/31802#issuecomment-2221188234
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment `assign set of reviewers`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "lahariguduru (via GitHub)" <gi...@apache.org>.
lahariguduru commented on code in PR #31802:
URL: https://github.com/apache/beam/pull/31802#discussion_r1673186384
##########
sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java:
##########
@@ -48,8 +50,38 @@ static List<Schema.Field> mapFieldPositions(CSVFormat format, Schema schema) {
* Parse the given {@link String} cell of the CSV record based on the given field's {@link
* Schema.FieldType}.
*/
- // TODO(https://github.com/apache/beam/issues/31719): implement method.
static Object parseCell(String cell, Schema.Field field) {
- return "";
+ Schema.FieldType fieldType = field.getType();
+ try {
+ switch (fieldType.getTypeName()) {
+ case STRING:
+ return cell;
+ case INT16:
+ return Short.parseShort(cell);
+ case INT32:
+ return Integer.parseInt(cell);
+ case INT64:
+ return Long.parseLong(cell);
+ case BOOLEAN:
+ return Boolean.parseBoolean(cell);
+ case BYTE:
+ return Byte.parseByte(cell);
+ case DECIMAL:
+ return new BigDecimal(cell);
+ case DOUBLE:
+ return Double.parseDouble(cell);
+ case FLOAT:
+ return Float.parseFloat(cell);
+ case DATETIME:
+ return Instant.parse(cell);
+ default:
+ throw new IllegalArgumentException(
Review Comment:
I completely agree, just changed the method to utilize UnsupportedOperationException instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #31802:
URL: https://github.com/apache/beam/pull/31802#issuecomment-2215431311
Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
R: @damondouglas for label java.
R: @johnjcasey for label io.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "lahariguduru (via GitHub)" <gi...@apache.org>.
lahariguduru commented on PR #31802:
URL: https://github.com/apache/beam/pull/31802#issuecomment-2221186319
R: @Abacn
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #31802:
URL: https://github.com/apache/beam/pull/31802#issuecomment-2215488032
Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
R: @kennknowles for label java.
R: @johnjcasey for label io.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "damondouglas (via GitHub)" <gi...@apache.org>.
damondouglas commented on PR #31802:
URL: https://github.com/apache/beam/pull/31802#issuecomment-2218580718
@johnjcasey Thank you for your review. @lahariguduru is my student and I will clear my review after yours.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #31802:
URL: https://github.com/apache/beam/pull/31802#discussion_r1672837669
##########
sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java:
##########
@@ -48,8 +50,38 @@ static List<Schema.Field> mapFieldPositions(CSVFormat format, Schema schema) {
* Parse the given {@link String} cell of the CSV record based on the given field's {@link
* Schema.FieldType}.
*/
- // TODO(https://github.com/apache/beam/issues/31719): implement method.
static Object parseCell(String cell, Schema.Field field) {
- return "";
+ Schema.FieldType fieldType = field.getType();
+ try {
+ switch (fieldType.getTypeName()) {
+ case STRING:
+ return cell;
+ case INT16:
+ return Short.parseShort(cell);
+ case INT32:
+ return Integer.parseInt(cell);
+ case INT64:
+ return Long.parseLong(cell);
+ case BOOLEAN:
+ return Boolean.parseBoolean(cell);
+ case BYTE:
+ return Byte.parseByte(cell);
+ case DECIMAL:
+ return new BigDecimal(cell);
+ case DOUBLE:
+ return Double.parseDouble(cell);
+ case FLOAT:
+ return Float.parseFloat(cell);
+ case DATETIME:
+ return Instant.parse(cell);
+ default:
+ throw new IllegalArgumentException(
Review Comment:
Consider UnsupportedOperationException ? Otherwise it will be caught in outer try block and throw again, which is redundant
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "lahariguduru (via GitHub)" <gi...@apache.org>.
lahariguduru commented on code in PR #31802:
URL: https://github.com/apache/beam/pull/31802#discussion_r1670974053
##########
sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java:
##########
@@ -48,8 +50,38 @@ static List<Schema.Field> mapFieldPositions(CSVFormat format, Schema schema) {
* Parse the given {@link String} cell of the CSV record based on the given field's {@link
* Schema.FieldType}.
*/
- // TODO(https://github.com/apache/beam/issues/31719): implement method.
static Object parseCell(String cell, Schema.Field field) {
- return "";
+ Schema.FieldType fieldType = field.getType();
+ try {
+ switch (fieldType.getTypeName()) {
+ case STRING:
+ return cell;
+ case INT16:
+ return Short.parseShort(cell);
+ case INT32:
+ return Integer.parseInt(cell);
+ case INT64:
+ return Long.parseLong(cell);
+ case BOOLEAN:
+ return Boolean.parseBoolean(cell);
+ case BYTE:
+ return Byte.parseByte(cell);
+ case DECIMAL:
+ return new BigDecimal(cell);
+ case DOUBLE:
+ return Double.parseDouble(cell);
+ case FLOAT:
+ return Float.parseFloat(cell);
+ case DATETIME:
+ return Instant.parse(cell);
Review Comment:
No, there is an error PCollection that is thrown for types that are not Default.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "damondouglas (via GitHub)" <gi...@apache.org>.
damondouglas commented on code in PR #31802:
URL: https://github.com/apache/beam/pull/31802#discussion_r1669421259
##########
sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/ExamplePojo.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.csv;
+
+import com.google.auto.value.AutoValue;
+import java.time.Instant;
+import org.apache.beam.sdk.schemas.AutoValueSchema;
+import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
+import org.apache.beam.sdk.schemas.annotations.SchemaCaseFormat;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.CaseFormat;
+
+@SchemaCaseFormat(CaseFormat.LOWER_UNDERSCORE)
+@AutoValue
+@DefaultSchema(AutoValueSchema.class)
+abstract class ExamplePojo {
Review Comment:
Remove this file from the PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "damondouglas (via GitHub)" <gi...@apache.org>.
damondouglas commented on PR #31802:
URL: https://github.com/apache/beam/pull/31802#issuecomment-2215486879
assign to next reviewer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CsvIO] Implemented CsvIOParseHelpers:parseCell [beam]
Posted by "damondouglas (via GitHub)" <gi...@apache.org>.
damondouglas merged PR #31802:
URL: https://github.com/apache/beam/pull/31802
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org