-
Notifications
You must be signed in to change notification settings - Fork 883
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
Add z-order docs #1481
Closed
Closed
Add z-order docs #1481
Changes from all commits
Commits
Show all changes
3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,121 @@ | ||
<!-- | ||
- Licensed to the Apache Software Foundation (ASF) under one or more | ||
- contributor license agreements. See the NOTICE file distributed with | ||
- this work for additional information regarding copyright ownership. | ||
- The ASF licenses this file to You under the Apache License, Version 2.0 | ||
- (the "License"); you may not use this file except in compliance with | ||
- the License. You may obtain a copy of the License at | ||
- | ||
- http://www.apache.org/licenses/LICENSE-2.0 | ||
- | ||
- Unless required by applicable law or agreed to in writing, software | ||
- distributed under the License is distributed on an "AS IS" BASIS, | ||
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
- See the License for the specific language governing permissions and | ||
- limitations under the License. | ||
--> | ||
|
||
<div align=center> | ||
|
||
![](../imgs/kyuubi_logo.png) | ||
|
||
</div> | ||
|
||
# Z-order introduction | ||
|
||
## Introduction | ||
|
||
The following picture shows the workflow of z-order. | ||
|
||
![](../imgs/extension/zorder-workflow.png) | ||
|
||
It contains three parties: | ||
- Upstream | ||
|
||
Due to the extra sort, the upstream job will run a little slower than before | ||
|
||
- Table | ||
|
||
Z-order has the good data clustering, so the compression ratio can be improved | ||
|
||
- Downstream | ||
|
||
Improve the downstream read performance benefit from data skipping. Since the parquet and orc file support collect data statistic automatically when you write data e.g. minimum and maximum values, the good data clustering let the pushed down filter more efficient | ||
|
||
### Supported table format | ||
|
||
| Table Format | Supported | | ||
|--------------|-----------| | ||
| parquet | Y | | ||
| orc | Y | | ||
| json | N | | ||
| csv | N | | ||
| text | N | | ||
|
||
### Supported column data type | ||
|
||
| Column Data Type | Supported | | ||
|------------------|-----------| | ||
| byte | Y | | ||
| short | Y | | ||
| int | Y | | ||
| long | Y | | ||
| float | Y | | ||
| double | Y | | ||
| boolean | Y | | ||
| string | Y | | ||
| decimal | Y | | ||
| date | Y | | ||
| timestamp | Y | | ||
| array | N | | ||
| map | N | | ||
| struct | N | | ||
| udt | N | | ||
|
||
## How to use | ||
|
||
This feature is inside Kyuubi extension, so you should apply the extension to Spark by following steps. | ||
|
||
- add extension jar: `copy $KYUUBI_HOME/extension/kyuubi-extension-spark-3-1* $SPARK_HOME/jars/` | ||
- add config into `spark-defaults.conf`: `spark.sql.extensions=org.apache.kyuubi.sql.KyuubiSparkSQLExtension` | ||
|
||
Due to the extension, z-order only works with Spark-3.1 and higher version. | ||
|
||
### Optimize history data | ||
|
||
If you want to optimize the history data of a table, the `OPTIMIZE ...` syntax is good to go. Due to Spark SQL doesn't support read and overwrite same datasource table, the syntax can only support to optimize Hive table. | ||
|
||
#### Syntax | ||
```sql | ||
OPTIMIZE table_name [WHERE predicate] ZORDER BY col_name1 [, ...] | ||
``` | ||
|
||
Note that, the `predicate` only supports partition spec. | ||
|
||
#### Examples | ||
```sql | ||
OPTIMIZE t1 ZORDER BY c3; | ||
|
||
OPTIMIZE t1 ZORDER BY c1,c2; | ||
|
||
OPTIMIZE t1 WHERE day = '2021-12-01' ZORDER BY c1,c2; | ||
``` | ||
|
||
### Optimize incremental data | ||
|
||
Kyuubi supports optimize a table automatically for incremental data. e.g., time partitioned table. The only things you need to do is adding Kyuubi properties into the target table properties: | ||
```sql | ||
ALTER TABLE t1 SET TBLPROPERTIES('kyuubi.zorder.enabled'='true','kyuubi.zorder.cols'='c1,c2'); | ||
``` | ||
- the key `kyuubi.zorder.enabled` decide if the table allows Kyuubi to optimize by z-order. | ||
- the key `kyuubi.zorder.cols` decide which columns are used to optimize by z-order. | ||
|
||
Kyuubi will detect the properties and optimize SQL using z-order during SQL compilation, so you can enjoy z-order with all writing table command like: | ||
|
||
```sql | ||
INSERT INTO TABLE t1 PARTITION() ...; | ||
|
||
INSERT OVERWRITE TABLE t1 PARTITION() ...; | ||
|
||
CREATE TABLE t1 AS SELECT ...; | ||
``` |
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.
Let describe the picture