question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type of minimum/maximum constraint should be the same of the field

See original GitHub issue

According to the spec, the type of the minimum/maximum constraint should be the same as the constrained field. The examples given in the official table-schema respect this principle. Here is the example given in the official schema for an integer:

   {
         "name": "age", 
         "type": "integer",
         "constraints": {
             "unique": true, 
             "minimum": 100, 
             "maximum": 9999
         }
    }

However, the spec for the minimum and maximum constraint expect their type to be string all the time. For example the spec for the minimum constraint of an integer:

{
    "minimum": {
        "type": "string",
        "description": "A minimum value for the property, context specific for the property type, and conforming with the format for the property.",
        "context": "This is different to `minLength`, which checks the number of items in the value. A `minimum` value constraint checks whether a field value is greater than or equal to the specified value."
    }
}

Shouldn’t ☝️ be "type": "integer"?

Same is true for other field types with minimum and maximum constraints.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
rollcommented, Jun 23, 2017

@georgiana-b It just has been added to the specs:

All constraints MUST be tested against the logical representation of data, and the physical representation of constraint values MAY be primitive types as possible in JSON, or represented as strings that are castable with the type and format rules of the field.

And on implementation level you just treat field’s data value and constraint value the same - https://github.com/frictionlessdata/tableschema-py/blob/master/tableschema/field.py#L153-L167

For example you have field:

name: name
type: integer
constraints:
  maximum: 20 or '20'

with data

50
'40'
30

So you first just cast constraint to field type (‘20’ -> 20) and then compare to values also cast to data type (‘40’ -> 40).

1reaction
rollcommented, Jun 29, 2017

@pwalsh Both will work for implementations for now. But if you’re in the mood for second option (i.e. have time=) it will be better. Though enum is also not typed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can Min or Max field values from Column Constraint...
Hi, I have a Kanban board with the Minimum and Maximum values set as constraints. However, I want to perform various events based...
Read more >
java - Why do bean validation Min/Max constraints not support ...
Use the @DecimalMin annotation. You will need to pass a literal String value, because the attrubute value must be constant (String.
Read more >
Max-Min Problems - UT Austin Wikis
Max -min problems, also known as optimization problems, are word problems that ask for the maximum or minimum values of a function, often...
Read more >
Min and max constraints - Oracle Communities
I've set up all of my tables with PK and FK constraints and I'm wondering if you can enforce min and max column...
Read more >
Anatomy of a Constraint - Auto Layout Guide - Apple Developer
For example, you can use constraints to define the minimum or maximum size for a view (Listing 3-3). Listing 3-3Assigning a minimum and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found