diff --git a/presto-hive/src/main/java/io/prestosql/plugin/hive/HiveWriterFactory.java b/presto-hive/src/main/java/io/prestosql/plugin/hive/HiveWriterFactory.java index 728347eedb2c76898c5157c2f6460e44a6b22b62..e479daaab2c437f69bc935f5d3430f17b58e406d 100755 --- a/presto-hive/src/main/java/io/prestosql/plugin/hive/HiveWriterFactory.java +++ b/presto-hive/src/main/java/io/prestosql/plugin/hive/HiveWriterFactory.java @@ -366,7 +366,7 @@ public class HiveWriterFactory Optional partitionName; if (!partitionColumnNames.isEmpty()) { - partitionName = Optional.of(FileUtils.makePartName(partitionColumnNames, partitionValues)); + partitionName = Optional.of(FileUtils.makePartName(partitionColumnNames, partitionValues).replaceAll("\\s+$", "")); } else { partitionName = Optional.empty(); diff --git a/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveIntegrationSmokeTest.java b/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveIntegrationSmokeTest.java index 6955b72c316e92e1283872004c42cc6b110509e1..089e4b6f31122079cf90fb7a3849e86ab2356905 100644 --- a/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveIntegrationSmokeTest.java +++ b/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveIntegrationSmokeTest.java @@ -6588,4 +6588,35 @@ public class TestHiveIntegrationSmokeTest assertQuery(String.format("SELECT * FROM %s.%s", schema, table), "VALUES (1, 1, 1)"); assertUpdate(String.format("DROP TABLE %s.%s", schema, table)); } + + @Test + public void testNoPaddingForFixedCharPartitionColumn() + { + assertUpdate("CREATE TABLE fixed_char_partition_column (a int, b char(3)) with (format='orc', partitioned_by = ARRAY['b'])"); + assertUpdate("INSERT INTO fixed_char_partition_column VALUES(1,'o'), (2,'ol'),(3,'olk')", 3); + + TableMetadata tableMetadata = getTableMetadata(catalog, getSession().getSchema().get(), "fixed_char_partition_column"); + String tablePath = tableMetadata.getMetadata().getProperties().get("location").toString(); + + File tableDirectory = new File(tablePath.replace("file:", "")); + List files = listAllFiles(tableDirectory, new ArrayList<>()); + files.forEach((file) -> { + assertEquals(file.toString().split(" ").length, 1); + }); + + assertUpdate("DROP TABLE fixed_char_partition_column"); + } + + private List listAllFiles(File file, List resultFiles) + { + if (file.isFile()) { + resultFiles.add(file); + } + else { + for (File child : file.listFiles()) { + listAllFiles(child, resultFiles); + } + } + return resultFiles; + } }