You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/08/03 10:35:00 UTC

[jira] [Work logged] (BEAM-10292) DefaultFilenamePolicy.ParamsCoder loses information whether Params's resource ID is file/directory

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

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

                Author: ASF GitHub Bot
            Created on: 03/Aug/20 10:34
            Start Date: 03/Aug/20 10:34
    Worklog Time Spent: 10m 
      Work Description: davidak09 commented on a change in pull request #12050:
URL: https://github.com/apache/beam/pull/12050#discussion_r464331768



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/DefaultFilenamePolicy.java
##########
@@ -182,19 +184,26 @@ public void encode(Params value, OutputStream outStream) throws IOException {
       if (value == null) {
         throw new CoderException("cannot encode a null value");
       }
-      stringCoder.encode(value.baseFilename.get().toString(), outStream);
-      stringCoder.encode(value.shardTemplate, outStream);
-      stringCoder.encode(value.suffix, outStream);
+      STRING_CODER.encode(value.baseFilename.get().toString(), outStream);
+      STRING_CODER.encode(value.shardTemplate, outStream);
+      STRING_CODER.encode(value.suffix, outStream);
+      BOOLEAN_CODER.encode(value.baseFilename.get().isDirectory(), outStream);
     }
 
     @Override
     public Params decode(InputStream inStream) throws IOException {
-      ResourceId prefix =
-          FileBasedSink.convertToFileResourceIfPossible(stringCoder.decode(inStream));
-      String shardTemplate = stringCoder.decode(inStream);
-      String suffix = stringCoder.decode(inStream);
+      String prefix = STRING_CODER.decode(inStream);
+      String shardTemplate = STRING_CODER.decode(inStream);
+      String suffix = STRING_CODER.decode(inStream);
+      ResourceId baseFilename;
+      if (inStream.available() > 0) {
+        baseFilename = FileSystems.matchNewResource(prefix, BOOLEAN_CODER.decode(inStream));
+      } else {
+        // fallback for ensure backward compatibility
+        baseFilename = FileBasedSink.convertToFileResourceIfPossible(prefix);

Review comment:
       OK, I agree with the first solution - taking the breaking change. I will ask on the mailing list.
   
   BTW I did workaround in my project where I use only files (not directories) as `Params` base filenames and then everything works fine. That means I no longer needs this fix but it still seems to me like a bug which is worth fixing.
   
   (P.S.: The suffix wouldn't have to be the path separator (`/`) but e.g. `sometotallyrandomstring123`  - but it's very ugly...)
   




----------------------------------------------------------------
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:
users@infra.apache.org


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

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

> DefaultFilenamePolicy.ParamsCoder loses information whether Params's resource ID is file/directory
> --------------------------------------------------------------------------------------------------
>
>                 Key: BEAM-10292
>                 URL: https://issues.apache.org/jira/browse/BEAM-10292
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: David Janicek
>            Priority: P2
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> *DefaultFilenamePolicy.ParamsCoder* uses simple *StringUtf8Coder* for encoding/decoding *DefaultFilenamePolicy.Params*'s *baseFilename* and therefore looses information whether *Params.baseFilename* resource ID is file or directory.
> The result is that it's effectively preventing user to define directory as *baseFilename provider* when using dynamic destinations because after deserialization it's translated to file.
> Solution is easy - use *ResourceIdCoder* for encoding/decoding.



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