diff --git common/src/java/org/apache/hadoop/hive/common/type/Date.java common/src/java/org/apache/hadoop/hive/common/type/Date.java index c7e2ab9980..6aeb06f20a 100644 --- common/src/java/org/apache/hadoop/hive/common/type/Date.java +++ common/src/java/org/apache/hadoop/hive/common/type/Date.java @@ -125,7 +125,8 @@ public void setTimeInMillis(long epochMilli) { } public static Date valueOf(String s) { - s = s.trim(); + //To compatible with non-breaking space and full-width space + s = s.trim().replace("\u00A0", " ").replace("\u3000", " "); int idx = s.indexOf(" "); if (idx != -1) { s = s.substring(0, idx); diff --git common/src/test/org/apache/hive/common/util/TestDateParser.java common/src/test/org/apache/hive/common/util/TestDateParser.java index 8c3a7a4fee..8cf1be3170 100644 --- common/src/test/org/apache/hive/common/util/TestDateParser.java +++ common/src/test/org/apache/hive/common/util/TestDateParser.java @@ -53,6 +53,11 @@ public void testValidCases() throws Exception { // Timestamp strings should parse ok checkValidCase("2001-11-12 01:02:03", Date.valueOf("2001-11-12")); + // Test compatible with non-breaking space and full-width space + checkValidCase("2021-01-01"+"\u00A0"+"00:00:00", Date.valueOf("2021-01-01")); + checkValidCase("2021-01-02"+"\u3000"+"00:00:00", Date.valueOf("2021-01-02")); + + // Leading spaces checkValidCase(" 1946-01-01", Date.valueOf("1946-01-01")); checkValidCase(" 2001-11-12 01:02:03", Date.valueOf("2001-11-12"));