frictionlessdata / tableschema-js

A JavaScript library for working with Table Schema.
http://frictionlessdata.io/
MIT License
82 stars 27 forks source link

Implement constraints inferring? #148

Closed iSimar closed 4 years ago

iSimar commented 6 years ago

Just like how you receive the type of a column, is there is a way to get the max length of characters for values in a column?

roll commented 6 years ago

@iSimar We can use field.constraints:

schema.getField('name').constraints.maxLength
field.constraints.maxLength
sebasalvarado commented 6 years ago

@roll: Thanks for your answer however the maxLength property is not present in the constraints object from the Field.

In fact, I get:

field.constraints

to be an empty object {}. Do I need to pass any special parameter in table.infer so that the object constraints is non-empty?

roll commented 6 years ago

@sebasalvarado No, it doesn't infer constraints. We have to set constraints manually in this case. I thought your descriptor had already had it

iSimar commented 5 years ago

@roll is there a roadmap to infer constraints?

roll commented 5 years ago

@iSimar I'm not sure. Could you please check in the official Gitter channel - https://gitter.im/frictionlessdata/chat

roll commented 4 years ago

The recommended way is to wrap the library functionality to achieve the goal e.g.

const table = await Table.load('data.csv')
const headers = table.headers
const sample = await table.read({limit: 100})
const schema = await infer(sample, {headers})
// analyze sample and add the needed constraints to the schema

I'm closing as in a general case, inferring constraints is not possible or expected by the majority of users