Giter Site home page Giter Site logo

Comments (6)

pwalsh avatar pwalsh commented on May 27, 2024

@akariv please have a read.

from tableschema-go.

roll avatar roll commented on May 27, 2024

@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.

akariv avatar akariv commented on May 27, 2024

@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.

danielfireman avatar danielfireman commented on May 27, 2024

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.

roll avatar roll commented on May 27, 2024

@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.

danielfireman avatar danielfireman commented on May 27, 2024

Got it.

I will keep in mind the naming consistency. Thanks for the heads up!

from tableschema-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.