You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by sb...@apache.org on 2019/04/30 20:21:01 UTC
[arrow] branch master updated: ARROW-5174: [Go] implement Stringer
for DataTypes
This is an automated email from the ASF dual-hosted git repository.
sbinet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 8a41288 ARROW-5174: [Go] implement Stringer for DataTypes
8a41288 is described below
commit 8a41288a57bbd0a0ea974ce9bc3ab2f28b9bc62b
Author: Sebastien Binet <bi...@cern.ch>
AuthorDate: Tue Apr 30 22:20:45 2019 +0200
ARROW-5174: [Go] implement Stringer for DataTypes
Author: Sebastien Binet <bi...@cern.ch>
Closes #4161 from sbinet/issue-5174 and squashes the following commits:
54c92403 <Sebastien Binet> ARROW-5174: implement Stringer for DataTypes
---
go/arrow/datatype_binary.go | 14 +++---
go/arrow/datatype_fixedwidth.go | 30 ++++++++-----
go/arrow/datatype_nested.go | 19 +++++++-
go/arrow/datatype_null.go | 5 ++-
go/arrow/datatype_numeric.gen.go | 84 ++++++++++++++++++++---------------
go/arrow/datatype_numeric.gen.go.tmpl | 7 +--
go/arrow/ipc/cmd/arrow-ls/main.go | 2 +-
7 files changed, 101 insertions(+), 60 deletions(-)
diff --git a/go/arrow/datatype_binary.go b/go/arrow/datatype_binary.go
index 40ab860..4fc0162 100644
--- a/go/arrow/datatype_binary.go
+++ b/go/arrow/datatype_binary.go
@@ -18,15 +18,17 @@ package arrow
type BinaryType struct{}
-func (t *BinaryType) ID() Type { return BINARY }
-func (t *BinaryType) Name() string { return "binary" }
-func (t *BinaryType) binary() {}
+func (t *BinaryType) ID() Type { return BINARY }
+func (t *BinaryType) Name() string { return "binary" }
+func (t *BinaryType) String() string { return "binary" }
+func (t *BinaryType) binary() {}
type StringType struct{}
-func (t *StringType) ID() Type { return STRING }
-func (t *StringType) Name() string { return "utf8" }
-func (t *StringType) binary() {}
+func (t *StringType) ID() Type { return STRING }
+func (t *StringType) Name() string { return "utf8" }
+func (t *StringType) String() string { return "utf8" }
+func (t *StringType) binary() {}
var (
BinaryTypes = struct {
diff --git a/go/arrow/datatype_fixedwidth.go b/go/arrow/datatype_fixedwidth.go
index 4444950..ae46610 100644
--- a/go/arrow/datatype_fixedwidth.go
+++ b/go/arrow/datatype_fixedwidth.go
@@ -16,10 +16,13 @@
package arrow
+import "strconv"
+
type BooleanType struct{}
-func (t *BooleanType) ID() Type { return BOOL }
-func (t *BooleanType) Name() string { return "bool" }
+func (t *BooleanType) ID() Type { return BOOL }
+func (t *BooleanType) Name() string { return "bool" }
+func (t *BooleanType) String() string { return "bool" }
// BitWidth returns the number of bits required to store a single element of this data type in memory.
func (t *BooleanType) BitWidth() int { return 1 }
@@ -32,6 +35,10 @@ func (*FixedSizeBinaryType) ID() Type { return FIXED_SIZE_BINARY }
func (*FixedSizeBinaryType) Name() string { return "fixed_size_binary" }
func (t *FixedSizeBinaryType) BitWidth() int { return 8 * t.ByteWidth }
+func (t *FixedSizeBinaryType) String() string {
+ return "fixed_size_binary[" + strconv.Itoa(t.ByteWidth) + "]"
+}
+
type (
Timestamp int64
Time32 int32
@@ -58,8 +65,9 @@ type TimestampType struct {
TimeZone string
}
-func (*TimestampType) ID() Type { return TIMESTAMP }
-func (*TimestampType) Name() string { return "timestamp" }
+func (*TimestampType) ID() Type { return TIMESTAMP }
+func (*TimestampType) Name() string { return "timestamp" }
+func (t *TimestampType) String() string { return "timestamp[" + t.Unit.String() + "]" }
// BitWidth returns the number of bits required to store a single element of this data type in memory.
func (*TimestampType) BitWidth() int { return 64 }
@@ -69,18 +77,20 @@ type Time32Type struct {
Unit TimeUnit
}
-func (*Time32Type) ID() Type { return TIME32 }
-func (*Time32Type) Name() string { return "time32" }
-func (*Time32Type) BitWidth() int { return 32 }
+func (*Time32Type) ID() Type { return TIME32 }
+func (*Time32Type) Name() string { return "time32" }
+func (*Time32Type) BitWidth() int { return 32 }
+func (t *Time32Type) String() string { return "time32[" + t.Unit.String() + "]" }
// Time64Type is encoded as a 64-bit signed integer, representing either microseconds or nanoseconds since midnight.
type Time64Type struct {
Unit TimeUnit
}
-func (*Time64Type) ID() Type { return TIME64 }
-func (*Time64Type) Name() string { return "time64" }
-func (*Time64Type) BitWidth() int { return 64 }
+func (*Time64Type) ID() Type { return TIME64 }
+func (*Time64Type) Name() string { return "time64" }
+func (*Time64Type) BitWidth() int { return 64 }
+func (t *Time64Type) String() string { return "time64[" + t.Unit.String() + "]" }
var (
FixedWidthTypes = struct {
diff --git a/go/arrow/datatype_nested.go b/go/arrow/datatype_nested.go
index 1c9b693..59a198f 100644
--- a/go/arrow/datatype_nested.go
+++ b/go/arrow/datatype_nested.go
@@ -19,6 +19,7 @@ package arrow
import (
"fmt"
"reflect"
+ "strings"
)
// ListType describes a nested type in which each array slot contains
@@ -38,8 +39,9 @@ func ListOf(t DataType) *ListType {
return &ListType{elem: t}
}
-func (*ListType) ID() Type { return LIST }
-func (*ListType) Name() string { return "list" }
+func (*ListType) ID() Type { return LIST }
+func (*ListType) Name() string { return "list" }
+func (t *ListType) String() string { return fmt.Sprintf("list<item: %v>", t.elem) }
// Elem returns the ListType's element type.
func (t *ListType) Elem() DataType { return t.elem }
@@ -88,6 +90,19 @@ func StructOf(fs ...Field) *StructType {
func (*StructType) ID() Type { return STRUCT }
func (*StructType) Name() string { return "struct" }
+func (t *StructType) String() string {
+ o := new(strings.Builder)
+ o.WriteString("struct<")
+ for i, f := range t.fields {
+ if i > 0 {
+ o.WriteString(", ")
+ }
+ o.WriteString(fmt.Sprintf("%s: %v", f.Name, f.Type))
+ }
+ o.WriteString(">")
+ return o.String()
+}
+
func (t *StructType) Fields() []Field { return t.fields }
func (t *StructType) Field(i int) Field { return t.fields[i] }
diff --git a/go/arrow/datatype_null.go b/go/arrow/datatype_null.go
index 7f0d8bf..5882dfe 100644
--- a/go/arrow/datatype_null.go
+++ b/go/arrow/datatype_null.go
@@ -19,8 +19,9 @@ package arrow
// NullType describes a degenerate array, with zero physical storage.
type NullType struct{}
-func (*NullType) ID() Type { return NULL }
-func (*NullType) Name() string { return "null" }
+func (*NullType) ID() Type { return NULL }
+func (*NullType) Name() string { return "null" }
+func (*NullType) String() string { return "null" }
var (
Null *NullType
diff --git a/go/arrow/datatype_numeric.gen.go b/go/arrow/datatype_numeric.gen.go
index 9b5dc83..d5b34d7 100644
--- a/go/arrow/datatype_numeric.gen.go
+++ b/go/arrow/datatype_numeric.gen.go
@@ -20,75 +20,87 @@ package arrow
type Int8Type struct{}
-func (t *Int8Type) ID() Type { return INT8 }
-func (t *Int8Type) Name() string { return "int8" }
-func (t *Int8Type) BitWidth() int { return 8 }
+func (t *Int8Type) ID() Type { return INT8 }
+func (t *Int8Type) Name() string { return "int8" }
+func (t *Int8Type) String() string { return "int8" }
+func (t *Int8Type) BitWidth() int { return 8 }
type Int16Type struct{}
-func (t *Int16Type) ID() Type { return INT16 }
-func (t *Int16Type) Name() string { return "int16" }
-func (t *Int16Type) BitWidth() int { return 16 }
+func (t *Int16Type) ID() Type { return INT16 }
+func (t *Int16Type) Name() string { return "int16" }
+func (t *Int16Type) String() string { return "int16" }
+func (t *Int16Type) BitWidth() int { return 16 }
type Int32Type struct{}
-func (t *Int32Type) ID() Type { return INT32 }
-func (t *Int32Type) Name() string { return "int32" }
-func (t *Int32Type) BitWidth() int { return 32 }
+func (t *Int32Type) ID() Type { return INT32 }
+func (t *Int32Type) Name() string { return "int32" }
+func (t *Int32Type) String() string { return "int32" }
+func (t *Int32Type) BitWidth() int { return 32 }
type Int64Type struct{}
-func (t *Int64Type) ID() Type { return INT64 }
-func (t *Int64Type) Name() string { return "int64" }
-func (t *Int64Type) BitWidth() int { return 64 }
+func (t *Int64Type) ID() Type { return INT64 }
+func (t *Int64Type) Name() string { return "int64" }
+func (t *Int64Type) String() string { return "int64" }
+func (t *Int64Type) BitWidth() int { return 64 }
type Uint8Type struct{}
-func (t *Uint8Type) ID() Type { return UINT8 }
-func (t *Uint8Type) Name() string { return "uint8" }
-func (t *Uint8Type) BitWidth() int { return 8 }
+func (t *Uint8Type) ID() Type { return UINT8 }
+func (t *Uint8Type) Name() string { return "uint8" }
+func (t *Uint8Type) String() string { return "uint8" }
+func (t *Uint8Type) BitWidth() int { return 8 }
type Uint16Type struct{}
-func (t *Uint16Type) ID() Type { return UINT16 }
-func (t *Uint16Type) Name() string { return "uint16" }
-func (t *Uint16Type) BitWidth() int { return 16 }
+func (t *Uint16Type) ID() Type { return UINT16 }
+func (t *Uint16Type) Name() string { return "uint16" }
+func (t *Uint16Type) String() string { return "uint16" }
+func (t *Uint16Type) BitWidth() int { return 16 }
type Uint32Type struct{}
-func (t *Uint32Type) ID() Type { return UINT32 }
-func (t *Uint32Type) Name() string { return "uint32" }
-func (t *Uint32Type) BitWidth() int { return 32 }
+func (t *Uint32Type) ID() Type { return UINT32 }
+func (t *Uint32Type) Name() string { return "uint32" }
+func (t *Uint32Type) String() string { return "uint32" }
+func (t *Uint32Type) BitWidth() int { return 32 }
type Uint64Type struct{}
-func (t *Uint64Type) ID() Type { return UINT64 }
-func (t *Uint64Type) Name() string { return "uint64" }
-func (t *Uint64Type) BitWidth() int { return 64 }
+func (t *Uint64Type) ID() Type { return UINT64 }
+func (t *Uint64Type) Name() string { return "uint64" }
+func (t *Uint64Type) String() string { return "uint64" }
+func (t *Uint64Type) BitWidth() int { return 64 }
type Float32Type struct{}
-func (t *Float32Type) ID() Type { return FLOAT32 }
-func (t *Float32Type) Name() string { return "float32" }
-func (t *Float32Type) BitWidth() int { return 32 }
+func (t *Float32Type) ID() Type { return FLOAT32 }
+func (t *Float32Type) Name() string { return "float32" }
+func (t *Float32Type) String() string { return "float32" }
+func (t *Float32Type) BitWidth() int { return 32 }
type Float64Type struct{}
-func (t *Float64Type) ID() Type { return FLOAT64 }
-func (t *Float64Type) Name() string { return "float64" }
-func (t *Float64Type) BitWidth() int { return 64 }
+func (t *Float64Type) ID() Type { return FLOAT64 }
+func (t *Float64Type) Name() string { return "float64" }
+func (t *Float64Type) String() string { return "float64" }
+func (t *Float64Type) BitWidth() int { return 64 }
type Date32Type struct{}
-func (t *Date32Type) ID() Type { return DATE32 }
-func (t *Date32Type) Name() string { return "date32" }
-func (t *Date32Type) BitWidth() int { return 32 }
+func (t *Date32Type) ID() Type { return DATE32 }
+func (t *Date32Type) Name() string { return "date32" }
+func (t *Date32Type) String() string { return "date32" }
+func (t *Date32Type) BitWidth() int { return 32 }
type Date64Type struct{}
-func (t *Date64Type) ID() Type { return DATE64 }
-func (t *Date64Type) Name() string { return "date64" }
-func (t *Date64Type) BitWidth() int { return 64 }
+func (t *Date64Type) ID() Type { return DATE64 }
+func (t *Date64Type) Name() string { return "date64" }
+func (t *Date64Type) String() string { return "date64" }
+func (t *Date64Type) BitWidth() int { return 64 }
var (
PrimitiveTypes = struct {
diff --git a/go/arrow/datatype_numeric.gen.go.tmpl b/go/arrow/datatype_numeric.gen.go.tmpl
index 9458964..193cf09 100644
--- a/go/arrow/datatype_numeric.gen.go.tmpl
+++ b/go/arrow/datatype_numeric.gen.go.tmpl
@@ -19,9 +19,10 @@ package arrow
{{range .In}}
type {{.Name}}Type struct {}
-func (t *{{.Name}}Type) ID() Type { return {{.Name|upper}} }
-func (t *{{.Name}}Type) Name() string { return "{{.Name|lower}}" }
-func (t *{{.Name}}Type) BitWidth() int { return {{.Size}} }
+func (t *{{.Name}}Type) ID() Type { return {{.Name|upper}} }
+func (t *{{.Name}}Type) Name() string { return "{{.Name|lower}}" }
+func (t *{{.Name}}Type) String() string { return "{{.Name|lower}}" }
+func (t *{{.Name}}Type) BitWidth() int { return {{.Size}} }
{{end}}
diff --git a/go/arrow/ipc/cmd/arrow-ls/main.go b/go/arrow/ipc/cmd/arrow-ls/main.go
index cf9a765..59e21f9 100644
--- a/go/arrow/ipc/cmd/arrow-ls/main.go
+++ b/go/arrow/ipc/cmd/arrow-ls/main.go
@@ -176,7 +176,7 @@ func displayField(o io.Writer, field arrow.Field, inc int) {
if field.Nullable {
nullable = ", nullable"
}
- fmt.Fprintf(o, "%*.s- %s: type=%v%v\n", inc, "", field.Name, field.Type.Name(), nullable)
+ fmt.Fprintf(o, "%*.s- %s: type=%v%v\n", inc, "", field.Name, field.Type, nullable)
if field.HasMetadata() {
fmt.Fprintf(o, "%*.smetadata: %v\n", inc, "", field.Metadata)
}