Comments (6)
@akariv please have a read.
from tableschema-go.
@danielfireman
I just going to dive into the problem but I could say about your example - things like post_cast
is an extended level of FrictionlessData implementations (see https://github.com/frictionlessdata/implementations#tableschema). We support it only in Python.
from tableschema-go.
@danielfireman why not go the way that the standard json
implementation is done in Go:
https://blog.golang.org/json-and-go
You can pass an interface with the correct fields, in which case unmarshalling will fill these fields. If you pass an empty interface, a map will be created. That's the best of both worlds.
from tableschema-go.
Thanks for chiming in, @akariv! Totally agree that is the best of both worlds. @roll, could we close on that? Further comments?
As per request from @roll, let's sumarize with examples from all options so far. We are going to use the following python fragment as guide:
table = tableschema.Table('data.csv', schema='schema.json')
table.headers # ['name', 'age']
records = table.read() # [['John', 55], ['Alex', 25]]
age_sum = 0
for r in records:
age_sum = age_sum + r[1]
print 'Name:', r[0], 'Age:', r[1]
print 'Average age:', age_sum/len(records)
- map[string]interface{} (equivalent to Map<String, Object> in java)
table, _ := tableschema.Table("data.csv")
fmt.Println(table.Headers()) // ["name", "age"]
records = table.All(context.Background())
ageSum := 0.0
for _, r := range records {
name := string(r["name"])
age := int(r["age"])
ageSum += float(age)
fmt.Printf("Name: %s Age: %d\n", name, age)
}
fmt.Println("Average age:%f", ageSum/10.0)
- Very general objects with accessor methods
// ... Same as above
for _, r := range records {
name := r["name"].AsString()
age := r["age"].AsInt()
ageSum += float(age)
fmt.Printf("Name: %s Age: %d\n", name, age)
}
// ... Same as above
- database/sql like
// ... Same as above
var string name
var age int
for _, r := range records {
r.Scanf(&name, &age) // This needs to be in the same order as headars
ageSum += float(age)
fmt.Printf("Name: %s Age: %d\n", name, age)
}
// ... Same as above
- Code generator
table, _ := tableschema.Table("data.csv")
fmt.Println(table.Headers()) // ["name", "age"]
var records []Record
table.All(context.Background(), &records)
for _, r := range records {
ageSum += float(r.Age)
fmt.Printf("Name: %s Age: %d\n", r.Name, r.Age)
}
fmt.Println("Average age:%f", ageSum/10.0)
- JSON Like
table, _ := tableschema.Table("data.csv")
fmt.Println(table.Headers()) // ["name", "age"]
var records []struct {
Name string `header:"name"`
Age int `header:"age"`
}
table.All(context.Background(), &records)
ageSum := 0.0
for _, r := range records {
ageSum += float(r.Age)
fmt.Printf("Name: %s Age: %d\n", r.Name, r.Age)
}
fmt.Println("Average age:%f", ageSum/10.0)
- Edit: Removed bad copy and paste from tableschema.Table
from tableschema-go.
@danielfireman
I'm also +1 for JSON-like. My comment about SQL-like was more like it could be better to use some proven solution and JSON-like seems even better. I've read how it works and flexibility with supporting both declared interface or empty interface {} should be good fit for Frictionless Data eco-system where people do many researches etc (e.g. quickly read and print data without full type declaration). I suppose it's not a point of this example but just as a note records -> rows
, Table.Read
etc as a part of naming consistency (where possible) between implementations.
from tableschema-go.
Got it.
I will keep in mind the naming consistency. Thanks for the heads up!
from tableschema-go.
Related Issues (20)
- Latest version is not released HOT 2
- Add xls/xlsx data processing HOT 6
- Add tableschema-go to golang.org/pkg/ HOT 4
- Number being inferred as boolean HOT 9
- valdate example and capitals.csv test data HOT 3
- Add support to go 11 and modules HOT 1
- Version 1.11 seems to have been released by mistake HOT 3
- Error when trying to build with go 1.14 HOT 1
- Error trying to CastTable. HOT 1
- CastRow does not support embedded types
- Problem running tests
- Present all errors when Casting table HOT 1
- Cast should support pointer types
- Constraints are not correctly processed HOT 2
- Constraints field is called "Constraints" HOT 1
- Support GZIP compressed CSV files HOT 2
- Add Table.Validate(schema) HOT 2
- Renaming master branch to main HOT 1
- Migrate to Github Actions HOT 2
- datetime fields not being properly processed by CastRow
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tableschema-go.