Skip to main content

Expression system

Introduction​

This page introduces the expression system of Apache Gravitino. Expressions are vital component of metadata definition, through expressions, you can define default values for columns, function arguments for function partitioning, bucketing, and sort term of 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​

Field reference is a reference to a field in a table. The following example creates a reference for the student field.

Create a field reference
[
{
"type": "field",
"fieldName": [
"student"
]
}
]

Literal​

Literal is a constant value. The following example creates a NULL literal and literals of three different data types for the value 1024.

Create literal expressions
[
{
"type": "literal",
"dataType": "null",
"value": "null"
},
{
"type": "literal",
"dataType": "integer",
"value": "1024"
},
{
"type": "literal",
"dataType": "string",
"value": "1024"
},
{
"type": "literal",
"dataType": "decimal(10,2)",
"value": "1024"
}
]

Function expression​

Function expression represents a function call with/without arguments. The arguments can be field references, literals, or other function expressions. The following example creates function expressions for rand() and date_trunc('year', birthday).

Create function expressions
[
{
"type": "function",
"funcName": "rand",
"funcArgs": []
},
{
"type": "function",
"funcName": "date_trunc",
"funcArgs": [
{
"type": "literal",
"dataType": "string",
"value": "year"
},
{
"type": "field",
"fieldName": [
"birthday"
]
}
]
}
]

Unparsed expression​

Unparsed expression is a special type of expression, 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.

Read an unparsed expression
{
"type": "unparsed",
"unparsedExpression": "(curdate() + interval 1 year)"
}