---
title: Dataset conventions
description: The rules that make published tables joinable with other datasets without preprocessing
---

These are the rules that make a published table joinable with other datasets without any preprocessing. They apply alike to Queria's own datasets and to everyone else's.

What a machine can check is left to tabledoc's checks (`tabledoc validate` and `tabledoc load`), Queria's checks on publishing, and dbt tests; this page holds what you need to make the judgement calls. Which layer a description belongs in is covered in [Writing descriptions](/en/publish/writing-descriptions).

## Names

Every name is lowercase letters, digits and underscores.

- Dataset: the name of the publisher or the source (`nlftp`, `e_stat`, `gif`). Never changes once published
- Schema: the subject (`boundary`, `facility`, `vocab`). Do not leave it as `main`, and do not expose layer names (`stg`, `mart`, `silver`)
- Table: a noun for what one row is (`shelter`, `term`, `code_system`). No dates or versions in the name

When you rename a table or a schema, keep the old name around for a while.

## Column names

Column names follow a vocabulary chosen by the kind of data.

- General data (maps, places, data from outside Japan): [schema.org](https://schema.org/) terms in snake_case (`postalCode` → `postal_code`)
- Japanese public data (national and municipal statistics and registers): the English names of the Digital Agency's [Government Interoperability Framework (GIF)](https://www.digital.go.jp/policies/data_strategy_government_interoperability_framework) in snake_case (`localGovernmentCode` → `local_government_code`). When a GIF term only adds a qualifier to a schema.org term, use the shorter one (`latitude`, not `latitudeOfRepresentativePoint`)
- A column's `title` is the GIF Japanese name either way, the [IMI](https://imi.go.jp/) term when GIF has none, and the source's own heading when neither does

Columns that mean the same thing under different names are tied together in the vocabulary [queria-io/vocabulary](https://github.com/queria-io/vocabulary). What a column represents is in the data element vocabulary `data_elements.csv`; what it identifies is in the entity vocabulary `entities.csv`. When naming a new column:

1. If the data element is in `data_elements.csv`, use its `title`. The column name is the value in its `name` column for Japanese public data, and its `schema_org` term in snake_case for general data (the `name` value when `schema_org` is empty)
2. If not, look the term up in your vocabulary (the `schemaorg` or `gif` dataset below) and use it in snake_case
3. If no vocabulary has it, name it as you like, but without abbreviations (`lat`, `pref`, `num`)

Some common data elements:

- Local government code (6 digits): `local_government_code` (also seen as `lg_code`)
- Prefecture: `prefecture` in public data, `address_region` in general data (`pref_name`)
- Postal code: `postal_code` (`postcode`, `zipcode`)
- Latitude and longitude: `latitude` / `longitude` (`lat` / `lon`)

A column in a code system of the source's own is qualified with that system's name, so it is not mistaken for the standard one (`police_city_code` for police jurisdiction codes).

There is no need to rename existing columns. Abbreviations such as `lat` or `pref_code` are the exception: add a column with the new name beside the old one, mark the old one deprecated in its description, and drop it later.

## Types and values

Publish values in a type that can be joined and aggregated as is. Whatever meaning the conversion loses goes in another column. Types are read from the data, so they are not written in the table file.

- Codes (local government codes, corporate numbers, postal codes, grid squares): `VARCHAR`. Keep leading zeros and state the number of digits and whether there is a check digit in the column description. Postal codes are 7 digits with no hyphen
- Quantities, amounts, counts: a numeric type, never `VARCHAR`. State the unit in the column description
- Dates and points in time: `DATE`, or an `INTEGER` Gregorian year when only the year is known. Convert Japanese era years
- Coordinates: `latitude` / `longitude` as decimal-degree `DOUBLE` in a world geodetic datum (JGD2011 or WGS 84). Convert sources in the old Tokyo Datum. Point data also gets a `geometry` column, with its coordinate reference system in the column description as `EPSG:xxxx`
- Booleans: `BOOLEAN`. Convert `○`, `有`, `1` and the like
- Strings: NFKC-normalized, with surrounding whitespace removed
- Tables that mix national, prefectural and municipal rows in one column: add an `area_level` column, and mark subtotal rows

### Missing and suppressed values

Where a statistical table puts a symbol such as `-`, `x` or `…` in place of a number, split the column into a value and its status.

- `value`: the number; `0` where the symbol means zero, `NULL` on rows with any other symbol
- `value_flag`: the observation status, as a one-letter code from the observation status (`OBS_STATUS`) of [SDMX](https://sdmx.org/), the international standard for exchanging statistical data
- `value_raw`: the source's symbol as it was

How the symbols common in Japanese statistical tables map to `value_flag`. Where the source's legend says otherwise, follow the legend and state the mapping in the column description.

- Normal value: `A`
- Estimated value: `E`
- Provisional or preliminary value: `P`
- No cases (`-` and the like, where the legend means a count of zero): `value` set to `0`, flag `A`
- Not applicable (where the legend says a value cannot exist, such as a municipality in a year before it was formed): `M`
- Suppressed (`x` and the like): `Q`
- Not collected or unknown (`…` and the like): `L`

The column names may change (`population` and `population_flag`, for example).

### Lookup tables and shared conversions

Lookup tables that turn codes into names go in dbt `seeds/`, not in a SQL `CASE`, so a test can catch values with no entry. Conversions every dataset needs, such as date notation variants, degrees-minutes-seconds and restoring leading zeros, are shared rather than rewritten per dataset. For Queria's own datasets, they belong in the `macros/` of [dataset-shared](https://github.com/queria-io/dataset-shared): a conversion that is not there yet is added there as a dbt macro, not written inside the dataset.

## Transformation steps

We recommend building tables in three steps: raw, stg and mart. This is not required. Separate steps let you rebuild without fetching again, and show later which transformation happened where.

- raw: the data as fetched. Column names and values are left unchanged. Only this step reads the fetched files
- stg: reads one raw table and casts types, renames columns, and normalizes codes and notation
- mart: reads stg tables and joins, pivots or unpivots, and sets the grain. The tables you publish live in this step

Keep fetch scripts to fetching and converting files such as Excel or PDF into a format that can be read as a table. Do the content transformations in stg and mart. In dbt, split the directories into `models/<topic>/raw`, `stg` and `mart`. Step names do not appear in schema names ([Names](#names)).

## Tables and views

Write the tables you publish as tables, not views. In dbt, set `+materialized: table` on the models you declare. A view is computed from its source tables every time it is read. When `fdl push` measures row counts, value ranges and lists of values, it computes each view in full at every push, which makes the push slow. Intermediate steps you do not declare (such as stg) can stay views.

## Grain

Decide what one row of a published table is, and hold it with tests. Duplicate rows silently skew aggregates, so they are stopped before publishing.

- State the grain in the first sentence of the table description ("One row per municipality per year")
- Write the grain columns in `primary_key` in the table file (see [Publish data](/en/publish#declare-the-primary-key))
- For data the source revises (corrections, final figures replacing preliminary ones, municipal mergers), decide per dataset whether a column records which snapshot a row belongs to, and say so in the description
- Data whose source varies row by row keeps it in a column (`source_url`)

## Source files

For data the publisher distributes as files, such as Excel, CSV, PDF or ZIP, we recommend publishing the list of fetched files as a table. This is not required. It lets anyone check which file each row came from, when it was fetched and from where. Data fetched from an API or a web page is out of scope.

- Name the table `source_file`. One row is one file; when the content at a URL changes, the new content is a new row. Its columns are below. `bytes` and `media_type` have the same names as the columns `fdl assets` writes
  - `url`: the URL the file was fetched from
  - `page_url`: the URL of the page that listed the file, if any
  - `sha256`: the file's sha256
  - `bytes`: the size in bytes
  - `media_type`: the media type
  - `retrieved_at`: when the file was fetched (UTC)
  - `etag`, `last_modified`: the `ETag` and `Last-Modified` headers of the response, or null
- On the next fetch, compare `ETag`, `Last-Modified` and the size with the previous row. Skip the download only when they match and the file is at hand or stored as an asset. Fetch without comparing when the response has neither `ETag` nor `Last-Modified`. When the publisher gives each file an ID that never changes (a document number, say), keep that ID as a column too
- A table that reads the files keeps the sha256 of the source file in a `source_sha256` column on each row. For Excel, it also keeps the sheet name (`source_sheet`) and row number (`source_row`). A published table keeps `source_sha256` when each of its rows is made from one file

Do not store files that can be fetched again from their URL. Store only the files that are hard to fetch again, as FDL [assets](https://fdl.queria.io/spec/versions#assets) of the version. When you store every file in the list, mark `sha256` with `asset: true`. When you store only some, add an `asset_sha256` column that holds the sha256 of the stored files and null for the rest, and mark that column instead. `fdl push` stops when a column marked `asset: true` holds the sha256 of a file the repository lacks. Store these files:

- Files that need an API key, or a large number of requests one by one
- Files the publisher removes from its page, or replaces at the same URL

Give the folder that holds the asset files to `tabledoc load --out build/assets --assets <folder>`. tabledoc links those files into `build/assets/`, and `fdl commit --assets build/assets` commits them with the README and guides. At `fdl push`, only the files the repository lacks are uploaded, and the same content is stored once. Do not store files whose terms of use do not allow redistribution, even if they are hard to fetch again. Anyone can download the assets of a published dataset.

## Identifiers

Declare an identifier with `entity: { type: foreign, name: ... }` on every column that can be matched across datasets. The syntax and the list of identifiers are in [Publish data](/en/publish#declare-identifiers).

- If a published table has a column that can be matched, it always gets an identifier
- `name` is a name from the entity vocabulary `entities.csv`. Queria refuses a push with any other name. Propose new keys to queria-io/vocabulary
- A category column not used for matching gets `dimension: categorical`, and a date column `dimension: time`

## Metadata

The keys of `tabledoc.yml` correspond to items of [DCAT](https://www.w3.org/TR/vocab-dcat-3/), the W3C data catalog vocabulary (DCAT-GoJ is the Japanese government's profile of it). Filling in each field gives you what a government data catalog asks for.

- `title` and `title_reading` → `dct:title`: the source's formal name and its reading
- `description` → `dct:description`: what the data is, what it is for, then the attribution text
- `licenses` → `dct:license`: for an ID in [tabledoc's registry](https://github.com/queria-io/tabledoc/blob/main/src/tabledoc/licenses.json) (some SPDX identifiers such as `CC-BY-4.0`, and terms of use such as `JP-PDL-1.0`), write the ID alone and tabledoc fills in the title, URL and terms. For a license not in the registry, write `id: other` and spell out the terms (commercial use, share-alike, attribution)
- `contributors` with `roles` → `dct:publisher`, `dct:rightsHolder` and so on: keep the rights holder and the provider apart
- `sources` → `dct:source`: the `id`, name and URL of where the data was fetched from. A table's own sources go in that table's `sources`, which refers to a source of the dataset by its `id` alone. A table that has them replaces the dataset's rather than adding to them, so list both if both apply
- `update_frequency` → `dct:accrualPeriodicity`: how often it is actually updated
- `spatial_coverage` → `dct:spatial`: a country code or local government codes
- `temporal_coverage` → `dct:temporal`: the period covered
- `topics` → `dcat:keyword`: classifying words and the other names people use for the data

## Looking up the vocabularies

When choosing a column name or `title`, the vocabularies themselves can be queried with SQL as Queria datasets. Each is refreshed from its source regularly, so there is no need to keep a copy.

- `gif`: items for Japanese public data (`vocab.term`), code lists (`vocab.code`), and the definitions and publishers of government code systems (`vocab.code_system`)
- `imi`: IMI terms with their permanent URIs (`vocab.term`) and the properties of each class (`vocab.class_property`)
- `schemaorg`: schema.org properties (`vocab.property`, with the snake_case form in `snake_case_name`) and types (`vocab.type`, `vocab.type_property`)

```sql
-- GIF items about postal codes, with candidate column names
SELECT class_name, term_ja, snake_case_name FROM gif.vocab.term WHERE term_ja LIKE '%郵便%';

-- Is there a schema.org property of the same name?
SELECT name, snake_case_name, description FROM schemaorg.vocab.property WHERE snake_case_name = 'postal_code';
```

## Checks

`tabledoc load` checks:

- the keys of `tabledoc.yml` and the `<table>.tabledoc.yml` files (JSON Schema), including the values of `entity` `type` and `dimension`
- the name and place of each table file, and the same key written in both dbt's yml and the table file (errors)
- that the described tables and columns, and the `primary_key` columns, are in the working catalog (errors)
- that the columns with `asset: true` are `varchar` (errors)

When it receives a push, Queria checks the following and refuses a version that fails:

- that key names are in the entity vocabulary, and that each license states whether commercial use is allowed (`commercial_use`). `tabledoc load` fills in the terms of an id in tabledoc's registry; a license not in the registry keeps the terms you write

Check that primary key values are unique and never NULL with dbt tests (`unique` and `not_null`).
