https://github.com/shellyln/go-graphdt
A datatable that represents object graphs for Go.
https://github.com/shellyln/go-graphdt
csv datatable datatables datatables-library go golang json library mapreduce object-graph query-engine
Last synced: 11 months ago
JSON representation
A datatable that represents object graphs for Go.
- Host: GitHub
- URL: https://github.com/shellyln/go-graphdt
- Owner: shellyln
- License: mit
- Created: 2023-04-22T04:31:02.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-07T09:01:06.000Z (almost 3 years ago)
- Last Synced: 2025-01-29T09:44:58.805Z (about 1 year ago)
- Topics: csv, datatable, datatables, datatables-library, go, golang, json, library, mapreduce, object-graph, query-engine
- Language: Go
- Homepage:
- Size: 720 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE.md
Awesome Lists containing this project
README
# GraphDT
A datatable that represents object graphs.
[](https://github.com/shellyln/go-graphdt/actions/workflows/test.yml)
[](https://github.com/shellyln/go-graphdt/releases)
[](https://github.com/shellyln/go-graphdt)

---
## ⭐️ Features
* Sort by multiple columns
* Filter by multiple columns and/or formulas that can include function calls
* Select multiple columns and/or formulas that can include scalar function calls
* Aggregate multiple columns and/or formulas that can include aggregation function calls
* Group by multiple columns
* Filter by aggregated values
* Simple iteration of rows
* Object graph based traversal for each row
* Create new data table from describe
* Import and export to CSV
* Import and export to JSON Lines
* Unmarshal to untyped objects
* Unmarshal to typed objects
## 🚀 Getting started
```go
package main
import (
"bytes"
"encoding/csv"
"fmt"
"github.com/shellyln/go-graphdt/datatable"
"github.com/shellyln/go-graphdt/datatable/runtime"
"github.com/shellyln/go-graphdt/datatable/types"
)
var csv1Bytes []byte
var csv2Bytes []byte
func main() {
csv1Bytes = []byte(`Foo,Bar,Baz
1,2,3`)
csv2Bytes = []byte(`Foo,Qux,Quux,Corge
1,1,2,3
1,11,12,13`)
ctx := runtime.NewRuntimeContext()
dt1 := datatable.NewDataTableWithSize(
ctx, 0, 0,
types.Type_Nullable_String,
types.Type_Nullable_I64,
types.Type_Nullable_F64,
)
dt1.SetSimpleHeader([]string{"Foo", "Bar", "Baz"})
dt2 := datatable.NewDataTableWithSize(
ctx, 0, 0,
types.Type_Nullable_String,
types.Type_Nullable_String,
types.Type_Nullable_I64,
types.Type_Nullable_F64,
)
dt2.SetSimpleHeader([]string{"Foo", "Qux", "Quux", "Corge"})
buf1 := bytes.NewReader(csv1Bytes)
reader1 := csv.NewReader(buf1)
if err := dt1.AppendFromCSV(reader1, datatable.CSVOptions{HasHeader: true}); err != nil {
fmt.Printf("error = %v\n", err)
return
}
err := dt1.Filter([]types.FilterInfo{
{Op: types.Op_LoadCol, Col: 1},
{Op: types.Op_LoadImmediate, Param: 63},
{Op: types.Op_Lt},
{Op: types.Op_LoadCol, Col: 1},
{Op: types.Op_LoadImmediate, Param: 64},
{Op: types.Op_Gt},
{Op: types.Op_Or},
}...)
if err != nil {
fmt.Printf("error = %v\n", err)
return
}
err = dt1.Sort([]types.SortInfo{
{Col: 0, Desc: false, NullsLast: true},
{Col: 2},
}...)
if err != nil {
fmt.Printf("error = %v\n", err)
return
}
buf2 := bytes.NewReader(csv2Bytes)
reader2 := csv.NewReader(buf2)
if err := dt2.AppendFromCSV(reader2, datatable.CSVOptions{HasHeader: true}); err != nil {
fmt.Printf("error = %v\n", err)
return
}
result, err := dt1.LeftJoin(0, dt2, 0, "quxes", datatable.JoinOptions{})
if err != nil {
fmt.Printf("error = %v\n", err)
return
}
fmt.Println(result.ColNames())
fmt.Println(result.ColSimpleNames())
values := make([]interface{}, result.ColLen())
result.ForEach(func(i int, row datatable.DataRow) bool {
fmt.Println(row.Values(values))
return false
})
result.ToUntyped(func(i int, record map[string]interface{}) bool {
fmt.Println(record)
return false
})
}
```
## 🚧 TODO
* Standard scalar / aggregation functions
* Data adapter interface
* Unit tests
* Documents
## ⚖️ License
MIT
Copyright (c) 2023 Shellyl_N and Authors.