Skip to content

Commit fded129

Browse files
committed
Fix #21317: Replace colons with underscores in window filenames for Windows compatibility
The default FilenamePolicy uses Instant.toString() for Beam Windows, which produces ISO-8601 format (e.g., 2021-12-31T23:00:00.000Z) containing colons. Colons are illegal characters in Windows file paths, causing InvalidPathException when using TextIO.write().withWindowedWrites() on Windows. This fix replaces colons with underscores ONLY on Windows to ensure cross-platform compatibility without breaking existing filenames on other OSes. Fixes #21317
1 parent e6fcdd7 commit fded129

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

sdks/java/core/src/main/java/org/apache/beam/sdk/io/DefaultFilenamePolicy.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,15 @@ private String windowToString(BoundedWindow window) {
353353
}
354354
if (window instanceof IntervalWindow) {
355355
IntervalWindow iw = (IntervalWindow) window;
356-
return String.format("%s-%s", iw.start().toString(), iw.end().toString());
356+
// Use ISO-8601 format but replace colons with underscores for Windows compatibility
357+
// since colons are illegal characters in Windows file paths.
358+
String startStr = iw.start().toString();
359+
String endStr = iw.end().toString();
360+
if (System.getProperty("os.name").startsWith("Windows")) {
361+
startStr = startStr.replace(':', '_');
362+
endStr = endStr.replace(':', '_');
363+
}
364+
return String.format("%s-%s", startStr, endStr);
357365
}
358366
return window.toString();
359367
}

0 commit comments

Comments
 (0)