paleolimbot commented on code in PR #1138:
URL: https://github.com/apache/iceberg-go/pull/1138#discussion_r3396456251


##########
table/arrow_utils.go:
##########
@@ -1828,3 +1848,154 @@ func positionDeleteRecordsToDataFilesDV(ctx 
context.Context, rootLocation string
                }
        }
 }
+
+func checkCRSString(rawCrs json.RawMessage) bool {
+       b := bytes.TrimSpace(rawCrs)
+
+       return len(b) > 0 && b[0] == '"'
+}
+
+func checkCRSSJSON(rawCrs json.RawMessage) bool {
+       b := bytes.TrimSpace(rawCrs)
+
+       return len(b) > 0 && b[0] == '{'
+}
+
+func geoArrowCRSToIcebergCRS(meta geoarrow.Metadata) (string, error) {
+       if len(meta.CRS) == 0 {
+               return "srid:0", nil
+       }
+
+       switch {
+       case checkCRSString(meta.CRS):
+               var crs string
+               if len(meta.CRS) > 0 {
+                       if err := json.Unmarshal(meta.CRS, &crs); err != nil {
+                               return "", fmt.Errorf("invalid geoarrow CRS 
metadata: %w", err)
+                       }
+               }
+
+               if strings.EqualFold(crs, "OGC:CRS84") || 
strings.EqualFold(crs, "EPSG:4326") {
+                       return "OGC:CRS84", nil
+               }
+
+               switch meta.CRSType {
+               case geoarrow.CRSTypeSRID:
+                       return "srid:" + crs, nil
+               case geoarrow.CRSTypePROJJSON:
+                       return "", errors.New("JSON object written to crs as 
string")

Review Comment:
   This could be me misinterpreting what the Go code is doing here...I didn't 
spot an error in the tests, I just wanted to make sure that if somebody 
specified `{"crs": {...}, "crs_type": "projjson"}` they would get the same 
thing as specifying `{"crs": {...}}`.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to