-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#1134] docs: Add user doc of expression #1991
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
--- | ||
title: "Expression system of Gravitino" | ||
slug: /expression | ||
date: 2024-02-02 | ||
keyword: expression function field literal reference | ||
license: Copyright 2024 Datastrato Pvt Ltd. This software is licensed under the Apache License version 2. | ||
--- | ||
|
||
import 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. | ||
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. | ||
|
||
<Tabs> | ||
<TabItem value="Json" label="Json"> | ||
|
||
```json | ||
[ | ||
{ | ||
"type": "field", | ||
"fieldName": [ | ||
"student" | ||
] | ||
} | ||
] | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="java" label="Java"> | ||
|
||
```java | ||
NamedReference field = NamedReference.field("student"); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
## Literal | ||
|
||
Literal 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`. | ||
|
||
<Tabs> | ||
<TabItem value="Json" label="Json"> | ||
|
||
```json | ||
[ | ||
{ | ||
"type": "literal", | ||
"dataType": "integer", | ||
"value": "1024" | ||
}, | ||
{ | ||
"type": "literal", | ||
"dataType": "string", | ||
"value": "1024" | ||
}, | ||
{ | ||
"type": "literal", | ||
"dataType": "decimal(10,2)", | ||
"value": "1024" | ||
} | ||
] | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="java" label="Java"> | ||
|
||
```java | ||
Literal<?>[] literals = | ||
new Literal[] { | ||
Literals.integerLiteral(1024), | ||
Literals.stringLiteral("1024"), | ||
Literals.decimalLiteral(Decimal.of("1024", 10, 2)) | ||
}; | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
## 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)`. | ||
|
||
<Tabs> | ||
<TabItem value="Json" label="Json"> | ||
|
||
```json | ||
[ | ||
{ | ||
"type": "function", | ||
"funcName": "rand", | ||
"funcArgs": [] | ||
}, | ||
{ | ||
"type": "function", | ||
"funcName": "date_trunc", | ||
"funcArgs": [ | ||
{ | ||
"type": "literal", | ||
"dataType": "string", | ||
"value": "year" | ||
}, | ||
{ | ||
"type": "field", | ||
"fieldName": [ | ||
"birthday" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="java" label="Java"> | ||
|
||
```java | ||
FunctionExpression[] functionExpressions = | ||
new FunctionExpression[] { | ||
FunctionExpression.of("rand"), | ||
FunctionExpression.of("date_trunc", Literals.stringLiteral("year"), NamedReference.field("birthday")) | ||
}; | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it
Json
orjson
forvalue
? I see that below in Java it isvalue="java"
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After local testing, both can be rendered correctly.
This writing appears in other documents as well, should I change it to keep the styling consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK if it can be rendered correctly. If you want to unify them you can do it in another PR.