From 6c70844b54bf414ad6cabbef6afb5b22ef2140a8 Mon Sep 17 00:00:00 2001 From: Jiao Mingye <35512473+mxdzs0612@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:41:49 +0800 Subject: [PATCH] [BugFix] Fix cannot insert into overwrite a hive partition when files are written by hive (#53792) Signed-off-by: Jiao Mingye --- .../java/com/starrocks/connector/hive/HiveWriteUtils.java | 7 +++++-- .../com/starrocks/connector/hive/HiveWriteUtilsTest.java | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/hive/HiveWriteUtils.java b/fe/fe-core/src/main/java/com/starrocks/connector/hive/HiveWriteUtils.java index 55f82c084586e..cb738df616c75 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/hive/HiveWriteUtils.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/hive/HiveWriteUtils.java @@ -110,8 +110,11 @@ public static String getStagingDir(HiveTable table, String tempStagingDir) { } public static boolean fileCreatedByQuery(String fileName, String queryId) { - Preconditions.checkState(fileName.length() > queryId.length() && queryId.length() > 8, - "file name or query id is invalid"); + Preconditions.checkState(queryId.length() > 8, "file name or query id is invalid"); + if (fileName.length() <= queryId.length()) { + // file is created by other engine like hive + return false; + } String checkQueryId = queryId.substring(0, queryId.length() - 8); return fileName.startsWith(checkQueryId) || fileName.endsWith(checkQueryId); } diff --git a/fe/fe-core/src/test/java/com/starrocks/connector/hive/HiveWriteUtilsTest.java b/fe/fe-core/src/test/java/com/starrocks/connector/hive/HiveWriteUtilsTest.java index 6a81ada130088..e6b1ffaa2a03e 100644 --- a/fe/fe-core/src/test/java/com/starrocks/connector/hive/HiveWriteUtilsTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/connector/hive/HiveWriteUtilsTest.java @@ -96,4 +96,9 @@ public FileSystem get(URI uri, Configuration conf) { "Failed to create directory", () -> HiveWriteUtils.createDirectory(path, new Configuration())); } + + @Test + public void testFileCreateByQuery() { + Assert.assertFalse(HiveWriteUtils.fileCreatedByQuery("000000_0", "aaaa-bbbb")); + } }