From bfa67f1fa709b465af331def068b73f4a62de563 Mon Sep 17 00:00:00 2001 From: roll Date: Thu, 28 Mar 2024 09:36:24 +0000 Subject: [PATCH] Make default field type to be `any` (#13) * Fixed default field type * Updated any type * Updated wording * Fixed typo Co-authored-by: Peter Desmet * Aded an example * Added note that any can be omitted * Update content/docs/specifications/table-schema.md Co-authored-by: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> * Update content/docs/specifications/table-schema.md Co-authored-by: Peter Desmet * Update content/docs/specifications/table-schema.md Co-authored-by: Peter Desmet --------- Co-authored-by: Peter Desmet Co-authored-by: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Co-authored-by: Peter Desmet --- content/docs/specifications/table-schema.md | 53 ++++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/content/docs/specifications/table-schema.md b/content/docs/specifications/table-schema.md index 272be5cb..fe46c212 100644 --- a/content/docs/specifications/table-schema.md +++ b/content/docs/specifications/table-schema.md @@ -188,15 +188,14 @@ A data consumer `MUST`: ### Types and Formats -`type` and `format` properties are used to give The type of the field (string, number etc) - see below for -more detail. If type is not provided a consumer `SHOULD` assume a type of "string". +`type` and `format` properties are used to give the type of the field (string, number, etc.) - see below for more detail. If type is not provided a consumer `MUST` utilize the `any` type for the field instead of inferring it from the field's values. A field's `type` property is a string indicating the type of this field. A field's `format` property is a string, indicating a format for the field type. Both `type` and `format` are optional: in a field descriptor, the absence of a -`type` property indicates that the field is of the type "string", and the +`type` property indicates that the field is of the type "any", and the absence of a `format` property indicates that the field's type `format` is "default". @@ -391,11 +390,48 @@ The field contains a JSON object according to GeoJSON or TopoJSON spec. #### any -Any `type` or `format` is accepted. When converting from physical to logical representation, the behaviour `SHOULD` be similar to String field type. +The field contains values of a unspecified or mixed type. A data consumer `MUST NOT` perform any processing on this field's values and `MUST` interpret them as it is in the data source. This data type is directly modelled on the concept of the `any` type of strongly typed object-oriented languages like [TypeScript](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any). -[strptime]: https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior -[iso8601-duration]: https://en.wikipedia.org/wiki/ISO_8601#Durations -[xsd-duration]: http://www.w3.org/TR/xmlschema-2/#duration +For example, having a Table Schema below: + +```json +{ + "fields": [ + { "name": "id", "type": "any" }, + { "name": "name", "type": "any" } + ] +} +``` + +This CSV data file will have logical values as below: + +```csv +id,name +1,apple +2,orange +``` + +```javascript +{id: "1", name: "apple"} +{id: "2", name: "orange"} +``` + +While this JSON data file will have logical values as below: + +```json +[ + ["id", "name"] + [1, "apple"] + [2, "orange"] +] +``` + +```javascript +{id: 1, name: "apple"} +{id: 2, name: "orange"} +``` + +Note, that for the CSV data source the `id` field is interpreted as a string because CSV supports only one data type i.e. string, and for the JSON data source the `id` field is interpreted as an integer because JSON supports a numeric data type and the value was declared as an integer. Also, for the Table Schema above a `type` property for each field can be omitted as it is a default field type. ### Rich Types @@ -817,3 +853,6 @@ Table Schema draws content and/or inspiration from, among others, the following [dspl]: https://developers.google.com/public-data/docs/schema/dspl18 [html5 forms]: http://www.whatwg.org/specs/web-apps/current-work/#attr-input-typ [elasticsearch]: http://www.elasticsearch.org/guide/reference/mapping/ +[strptime]: https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior +[iso8601-duration]: https://en.wikipedia.org/wiki/ISO_8601#Durations +[xsd-duration]: http://www.w3.org/TR/xmlschema-2/#duration