zeroshade commented on code in PR #43679:
URL: https://github.com/apache/arrow/pull/43679#discussion_r1718683271


##########
go/parquet/pqarrow/schema.go:
##########
@@ -611,6 +515,85 @@ func arrowFromFLBA(logical schema.LogicalType, length int) 
(arrow.DataType, erro
        }
 }
 
+func getParquetType(typ arrow.DataType, props *parquet.WriterProperties, 
arrprops ArrowWriterProperties) (parquet.Type, schema.LogicalType, int, error) {
+       switch typ.ID() {
+       case arrow.NULL:
+               return parquet.Types.Int32, schema.NullLogicalType{}, -1, nil
+       case arrow.BOOL:
+               return parquet.Types.Boolean, schema.NoLogicalType{}, -1, nil
+       case arrow.UINT8:
+               return parquet.Types.Int32, schema.NewIntLogicalType(8, false), 
-1, nil
+       case arrow.INT8:
+               return parquet.Types.Int32, schema.NewIntLogicalType(8, true), 
-1, nil
+       case arrow.UINT16:
+               return parquet.Types.Int32, schema.NewIntLogicalType(16, 
false), -1, nil
+       case arrow.INT16:
+               return parquet.Types.Int32, schema.NewIntLogicalType(16, true), 
-1, nil
+       case arrow.UINT32:
+               return parquet.Types.Int32, schema.NewIntLogicalType(32, 
false), -1, nil
+       case arrow.INT32:
+               return parquet.Types.Int32, schema.NewIntLogicalType(32, true), 
-1, nil
+       case arrow.UINT64:
+               return parquet.Types.Int64, schema.NewIntLogicalType(64, 
false), -1, nil
+       case arrow.INT64:
+               return parquet.Types.Int64, schema.NewIntLogicalType(64, true), 
-1, nil
+       case arrow.FLOAT32:
+               return parquet.Types.Float, schema.NoLogicalType{}, -1, nil
+       case arrow.FLOAT64:
+               return parquet.Types.Double, schema.NoLogicalType{}, -1, nil
+       case arrow.STRING, arrow.LARGE_STRING:
+               return parquet.Types.ByteArray, schema.StringLogicalType{}, -1, 
nil
+       case arrow.BINARY, arrow.LARGE_BINARY:
+               return parquet.Types.ByteArray, schema.NoLogicalType{}, -1, nil
+       case arrow.FIXED_SIZE_BINARY:
+               return parquet.Types.FixedLenByteArray, schema.NoLogicalType{}, 
typ.(*arrow.FixedSizeBinaryType).ByteWidth, nil
+       case arrow.DECIMAL, arrow.DECIMAL256:
+               dectype := typ.(arrow.DecimalType)
+               precision := int(dectype.GetPrecision())
+               scale := int(dectype.GetScale())
+
+               if !props.StoreDecimalAsInteger() || precision > 18 {
+                       return parquet.Types.FixedLenByteArray, 
schema.NewDecimalLogicalType(int32(precision), int32(scale)), 
int(DecimalSize(int32(precision))), nil
+               }
+
+               pqType := parquet.Types.Int32
+               if precision > 9 {
+                       pqType = parquet.Types.Int64
+               }
+
+               return pqType, schema.NoLogicalType{}, -1, nil
+       case arrow.DATE32:
+               return parquet.Types.Int32, schema.DateLogicalType{}, -1, nil
+       case arrow.DATE64:
+               return parquet.Types.Int32, schema.DateLogicalType{}, -1, nil
+       case arrow.TIMESTAMP:
+               pqType, logicalType, err := 
getTimestampMeta(typ.(*arrow.TimestampType), props, arrprops)
+               return pqType, logicalType, -1, err
+       case arrow.TIME32:
+               return parquet.Types.Int32, schema.NewTimeLogicalType(true, 
schema.TimeUnitMillis), -1, nil
+       case arrow.TIME64:
+               pqTimeUnit := schema.TimeUnitMicros
+               if typ.(*arrow.Time64Type).Unit == arrow.Nanosecond {
+                       pqTimeUnit = schema.TimeUnitNanos
+               }
+
+               return parquet.Types.Int64, schema.NewTimeLogicalType(true, 
pqTimeUnit), -1, nil
+       case arrow.FLOAT16:
+               return parquet.Types.FixedLenByteArray, 
schema.Float16LogicalType{}, arrow.Float16SizeBytes, nil
+       case arrow.EXTENSION:
+               storageType := typ.(arrow.ExtensionType).StorageType()
+               pqType, logicalType, length, err := getParquetType(storageType, 
props, arrprops)
+               withCustomType, ok := typ.(extensions.CustomParquetType)
+               if ok {
+                       logicalType = withCustomType.ParquetLogicalType()
+               }

Review Comment:
   condense this
   
   ```go
   if withCustomType, ok := typ.(CustomParquetType); ok {
        logicalType = withCustomType.ParquetLogicalType()
   }
   ```
   
   and the `CustomParquetType` interface can be defined in here rather than in 
the Arrow lib



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