HyukjinKwon commented on code in PR #47253:
URL: https://github.com/apache/arrow/pull/47253#discussion_r2667849420


##########
python/pyarrow/parquet/core.py:
##########
@@ -90,6 +90,69 @@ def _check_filters(filters, check_null_strings=True):
     return filters
 
 
+def _map_spark_to_arrow_types(datatype: pa.DataType) -> str | None:
+    lookup = {
+        "NA": "null",
+        "BOOL": "boolean",
+        "INT8": "byte",
+        "INT16": "short",
+        **dict.fromkeys(
+            ["UINT8", "UINT16", "UINT32", "UINT64", "INT32"], "integer"),
+        "INT64": "long",
+        **dict.fromkeys(["HALF_FLOAT", "FLOAT"], "float"),
+        "DOUBLE": "double",
+        "BINARY": "binary",
+        "STRING": "string",
+        **dict.fromkeys(
+            ["DECIMAL" + str(2 ** i) for i in range(5, 9)], "decimal"),
+        **dict.fromkeys(
+            ["LIST", "LARGE_LIST", "LIST_VIEW", "LARGE_LIST_VIEW", 
"FIXED_SIZE_LIST"],
+            "array",
+        ),
+        "MAP": "map",
+        **dict.fromkeys(["DATE32", "DATE64"], "date"),
+        "TIMESTAMP": "timestamp",
+        "INTERVAL_MONTH_DAY_NANO": "Calendar Interval",  # TODO: Correct this
+    }
+
+    str_value = pa.types.TypesEnum(datatype.id).name
+
+    try:
+        return lookup[str_value]
+    except KeyError:
+        return None
+
+
+def _substitute_spark_metadata(schema: pa.Schema) -> dict:
+    metadata = schema.metadata
+    spark_key = b"org.apache.spark.sql.parquet.row.metadata"
+
+    try:
+        spark_row_metadata = json.loads(
+            schema.metadata.pop(spark_key, None))
+    except (TypeError, json.JSONDecodeError):  # Could not convert Spark's row 
metadata
+        return metadata
+
+    spark_fields = [field["name"] for field in spark_row_metadata["fields"]]
+
+    for name in schema.names:
+        field = schema.field(name)
+
+        if name in spark_fields:
+            continue
+
+        spark_row_metadata["fields"].append({
+            "name": field.name,
+            "type": _map_spark_to_arrow_types(field.type),

Review Comment:
   And seem like we're missing nested types like struct type and array/map



##########
python/pyarrow/parquet/core.py:
##########
@@ -90,6 +90,69 @@ def _check_filters(filters, check_null_strings=True):
     return filters
 
 
+def _map_spark_to_arrow_types(datatype: pa.DataType) -> str | None:
+    lookup = {
+        "NA": "null",
+        "BOOL": "boolean",
+        "INT8": "byte",
+        "INT16": "short",
+        **dict.fromkeys(
+            ["UINT8", "UINT16", "UINT32", "UINT64", "INT32"], "integer"),
+        "INT64": "long",
+        **dict.fromkeys(["HALF_FLOAT", "FLOAT"], "float"),
+        "DOUBLE": "double",
+        "BINARY": "binary",
+        "STRING": "string",
+        **dict.fromkeys(
+            ["DECIMAL" + str(2 ** i) for i in range(5, 9)], "decimal"),

Review Comment:
   and decimal precision



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to