Repository: apache/gravitino (Java)

Issue:
[Improvement] Add support for VarcharType and CharType partition values in SparkPartitionUtils.getSparkPartitionValue
### What would you like to be improved?

Add support for VarcharType and CharType partition values in spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/SparkPartitionUtils.java

Here a test to help:
```
  @Test
  void testGetSparkPartitionValueVarcharAndChar() {
    Assertions.assertEquals(
        UTF8String.fromString("abc"),
        SparkPartitionUtils.getSparkPartitionValue("abc", VarcharType.apply(5)));
    Assertions.assertEquals(
        UTF8String.fromString("xy"),
        SparkPartitionUtils.getSparkPartitionValue("xy", CharType.apply(2)));
  }
```

### How should we improve?

_No response_


Discussion:
@justinmclean Hi, Could I work on this issue?
Yes, it's all yours.



Patch:
diff --git a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/SparkPartitionUtils.java b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/SparkPartitionUtils.java
index a8e88b6b188..2c5689292ec 100644
--- a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/SparkPartitionUtils.java
+++ b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/SparkPartitionUtils.java
@@ -148,6 +148,10 @@ public static Object getSparkPartitionValue(String hivePartitionValue, DataType
         return Float.parseFloat(hivePartitionValue);
       } else if (dataType instanceof DecimalType) {
         return Decimal.apply(hivePartitionValue);
+      } else if (dataType instanceof VarcharType) {
+        return UTF8String.fromString(hivePartitionValue);
+      } else if (dataType instanceof CharType) {
+        return UTF8String.fromString(hivePartitionValue);
       } else {
         throw new UnsupportedOperationException("Unsupported partition type: " + dataType);
       }


Test patch:
diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/utils/TestSparkPartitionUtils.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/utils/TestSparkPartitionUtils.java
index 1b9737b844a..370c72f33a7 100644
--- a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/utils/TestSparkPartitionUtils.java
+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/utils/TestSparkPartitionUtils.java
@@ -22,13 +22,16 @@
 import java.time.LocalDate;
 import org.apache.gravitino.rel.expressions.literals.Literal;
 import org.apache.gravitino.rel.expressions.literals.Literals;
+import org.apache.gravitino.rel.types.Types;
 import org.apache.spark.sql.catalyst.InternalRow;
 import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
+import org.apache.spark.sql.types.CharType;
 import org.apache.spark.sql.types.DataType;
 import org.apache.spark.sql.types.DataTypes;
 import org.apache.spark.sql.types.Metadata;
 import org.apache.spark.sql.types.StructField;
 import org.apache.spark.sql.types.StructType;
+import org.apache.spark.sql.types.VarcharType;
 import org.apache.spark.unsafe.types.UTF8String;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
@@ -46,6 +49,8 @@ public class TestSparkPartitionUtils {
   float floatValue = 3.14f;
   double doubleValue = 3.1415926535;
   UTF8String stringValue = UTF8String.fromString("Hello World");
+  UTF8String varcharValue = UTF8String.fromString("abc");
+  UTF8String charValue = UTF8String.fromString("xy");
   int date = 0;
   private InternalRow internalRow =
       new GenericInternalRow(
@@ -58,7 +63,9 @@ public class TestSparkPartitionUtils {
             floatValue,
             doubleValue,
             stringValue,
-            date
+            date,
+            varcharValue,
+            charValue,
           });
   private Literal[] literals =
       new Literals.LiteralImpl[] {
@@ -71,6 +78,8 @@ public class TestSparkPartitionUtils {
         Literals.doubleLiteral(doubleValue),
         Literals.stringLiteral(stringValue.toString()),
         Literals.dateLiteral(LocalDate.of(1970, 1, 1)),
+        Literals.varcharLiteral(5, varcharValue.toString()),
+        Literals.of(charValue, Types.FixedCharType.of(2)),
       };
   private String[] hivePartitionValues = {
     "true",
@@ -81,7 +90,9 @@ public class TestSparkPartitionUtils {
     "3.14",
     "3.1415926535",
     "Hello World",
-    "1970-01-01"
+    "1970-01-01",
+    "abc",
+    "xy"
   };
   StructType schema =
       new StructType(
@@ -94,7 +105,9 @@ public class TestSparkPartitionUtils {
             new StructField("float", DataTypes.FloatType, false, Metadata.empty()),
             new StructField("double", DataTypes.DoubleType, false, Metadata.empty()),
             new StructField("string", DataTypes.StringType, false, Metadata.empty()),
-            new StructField("date", DataTypes.DateType, false, Metadata.empty())
+            new StructField("date", DataTypes.DateType, false, Metadata.empty()),
+            new StructField("varchar5", VarcharType.apply(5), false, Metadata.empty()),
+            new StructField("char2", CharType.apply(2), false, Metadata.empty()),
           });
 
   @Test