World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#1590] docs: Add doc for column default value (#2003)
mchades3ea808cd208d
diff --git a/docs/apache-hive-catalog.md b/docs/apache-hive-catalog.mdindex 12b5d5c287..0defa23450 100644--- a/docs/apache-hive-catalog.md+++ b/docs/apache-hive-catalog.md@@ -67,7 +67,8 @@ see [Manage Metadata Using Gravitino](./manage-metadata-using-gravitino.md#schem### Table capabilities-The Hive catalog supports creating, updating, and deleting tables in the HMS.+- The Hive catalog supports creating, updating, and deleting tables in the HMS.+- Doesn't support column default value.#### Table partitionsdiff --git a/docs/expression.md b/docs/expression.mdindex 6f2379616d..3515a36f1e 100644--- a/docs/expression.md+++ b/docs/expression.md@@ -9,7 +9,7 @@ license: Copyright 2024 Datastrato Pvt Ltd. This software is licensed under theimport Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';-This page introduces the expression system of Gravitino. Expressions are vital component of metadata definition, through expressions, you can define default values for columns and function arguments for [function partitioning](./table-partitioning-bucketing-sort-order-indexes.md#table-partitioning), [bucketing](./table-partitioning-bucketing-sort-order-indexes.md#table-bucketing), and sort term of [sort ordering](./table-partitioning-bucketing-sort-order-indexes.md#sort-ordering) in tables.+This page introduces the expression system of Gravitino. Expressions are vital component of metadata definition, through expressions, you can define [default values](./manage-metadata-using-gravitino.md#table-column-default-value) for columns, function arguments for [function partitioning](./table-partitioning-bucketing-sort-order-indexes.md#table-partitioning), [bucketing](./table-partitioning-bucketing-sort-order-indexes.md#table-bucketing), and sort term of [sort ordering](./table-partitioning-bucketing-sort-order-indexes.md#sort-ordering) in tables.Gravitino expression system divides expressions into three basic parts: field reference, literal, and function. Function expressions can contain field references, literals, and other function expressions.## Field reference@@ -44,13 +44,18 @@ NamedReference field = NamedReference.field("student");## LiteralLiteral is a constant value.-The following is an example of creating a literal expression, demonstrating how to create three different data types of literal expressions for the value `1024`.+The following is an example of creating a literal expression, demonstrating how to create a `NULL` literal and three different data types of literal expressions for the value `1024`.<Tabs><TabItem value="Json" label="Json">```json[+ {+ "type": "literal",+ "dataType": "null",+ "value": "null"+ },{"type": "literal","dataType": "integer",@@ -75,6 +80,7 @@ The following is an example of creating a literal expression, demonstrating how```javaLiteral<?>[] literals =new Literal[] {+ Literals.NULL,Literals.integerLiteral(1024),Literals.stringLiteral("1024"),Literals.decimalLiteral(Decimal.of("1024", 10, 2))@@ -133,3 +139,28 @@ FunctionExpression[] functionExpressions =</TabItem></Tabs>+## Unparsed expression++Unparsed expression is a special type of expression, currently serves exclusively for presenting the default value of a column when it's unsolvable.+The following shows the data structure of an unparsed expression in JSON and Java, enabling easy retrieval of its value.++<Tabs>+ <TabItem value="Json" label="Json">++```json+{+ "type": "unparsed",+ "unparsedExpression": "(curdate() + interval 1 year)"+}+```++ </TabItem>+ <TabItem value="java" label="Java">++```java+// The result of the following expression is a string "(curdate() + interval 1 year)"+String unparsedValue = ((UnparsedExpression) expressino).unparsedExpression();+```++ </TabItem>+</Tabs>diff --git a/docs/jdbc-mysql-catalog.md b/docs/jdbc-mysql-catalog.mdindex 3fb0040ff8..3e46d343ea 100644--- a/docs/jdbc-mysql-catalog.md+++ b/docs/jdbc-mysql-catalog.md@@ -28,7 +28,7 @@ Gravitino saves some system information in schema and table comment, like `(From- Supports metadata management of MySQL (5.7, 8.0).- Supports DDL operation for MySQL databases and tables.- Supports table index.-- Supports column default value and auto-increment.+- Supports [column default value](./manage-metadata-using-gravitino.md#table-column-default-value) and [auto-increment](./manage-metadata-using-gravitino.md#table-column-auto-increment).- Supports managing MySQL table features though table properties, like using `engine` to set MySQL storage engine.### Catalog properties@@ -79,7 +79,7 @@ Please refer to [Manage Metadata Using Gravitino](./manage-metadata-using-gravit- Gravitino table corresponds to the MySQL table.- Supports DDL operation for MySQL tables.- Supports index.-- Support column default value and auto-increment.+- Supports [column default value](./manage-metadata-using-gravitino.md#table-column-default-value) and [auto-increment](./manage-metadata-using-gravitino.md#table-column-auto-increment)..- Supports managing MySQL table features though table properties, like using `engine` to set MySQL storage engine.#### Table column types@@ -107,9 +107,7 @@ MySQL doesn't support Gravitino `Boolean` `Fixed` `Struct` `List` `Map` `Timesta#### Table column auto-increment-- Supports setting auto-increment.--:::notice+:::noteMySQL setting an auto-increment column requires simultaneously setting a unique index; otherwise, an error will occur.:::@@ -121,7 +119,7 @@ MySQL setting an auto-increment column requires simultaneously setting a unique"columns": [{"name": "id",- "type": "int",+ "type": "integer","comment": "id column comment","nullable": false,"autoIncrement": true@@ -175,7 +173,7 @@ Although MySQL itself does not support table properties, Gravitino offers table- Supports PRIMARY_KEY and UNIQUE_KEY.-:::notice+:::noteThe index name of the PRIMARY_KEY must be PRIMARY[Create table index](https://dev.mysql.com/doc/refman/8.0/en/create-table.html):::diff --git a/docs/jdbc-postgresql-catalog.md b/docs/jdbc-postgresql-catalog.mdindex 392544ca98..64c96be59f 100644--- a/docs/jdbc-postgresql-catalog.md+++ b/docs/jdbc-postgresql-catalog.md@@ -28,7 +28,7 @@ Gravitino saves some system information in schema and table comment, like `(From- Supports metadata management of PostgreSQL (12.x, 13.x, 14.x, 15.x, 16.x).- Supports DDL operation for PostgreSQL schemas and tables.- Supports table index.-- Supports column default value and auto-increment.+- Supports [column default value](./manage-metadata-using-gravitino.md#table-column-default-value). and [auto-increment](./manage-metadata-using-gravitino.md#table-column-auto-increment).### Catalog properties@@ -83,7 +83,7 @@ Please refer to [Manage Metadata Using Gravitino](./manage-metadata-using-gravit- The Gravitino table corresponds to the PostgreSQL table.- Supports DDL operation for PostgreSQL tables.- Supports index.-- Support column default value and auto-increment.+- Support [column default value](./manage-metadata-using-gravitino.md#table-column-default-value) and [auto-increment](./manage-metadata-using-gravitino.md#table-column-auto-increment).- Doesn't support table property settings.#### Table column types@@ -114,43 +114,6 @@ PostgreSQL doesn't support Gravitino `Fixed` `Struct` `List` `Map` `IntervalDay`- Supports setting auto-increment.-<Tabs>-<TabItem value="json" label="Json">--```json-{- "columns": [- {- "name": "id",- "type": "int",- "comment": "id column comment",- "nullable": false,- "autoIncrement": true- },- {- "name": "name",- "type": "varchar(500)",- "comment": "name column comment",- "nullable": true,- "autoIncrement": false- }- ]-}-```--</TabItem>-<TabItem value="java" label="Java">--```java-Column[] cols = new Column[] {- Column.of("id", Types.IntegerType.get(), "id column comment", false, true, null),- Column.of("name", Types.VarCharType.of(500), "Name of the user", true, false, null)-};-```--</TabItem>-</Tabs>-### Table properties- Doesn't support table properties.diff --git a/docs/lakehouse-iceberg-catalog.md b/docs/lakehouse-iceberg-catalog.mdindex f68c58ae76..71488602f8 100644--- a/docs/lakehouse-iceberg-catalog.md+++ b/docs/lakehouse-iceberg-catalog.md@@ -78,6 +78,8 @@ Please refer to [Manage Metadata Using Gravitino](./manage-metadata-using-gravit### Table capabilities+- Doesn't support column default value.+#### Table partitionsSupports transforms:diff --git a/docs/manage-metadata-using-gravitino.md b/docs/manage-metadata-using-gravitino.mdindex 53d00f8247..6d1a8da120 100644--- a/docs/manage-metadata-using-gravitino.md+++ b/docs/manage-metadata-using-gravitino.md@@ -21,7 +21,7 @@ but they may have some differences, especially in catalog property, table proper- [**Apache Iceberg**](./lakehouse-iceberg-catalog.md)-Assuming Gravitino has just started, and the host and port is <http://localhost:8090>.+Assuming Gravitino has just started, and the host and port is [http://localhost:8090](http://localhost:8090).## Metalake operations@@ -609,26 +609,44 @@ You can create a table by sending a `POST` request to the `/api/metalakes/{metal```shellcurl -X POST -H "Accept: application/vnd.gravitino.v1+json" \-H "Content-Type: application/json" -d '{- "name": "my_table",- "comment": "This is my table",+ "name": "exmaple_table",+ "comment": "This is an exmaple table","columns": [{"name": "id","type": "integer","comment": "id column comment",- "nullable": true+ "nullable": false,+ "autoIncrement": true,+ "defaultValue": {+ "type": "literal",+ "dataType": "integer",+ "value": "-1"+ }},{"name": "name",- "type": "string",+ "type": "varchar(500)""comment": "name column comment",- "nullable": true+ "nullable": true,+ "autoIncrement": false,+ "defaultValue": {+ "type": "literal",+ "dataType": "null",+ "value": "null"+ }},{- "name": "age",- "type": "integer",- "comment": "age column comment",- "nullable": true+ "name": "StartingDate",+ "type": "timestamp",+ "comment": "StartingDate column comment",+ "nullable": false,+ "autoIncrement": false,+ "defaultValue": {+ "type": "function",+ "funcName": "current_timestamp",+ "funcArgs": []+ }},{"name": "info",@@ -700,6 +718,13 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \"nullOrdering": "nulls_first"}],+ "indexes": [+ {+ "indexType": "primary_key",+ "name": "PRIMARY",+ "fieldNames": [["id"]]+ }+ ],"properties": {"format": "ORC"}@@ -731,11 +756,11 @@ Map<String, String> tablePropertiesMap = ImmutableMap.<String, String>builder().build();tableCatalog.createTable(- NameIdentifier.of("metalake", "catalog", "schema", "table"),+ NameIdentifier.of("metalake", "catalog", "schema", "exmaple_table"),new Column[] {- Column.of("id", Types.IntegerType.get(), "id column comment", true, false, null),- Column.of("name", Types.VarCharType.of(1000), "name column comment", true, false, null),- Column.of("age", Types.IntegerType.get(), "age column comment", true, false, null),+ Column.of("id", Types.IntegerType.get(), "id column comment", false, true, Literals.integerLiteral(-1)),+ Column.of("name", Types.VarCharType.of(500), "name column comment", true, false, Literals.NULL),+ Column.of("StartingDate", Types.TimestampType.withoutTimeZone(), "StartingDate column comment", false, false, Column.DEFAULT_VALUE_OF_CURRENT_TIMESTAMP),Column.of("info", Types.StructType.of(Field.nullableField("position", Types.StringType.get(), "Position of the user"),Field.nullableField("contact", Types.ListType.of(Types.IntegerType.get(), false), "contact field comment"),@@ -743,21 +768,28 @@ tableCatalog.createTable(), "info column comment", true, false, null),Column.of("dt", Types.DateType.get(), "dt column comment", true, false, null)},- "Create a new Table",+ "This is an exmaple table",tablePropertiesMap,new Transform[] {Transforms.identity("id")},Distributions.of(Strategy.HASH, 32, NamedReference.field("id")),- new SortOrder[] {SortOrders.ascending(NamedReference.field("name"))}+ new SortOrder[] {SortOrders.ascending(NamedReference.field("name"))},+ new Index[] {Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}})});```</TabItem></Tabs>+:::caution+The provided example demonstrates table creation but isn't directly executable in Gravitino, since not all catalogs fully support these capabilities.+:::+In order to create a table, you need to provide the following information:- Table column name and type-- Table property+- Table column default value (optional)+- Table column auto-increment (optional)+- Table property (optional)#### Gravitino table column type@@ -791,16 +823,30 @@ The following types that Gravitino supports:The related java doc is [here](pathname:///docs/0.4.0/api/java/com/datastrato/gravitino/rel/types/Type.html).+#### Table column default value++When defining a table column, you can specify a [literal](./expression.md#literal) or an [expression](./expression.md) as the default value. The default value typically applies to new rows that are inserted into the table by the underlying catalog.++The following is a table of the column default value that Gravitino supports for different catalogs:++| Catalog provider | Supported default value |+|---------------------|-------------------------|+| `hive` | NO |+| `lakehouse-iceberg` | NO |+| `jdbc-mysql` | YES |+| `jdbc-postgresql` | YES |+#### Table column auto-incrementAuto-increment provides a convenient way to ensure that each row in a table has a unique identifier without the need for manually managing identifier allocation.-The following catalogs support setting the table column auto-increment.--| Catalog provider | Auto-increment mapping |-|---------------------|-----------------------------------------------------------------------------------------------|-| `jdbc-mysql` | [MySQL auto-increment mapping](./jdbc-mysql-catalog.md#table-column-auto-increment) |-| `jdbc-postgresql` | [PostgreSQL auto-increment mapping](./jdbc-postgresql-catalog.md#table-column-auto-increment) |+The following table shows the column auto-increment that Gravitino supports for different catalogs:+| Catalog provider | Supported auto-increment |+|---------------------|-----------------------------------------------------------------------------|+| `hive` | NO |+| `lakehouse-iceberg` | NO |+| `jdbc-mysql` | YES with [limitations](./jdbc-mysql-catalog.md#table-column-auto-increment) |+| `jdbc-postgresql` | YES |#### Table property and type mapping@@ -813,7 +859,6 @@ The following is the table property that Gravitino supports:| `jdbc-mysql` | [MySQL table property](./jdbc-mysql-catalog.md#table-properties) | [MySQL type mapping](./jdbc-mysql-catalog.md#table-column-types) || `jdbc-postgresql` | [PostgreSQL table property](./jdbc-postgresql-catalog.md#table-properties) | [PostgreSQL type mapping](./jdbc-postgresql-catalog.md#table-column-types) |-#### Table partitioning, bucketing, sort ordering and indexingIn addition to the basic settings, Gravitino supports the following features:@@ -825,7 +870,6 @@ In addition to the basic settings, Gravitino supports the following features:| Table sort ordering | Equal to `SORTED BY` in Apache Hive, sort ordering is a method to sort the data in specific ways such as by a column or a function, and then store table data. it will highly improve the query performance under certain scenarios. | [SortOrder](pathname:///docs/0.4.0/api/java/com/datastrato/gravitino/rel/expressions/sorts/SortOrder.html) || Table indexing | Equal to `KEY/INDEX` in MySQL , unique key enforces uniqueness of values in one or more columns within a table. It ensures that no two rows have identical values in specified columns, thereby facilitating data integrity and enabling efficient data retrieval and manipulation operations. | [Index](pathname:///docs/0.4.0/api/java/com/datastrato/gravitino/rel/indexes/Index.html) |-For more information, please see the related document on [partitioning, bucketing, sorting, and indexing](table-partitioning-bucketing-sort-order-indexes.md).:::note@@ -861,6 +905,10 @@ tableCatalog.loadTable(NameIdentifier.of("metalake", "hive_catalog", "schema", "</TabItem></Tabs>+:::note+When Gravitino loads a table from a catalog that supports default value, if Gravitino is unable to parse the default value, it will use an **[Unparsed Expression](./expression.md#unparsed-expression)** to preserve the original default value, ensuring that the table can be loaded successfully.+:::+### Alter a tableYou can modify a table by sending a `PUT` request to the `/api/metalakes/{metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/tables/{table_name}` endpoint or just use the Gravitino Java client. The following is an example of modifying a table:@@ -911,7 +959,7 @@ Currently, Gravitino supports the following changes to a table:| Set a table property | `{"@type":"setProperty","property":"key1","value":"value1"}` | `TableChange.setProperty("key1", "value1")` || Remove a table property | `{"@type":"removeProperty","property":"key1"}` | `TableChange.removeProperty("key1")` || Add a column | `{"@type":"addColumn","fieldName":["position"],"type":"varchar(20)","comment":"Position of user","position":"FIRST"}` | `TableChange.addColumn(...)` |-| Delete a column | `{"@type":"deleteColumn","fieldName": ["name"], "ifExists": true}` | `TableChange.deleteColumn(...)` |+| Delete a column | `{"@type":"deleteColumn","fieldName": ["name"], "ifExists": true}` | `TableChange.deleteColumn(...)` || Rename a column | `{"@type":"renameColumn","oldFieldName":["name_old"], "newFieldName":"name_new"}` | `TableChange.renameColumn(...)` || Update the column comment | `{"@type":"updateColumnComment", "fieldName": ["name"], "newComment": "new comment"}` | `TableChange.updateColumnCommment(...)` || Update the type of a column | `{"@type":"updateColumnType","fieldName": ["name"], "newType":"varchar(100)"}` | `TableChange.updateColumnType(...)` |diff --git a/docs/open-api/tables.yaml b/docs/open-api/tables.yamlindex 62f55a4eb9..e8864f5322 100644--- a/docs/open-api/tables.yaml+++ b/docs/open-api/tables.yaml@@ -320,6 +320,13 @@ components:items:type: string+ ColumnDefaultValue:+ $ref: "./expression.yaml#/components/schemas/FunctionArg"+ description: The default value of the column+ required: false+ nullable: true+ default: null+Column:type: objectrequired:@@ -340,6 +347,8 @@ components:description: Whether the column is nullablenullable: truedefault: true+ defaultValue:+ $ref: "#/components/schemas/ColumnDefaultValue"autoIncrement:type: booleandescription: Whether the column is auto increment