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:

  1. fields: data field list, data field contains id, name, type, field id is used to support schema evolution.
  2. partitionKeys: field name list, partition definition of the table, it cannot be modified.
  3. primaryKeys: field name list, primary key definition of the table, it cannot be modified.
  4. options: map<string, string>, no ordered, options of the table, including a lot of capabilities and optimizations.

Example

  1. {
  2. "version" : 3,
  3. "id" : 0,
  4. "fields" : [ {
  5. "id" : 0,
  6. "name" : "order_id",
  7. "type" : "BIGINT NOT NULL"
  8. }, {
  9. "id" : 1,
  10. "name" : "order_name",
  11. "type" : "STRING"
  12. }, {
  13. "id" : 2,
  14. "name" : "order_user_id",
  15. "type" : "BIGINT"
  16. }, {
  17. "id" : 3,
  18. "name" : "order_shop_id",
  19. "type" : "BIGINT"
  20. } ],
  21. "highestFieldId" : 3,
  22. "partitionKeys" : [ ],
  23. "primaryKeys" : [ "order_id" ],
  24. "options" : {
  25. "bucket" : "5"
  26. },
  27. "comment" : "",
  28. "timeMillis" : 1720496663041
  29. }

Compatibility

For old versions:

  • version 1: should put bucket -> 1 to options if there is no bucket key.
  • version 1 & 2: should put file.format -> orc to options if there is no file.format key.

DataField

DataField represents a column of the table.

  1. id: int, column id, automatic increment, it is used for schema evolution.
  2. name: string, column name.
  3. type: data type, it is very similar to SQL type string.
  4. description: string.

Update Schema

Updating the schema should generate a new schema file.

  1. warehouse
  2. └── default.db
  3. └── my_table
  4. ├── schema
  5. ├── schema-0
  6. ├── schema-1
  7. └── 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 table, it is necessary to rely on them for schema evolution reading.