Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions go/arrow/datatype_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 20 additions & 10 deletions go/arrow/datatype_fixedwidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand All @@ -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 }
Expand All @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions go/arrow/datatype_nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package arrow
import (
"fmt"
"reflect"
"strings"
)

// ListType describes a nested type in which each array slot contains
Expand All @@ -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 }
Expand Down Expand Up @@ -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] }

Expand Down
5 changes: 3 additions & 2 deletions go/arrow/datatype_null.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 48 additions & 36 deletions go/arrow/datatype_numeric.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions go/arrow/datatype_numeric.gen.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion go/arrow/ipc/cmd/arrow-ls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down