From 6fa5bf71de9204fc0ae998d5b2aa38da5cd1736a Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Tue, 4 Jul 2023 17:51:08 +0200 Subject: [PATCH] Fix Hive sorted write failure when user identity contains @ sign It's common for staging path to contain `${USER}` placeholder and be on local file system. When username contains an AT sign (`name@domain`), the `setSchemeToFileIfAbsent` used to fail. --- .../java/io/trino/plugin/hive/HiveWriterFactory.java | 2 +- .../io/trino/plugin/hive/TestHiveWriterFactory.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveWriterFactory.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveWriterFactory.java index 0402d29933f4..eac252240698 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveWriterFactory.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveWriterFactory.java @@ -812,7 +812,7 @@ static Location setSchemeToFileIfAbsent(Location location) if (location.scheme().isPresent()) { return location; } - return Location.of("file:///" + location.path()); + return Location.of("file://@/" + location.path()); } private static class DataColumn diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveWriterFactory.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveWriterFactory.java index 8a61eca133b6..46fab5ce4595 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveWriterFactory.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveWriterFactory.java @@ -45,7 +45,7 @@ public void testSetsSchemeToFile() { String pathWithoutScheme = "/simple/file/path"; String result = setSchemeToFileIfAbsent(Location.of(pathWithoutScheme)).toString(); - assertThat(result).isEqualTo("file:///simple/file/path"); + assertThat(result).isEqualTo("file://@/simple/file/path"); URI resultUri = new Path(result).toUri(); assertThat(resultUri.getScheme()).isEqualTo("file"); assertThat(resultUri.getPath()).isEqualTo("/simple/file/path"); @@ -59,7 +59,7 @@ public void testSetsSchemeToFile() String pathWithEmptySpaces = "/simple/file 1/path"; result = setSchemeToFileIfAbsent(Location.of(pathWithEmptySpaces)).toString(); - assertThat(result).isEqualTo("file:///simple/file 1/path"); + assertThat(result).isEqualTo("file://@/simple/file 1/path"); resultUri = new Path(result).toUri(); assertThat(resultUri.getScheme()).isEqualTo("file"); assertThat(resultUri.getPath()).isEqualTo("/simple/file 1/path"); @@ -70,5 +70,12 @@ public void testSetsSchemeToFile() resultUri = new Path(result).toUri(); assertThat(resultUri.getScheme()).isEqualTo("s3"); assertThat(resultUri.getPath()).isEqualTo("/file 1/path"); + + String pathWithAtSign = "/tmp/user@example.com"; + result = setSchemeToFileIfAbsent(Location.of(pathWithAtSign)).toString(); + assertThat(result).isEqualTo("file://@/tmp/user@example.com"); + resultUri = new Path(result).toUri(); + assertThat(resultUri.getScheme()).isEqualTo("file"); + assertThat(resultUri.getPath()).isEqualTo("/tmp/user@example.com"); } }