Expression system of Apache Gravitino
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 is an example of creating a field reference expression, demonstrating how to create a reference for the student
field.
- Json
- Java
[
{
"type": "field",
"fieldName": [
"student"
]
}
]
NamedReference field = NamedReference.field("student");
Literal
Literal is a constant value.
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
.
- Json
- Java
[
{
"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"
}
]
Literal<?>[] literals =
new Literal[] {
Literals.NULL,
Literals.integerLiteral(1024),
Literals.stringLiteral("1024"),
Literals.decimalLiteral(Decimal.of("1024", 10, 2))
};
Function expression
Function expression represents a function call with/without arguments. The arguments can be field references, literals, or other function expressions.
The following is an example of creating a function expression, demonstrating how to create function expressions for rand()
and date_trunc('year', birthday)
.
- Json
- Java
[
{
"type": "function",
"funcName": "rand",
"funcArgs": []
},
{
"type": "function",
"funcName": "date_trunc",
"funcArgs": [
{
"type": "literal",
"dataType": "string",
"value": "year"
},
{
"type": "field",
"fieldName": [
"birthday"
]
}
]
}
]
FunctionExpression[] functionExpressions =
new FunctionExpression[] {
FunctionExpression.of("rand"),
FunctionExpression.of("date_trunc", Literals.stringLiteral("year"), NamedReference.field("birthday"))
};