zeroshade commented on code in PR #960:
URL: https://github.com/apache/arrow-go/pull/960#discussion_r3615902333
##########
parquet/schema/logical_types.go:
##########
@@ -1228,3 +1247,242 @@ func (NoLogicalType) Equals(rhs LogicalType) bool {
}
func (NoLogicalType) IsNone() bool { return true }
+
+// GeometryLogicalType represents geospatial features in WKB format.
+type GeometryLogicalType struct {
+ baseLogicalType
+ // Crs optionally identifies the coordinate reference system. If empty,
+ // it defaults to OGC:CRS84.
+ Crs string
+}
+
+func geometryLogicalTypeFromThrift(t *format.GeometryType) GeometryLogicalType
{
+ if t == nil || !t.IsSetCrs() {
+ return GeometryLogicalType{}
+ }
+ return GeometryLogicalType{Crs: t.GetCrs()}
+}
+
+// CRS returns the coordinate reference system, or OGC:CRS84 when unset.
+func (t GeometryLogicalType) CRS() string {
+ if !t.IsCRSSet() {
+ return defaultGeospatialCRS
+ }
+ return t.Crs
+}
+
+// IsCRSSet returns whether the coordinate reference system was explicitly set.
+func (t GeometryLogicalType) IsCRSSet() bool {
+ return t.Crs != ""
+}
+
+func (t GeometryLogicalType) Equals(rhs LogicalType) bool {
+ other, ok := rhs.(GeometryLogicalType)
+ return ok && t.Crs == other.Crs
+}
+
+func (GeometryLogicalType) IsCompatible(c ConvertedType, dec DecimalMetadata)
bool {
+ if dec.IsSet {
+ return false
+ }
+ switch c {
+ case ConvertedTypes.None, ConvertedTypes.NA:
+ return true
+ }
+ return false
+}
+
+func (t GeometryLogicalType) MarshalJSON() ([]byte, error) {
+ values := map[string]interface{}{"Type": "Geometry"}
+ if t.IsCRSSet() {
+ values["crs"] = t.CRS()
+ }
+ return json.Marshal(values)
+}
+
+func (t GeometryLogicalType) String() string {
+ if t.IsCRSSet() {
+ return fmt.Sprintf("Geometry(crs=%s)", t.CRS())
+ }
+ return "Geometry"
+}
+
+func (GeometryLogicalType) SortOrder() SortOrder {
+ return SortUNKNOWN
+}
+
+func (GeometryLogicalType) ToConvertedType() (ConvertedType, DecimalMetadata) {
+ return ConvertedTypes.None, DecimalMetadata{}
+}
+
+func (GeometryLogicalType) IsApplicable(t parquet.Type, _ int32) bool {
+ return t == parquet.Types.ByteArray
+}
+
+func (t GeometryLogicalType) toThrift() *format.LogicalType {
+ typ := format.NewGeometryType()
+ if t.IsCRSSet() {
+ typ.Crs = thrift.StringPtr(t.Crs)
+ }
+ return &format.LogicalType{GEOMETRY: typ}
+}
+
+// GeographyLogicalType represents geospatial features in WKB format with a
+// non-linear edge interpolation algorithm.
+type GeographyLogicalType struct {
+ baseLogicalType
+ // Crs optionally identifies the coordinate reference system. If empty,
+ // it defaults to OGC:CRS84.
+ Crs string
+ // Algorithm optionally identifies the edge interpolation algorithm. If
+ // empty, it defaults to spherical.
+ Algorithm GeographyEdgeInterpolationAlgorithm
+}
+
+func geographyLogicalTypeFromThrift(t *format.GeographyType)
GeographyLogicalType {
+ if t == nil {
+ return GeographyLogicalType{}
+ }
+
+ ret := GeographyLogicalType{}
+ if t.IsSetCrs() {
+ ret.Crs = t.GetCrs()
+ }
+ if t.IsSetAlgorithm() {
+ ret.Algorithm =
GeographyEdgeInterpolationAlgorithm("").fromThrift(t.GetAlgorithm())
Review Comment:
If you make the `fromThrift` method a pointer receiver, then you could do
this:
```suggestion
ret.Algorithm.fromThrift(t.GetAlgorithm())
```
Alternately, it could still be a value receiver and just do
```suggestion
ret.Algorithm = ret.Algorithm.fromThrift(t.GetAlgorithm())
```
either way, it lets you avoid an allocation
##########
parquet/schema/logical_types.go:
##########
@@ -1228,3 +1247,242 @@ func (NoLogicalType) Equals(rhs LogicalType) bool {
}
func (NoLogicalType) IsNone() bool { return true }
+
+// GeometryLogicalType represents geospatial features in WKB format.
+type GeometryLogicalType struct {
+ baseLogicalType
+ // Crs optionally identifies the coordinate reference system. If empty,
+ // it defaults to OGC:CRS84.
+ Crs string
+}
+
+func geometryLogicalTypeFromThrift(t *format.GeometryType) GeometryLogicalType
{
+ if t == nil || !t.IsSetCrs() {
+ return GeometryLogicalType{}
+ }
+ return GeometryLogicalType{Crs: t.GetCrs()}
+}
+
+// CRS returns the coordinate reference system, or OGC:CRS84 when unset.
+func (t GeometryLogicalType) CRS() string {
+ if !t.IsCRSSet() {
+ return defaultGeospatialCRS
+ }
+ return t.Crs
+}
+
+// IsCRSSet returns whether the coordinate reference system was explicitly set.
+func (t GeometryLogicalType) IsCRSSet() bool {
+ return t.Crs != ""
+}
+
+func (t GeometryLogicalType) Equals(rhs LogicalType) bool {
+ other, ok := rhs.(GeometryLogicalType)
+ return ok && t.Crs == other.Crs
+}
+
+func (GeometryLogicalType) IsCompatible(c ConvertedType, dec DecimalMetadata)
bool {
+ if dec.IsSet {
+ return false
+ }
+ switch c {
+ case ConvertedTypes.None, ConvertedTypes.NA:
+ return true
+ }
+ return false
+}
+
+func (t GeometryLogicalType) MarshalJSON() ([]byte, error) {
+ values := map[string]interface{}{"Type": "Geometry"}
+ if t.IsCRSSet() {
+ values["crs"] = t.CRS()
+ }
+ return json.Marshal(values)
+}
+
+func (t GeometryLogicalType) String() string {
+ if t.IsCRSSet() {
+ return fmt.Sprintf("Geometry(crs=%s)", t.CRS())
+ }
+ return "Geometry"
+}
+
+func (GeometryLogicalType) SortOrder() SortOrder {
+ return SortUNKNOWN
+}
+
+func (GeometryLogicalType) ToConvertedType() (ConvertedType, DecimalMetadata) {
+ return ConvertedTypes.None, DecimalMetadata{}
+}
+
+func (GeometryLogicalType) IsApplicable(t parquet.Type, _ int32) bool {
+ return t == parquet.Types.ByteArray
+}
+
+func (t GeometryLogicalType) toThrift() *format.LogicalType {
+ typ := format.NewGeometryType()
+ if t.IsCRSSet() {
+ typ.Crs = thrift.StringPtr(t.Crs)
+ }
+ return &format.LogicalType{GEOMETRY: typ}
+}
+
+// GeographyLogicalType represents geospatial features in WKB format with a
+// non-linear edge interpolation algorithm.
+type GeographyLogicalType struct {
+ baseLogicalType
+ // Crs optionally identifies the coordinate reference system. If empty,
+ // it defaults to OGC:CRS84.
+ Crs string
+ // Algorithm optionally identifies the edge interpolation algorithm. If
+ // empty, it defaults to spherical.
+ Algorithm GeographyEdgeInterpolationAlgorithm
+}
+
+func geographyLogicalTypeFromThrift(t *format.GeographyType)
GeographyLogicalType {
+ if t == nil {
+ return GeographyLogicalType{}
+ }
+
+ ret := GeographyLogicalType{}
+ if t.IsSetCrs() {
+ ret.Crs = t.GetCrs()
+ }
+ if t.IsSetAlgorithm() {
+ ret.Algorithm =
GeographyEdgeInterpolationAlgorithm("").fromThrift(t.GetAlgorithm())
+ }
+ return ret
+}
+
+// CRS returns the coordinate reference system, or OGC:CRS84 when unset.
+func (t GeographyLogicalType) CRS() string {
+ if !t.IsCRSSet() {
+ return defaultGeospatialCRS
+ }
+ return t.Crs
+}
+
+// IsCRSSet returns whether the coordinate reference system was explicitly set.
+func (t GeographyLogicalType) IsCRSSet() bool {
+ return t.Crs != ""
+}
+
+// EdgeInterpolationAlgorithm returns the edge interpolation algorithm. If
+// unset, it returns GeographyEdgeSpherical.
+func (t GeographyLogicalType) EdgeInterpolationAlgorithm()
GeographyEdgeInterpolationAlgorithm {
+ if !t.IsEdgeInterpolationAlgorithmSet() {
+ return GeographyEdgeSpherical
+ }
+ return t.Algorithm
+}
+
+// IsEdgeInterpolationAlgorithmSet returns whether the edge interpolation
+// algorithm was explicitly set.
+func (t GeographyLogicalType) IsEdgeInterpolationAlgorithmSet() bool {
+ return t.Algorithm != ""
+}
+
+func (t GeographyLogicalType) Equals(rhs LogicalType) bool {
+ other, ok := rhs.(GeographyLogicalType)
+ return ok && t.Crs == other.Crs && t.Algorithm == other.Algorithm
+}
+
+func (GeographyLogicalType) IsCompatible(c ConvertedType, dec DecimalMetadata)
bool {
+ if dec.IsSet {
+ return false
+ }
+ switch c {
+ case ConvertedTypes.None, ConvertedTypes.NA:
+ return true
+ }
+ return false
+}
+
+func (t GeographyLogicalType) MarshalJSON() ([]byte, error) {
+ values := map[string]any{"Type": "Geography"}
+ if t.IsCRSSet() {
+ values["crs"] = t.CRS()
+ }
+ if t.IsEdgeInterpolationAlgorithmSet() {
+ values["algorithm"] = t.EdgeInterpolationAlgorithm().String()
+ }
+ return json.Marshal(values)
+}
+
+func (t GeographyLogicalType) String() string {
+ if !t.IsCRSSet() && !t.IsEdgeInterpolationAlgorithmSet() {
+ return "Geography"
+ }
+ return fmt.Sprintf("Geography(crs=%s, algorithm=%s)", t.CRS(),
t.EdgeInterpolationAlgorithm())
+}
+
+func (GeographyLogicalType) SortOrder() SortOrder {
+ return SortUNKNOWN
+}
+
+func (GeographyLogicalType) ToConvertedType() (ConvertedType, DecimalMetadata)
{
+ return ConvertedTypes.None, DecimalMetadata{}
+}
+
+func (GeographyLogicalType) IsApplicable(t parquet.Type, _ int32) bool {
+ return t == parquet.Types.ByteArray
+}
+
+func (t GeographyLogicalType) toThrift() *format.LogicalType {
+ typ := format.NewGeographyType()
+ if t.IsCRSSet() {
+ typ.Crs = thrift.StringPtr(t.Crs)
+ }
+ if t.IsEdgeInterpolationAlgorithmSet() {
+ alg := t.Algorithm.toThrift()
+ typ.Algorithm = &alg
+ }
+ return &format.LogicalType{GEOGRAPHY: typ}
+}
+
+func (GeographyEdgeInterpolationAlgorithm) fromThrift(alg
format.EdgeInterpolationAlgorithm) GeographyEdgeInterpolationAlgorithm {
+ switch alg {
+ case format.EdgeInterpolationAlgorithm_VINCENTY:
+ return GeographyEdgeVincenty
+ case format.EdgeInterpolationAlgorithm_THOMAS:
+ return GeographyEdgeThomas
+ case format.EdgeInterpolationAlgorithm_ANDOYER:
+ return GeographyEdgeAndoyer
+ case format.EdgeInterpolationAlgorithm_KARNEY:
+ return GeographyEdgeKarney
+ case format.EdgeInterpolationAlgorithm_SPHERICAL:
+ fallthrough
+ default:
+ return GeographyEdgeSpherical
+ }
+}
Review Comment:
move this and the other methods closer to the type definition
--
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]