[ 
https://issues.apache.org/jira/browse/BEAM-8865?focusedWorklogId=352642&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-352642
 ]

ASF GitHub Bot logged work on BEAM-8865:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Dec/19 14:15
            Start Date: 03/Dec/19 14:15
    Worklog Time Spent: 10m 
      Work Description: suztomo commented on pull request #10256: [BEAM-8865] 
Updating Javadoc of FileIO example
URL: https://github.com/apache/beam/pull/10256#discussion_r353201798
 
 

 ##########
 File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileIO.java
 ##########
 @@ -135,9 +135,15 @@
  *     .apply(FileIO.readMatches().withCompression(GZIP))
  *     .apply(MapElements
  *         // uses imports from TypeDescriptors
- *         .into(KVs(strings(), strings()))
- *         .via((ReadableFile f) -> KV.of(
- *             f.getMetadata().resourceId().toString(), 
f.readFullyAsUTF8String())));
+ *         .into(kvs(strings(), strings()))
+ *         .via((ReadableFile f) -> {
+ *           try {
+ *             return KV.of(
+ *                 f.getMetadata().resourceId().toString(), 
f.readFullyAsUTF8String());
+ *           } catch (IOException ex) {
+ *             throw new RuntimeException("Failed to read the file", ex);
 
 Review comment:
   Interesting; is there a way to use lambda while letting a checked exception 
thrown?
   
   My IntelliJ complains as below:
   
   <img width="697" alt="Screen Shot 2019-12-03 at 09 07 42" 
src="https://user-images.githubusercontent.com/28604/70058271-96fde000-15ac-11ea-9ea0-fb3057974bdb.png";>
   
   
   Also from Maven:
   
   ```
   [ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) 
on project word-count-beam: Compilation failure
   [ERROR] 
/Users/suztomo/word-count-beam/src/main/java/org/apache/beam/examples/WordCount.java:[225,85]
 unreported exception java.io.IOException; must be caught or declared to be 
thrown
   ```
   
   IntelliJ says it picks up this method (not the one with `Contextful`):
   
   ```
     /** Binary compatibility adapter for {@link #via(ProcessFunction)}. */
     public <NewInputT> MapElements<NewInputT, OutputT> via(
         SerializableFunction<NewInputT, OutputT> fn) {
       return via((ProcessFunction<NewInputT, OutputT>) fn);
     }
   ```
   
   Am I using the example in a wrong way?
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 352642)
    Time Spent: 1h  (was: 50m)

> FileIO's Javadoc is outdated: TypeDescriptors.KVs and unhandled IOException
> ---------------------------------------------------------------------------
>
>                 Key: BEAM-8865
>                 URL: https://issues.apache.org/jira/browse/BEAM-8865
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: Tomo Suzuki
>            Assignee: Tomo Suzuki
>            Priority: Major
>         Attachments: v1YuuuT2o2i.png
>
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> The doc says
>  !v1YuuuT2o2i.png! 
> However, I had to modify the code to below:
> {noformat}
>     p.apply("ReadLines",
>         FileIO.match().filepattern("hdfs:///foo/bar/*.gz"))
>         .apply(FileIO.readMatches().withCompression(GZIP))
>         .apply(MapElements
>             // uses imports from TypeDescriptors
>             .into(kvs(strings(), strings()))
>             .via((ReadableFile f) -> {
>               try {
>                 return KV.of(
>                     f.getMetadata().resourceId().toString(), 
> f.readFullyAsUTF8String());
>               } catch (IOException ex) {
>                 throw new RuntimeException("Failed to read the file", ex);
>               }
>              }))
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to