Matrix42 closed pull request #7287: [FLINK-11140][streaming] Fix empty child
path check in Buckets
URL: https://github.com/apache/flink/pull/7287
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/sink/filesystem/Buckets.java
b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/sink/filesystem/Buckets.java
index d08bc2ac0c3..736fd412d55 100644
---
a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/sink/filesystem/Buckets.java
+++
b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/sink/filesystem/Buckets.java
@@ -304,7 +304,11 @@ void close() {
}
private Path assembleBucketPath(BucketID bucketId) {
- return new Path(basePath, bucketId.toString());
+ String child = bucketId.toString();
+ if ("".equals(child)) {
+ return basePath;
+ }
+ return new Path(basePath, child);
}
/**
diff --git
a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketsTest.java
b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketsTest.java
index aee362178a7..81bf3fccf56 100644
---
a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketsTest.java
+++
b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketsTest.java
@@ -23,6 +23,7 @@
import org.apache.flink.core.fs.Path;
import org.apache.flink.core.io.SimpleVersionedSerializer;
import
org.apache.flink.streaming.api.functions.sink.filesystem.TestUtils.MockListState;
+import
org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.BasePathBucketAssigner;
import
org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.SimpleVersionedStringSerializer;
import
org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.DefaultRollingPolicy;
import
org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.OnCheckpointRollingPolicy;
@@ -396,4 +397,28 @@ public String getBucketId(String element,
BucketAssigner.Context context) {
restoredBuckets.initializeState(bucketState, partCounterState);
return restoredBuckets;
}
+
+ @Test
+ public void testAssembleBucketPath() throws Exception {
+ final File outDir = TEMP_FOLDER.newFolder();
+ final Path basePath = new Path(outDir.toURI());
+
+ final RollingPolicy<String, String> rollingPolicy =
+ DefaultRollingPolicy
+ .create()
+ .withMaxPartSize(7L)
+ .build();
+
+ Buckets<String, String> buckets = new Buckets<>(
+ basePath,
+ new BasePathBucketAssigner<>(),
+ new DefaultBucketFactoryImpl<>(),
+ new RowWisePartWriter.Factory<>(new
SimpleStringEncoder<>()),
+ rollingPolicy,
+ 0
+ );
+ long time = System.currentTimeMillis();
+ //onElement will invoke Buckets#AssembleBucketPath
+ buckets.onElement("abc", new TestUtils.MockSinkContext(time,
time, time));
+ }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services