Schema#
The version of the schema file starts from 0 and currently retains all versions of the schema. There may be old files that rely on the old schema version, so its deletion should be done with caution.
Schema File is JSON, it includes:
fields: data field list. Each data field containsid,name,type. Fieldidis used to support schema evolution.partitionKeys: field name list. Partition definition of the table; it cannot be modified.primaryKeys: field name list. Primary key definition of the table; it cannot be modified.options:map<string, string>, unordered. Options of the table, including a lot of capabilities and optimizations.
Example#
{
"version" : 3,
"id" : 0,
"fields" : [ {
"id" : 0,
"name" : "order_id",
"type" : "BIGINT NOT NULL"
}, {
"id" : 1,
"name" : "order_name",
"type" : "STRING"
}, {
"id" : 2,
"name" : "order_user_id",
"type" : "BIGINT"
}, {
"id" : 3,
"name" : "order_shop_id",
"type" : "BIGINT"
} ],
"highestFieldId" : 3,
"partitionKeys" : [ ],
"primaryKeys" : [ "order_id" ],
"options" : {
"bucket" : "5"
},
"comment" : "",
"timeMillis" : 1720496663041
}
Compatibility#
For old versions:
Version 1: should put
bucket -> 1tooptionsif there is nobucketkey.Versions 1 & 2: should put
file.format -> orctooptionsif there is nofile.formatkey.
DataField#
DataField represents a column of the table.
id: int, column id, automatic increment; it is used for schema evolution.name: string, column name.type: data type, very similar to SQL type string.description: string.
Limitations#
MAP Key Must Be NOT NULL#
Apache Arrow does not support nullable map keys. When defining a MAP type in the schema,
the key must be explicitly marked as NOT NULL. If the key is not marked as NOT NULL,
schema parsing will fail with an error.
For example, the following is valid:
{
"type": "MAP",
"key": "TINYINT NOT NULL",
"value": "SMALLINT"
}
The following is invalid and will be rejected:
{
"type": "MAP",
"key": "TINYINT",
"value": "SMALLINT"
}
Update Schema#
Updating the schema should generate a new schema file.
warehouse
└── default.db
└── my_table
├── schema
├── schema-0
├── schema-1
└── schema-2
There is a reference to schema in the snapshot. The schema file with the highest numerical value is usually the latest schema file.
Old schema files cannot be directly deleted because there may be old data files that reference old schema files. When reading the table, it is necessary to rely on them for schema evolution reading.