-
Notifications
You must be signed in to change notification settings - Fork 70
feat: support ddl for branch operation #576
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
Merged
Merged
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
This file contains hidden or 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 hidden or 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,101 @@ | ||
| # CREATE BRANCH | ||
|
|
||
| Create a named branch for a Lance table. | ||
|
|
||
| !!! warning "Spark Extension Required" | ||
| This feature requires the Lance Spark SQL extension to be enabled. See [Spark SQL Extensions](../../config.md#spark-sql-extensions) for configuration details. | ||
|
|
||
| ## Overview | ||
|
|
||
| The `CREATE BRANCH` command creates a new branch that points to a specific table state. A branch can be created from: | ||
|
|
||
| - the latest version of `main` | ||
| - a specific version on `main` | ||
| - the head of another branch | ||
| - a specific version on another branch | ||
| - a tag | ||
|
|
||
| Creating a branch records a new reference in table metadata. It does not duplicate the table's data files. | ||
|
|
||
| ## Syntax | ||
|
|
||
| === "SQL" | ||
|
|
||
| ```sql | ||
| ALTER TABLE <table> CREATE BRANCH [IF NOT EXISTS] <branch_name>; | ||
|
|
||
| ALTER TABLE <table> CREATE BRANCH [IF NOT EXISTS] <branch_name> | ||
| AS OF VERSION <version>; | ||
|
|
||
| ALTER TABLE <table> CREATE BRANCH [IF NOT EXISTS] <branch_name> | ||
| AS OF BRANCH <source_branch>; | ||
|
|
||
| ALTER TABLE <table> CREATE BRANCH [IF NOT EXISTS] <branch_name> | ||
| AS OF BRANCH <source_branch> VERSION <version>; | ||
|
|
||
| ALTER TABLE <table> CREATE BRANCH [IF NOT EXISTS] <branch_name> | ||
| AS OF TAG <tag_name>; | ||
| ``` | ||
|
|
||
| If the `AS OF` clause is omitted, the new branch is created from the latest version of `main`. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Create a branch from the latest `main` | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| ALTER TABLE lance.db.users CREATE BRANCH feature_x; | ||
| ``` | ||
|
|
||
| ### Create a branch from a specific `main` version | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| ALTER TABLE lance.db.users CREATE BRANCH IF NOT EXISTS snapshot_v5 | ||
| AS OF VERSION 5; | ||
| ``` | ||
|
|
||
| ### Create a branch from another branch head | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| ALTER TABLE lance.db.users CREATE BRANCH experiment_b | ||
| AS OF BRANCH experiment_a; | ||
| ``` | ||
|
|
||
| ### Create a branch from a specific version on another branch | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| ALTER TABLE lance.db.users CREATE BRANCH experiment_b_v3 | ||
| AS OF BRANCH experiment_a VERSION 3; | ||
| ``` | ||
|
|
||
| ### Create a branch from a tag | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| ALTER TABLE lance.db.users CREATE BRANCH release_fix | ||
| AS OF TAG release_candidate; | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| The `CREATE BRANCH` command returns: | ||
|
|
||
| | Column | Type | Description | | ||
| |--------|--------|----------------------------| | ||
| | `name` | String | The name of the new branch | | ||
|
|
||
| ## Notes and Limitations | ||
|
|
||
| - `CREATE BRANCH` is implemented as a Spark SQL extension command. | ||
| - The referenced table must be a Lance table. | ||
| - Creating a branch from a non-existent branch, tag, or version returns an error. | ||
| - The branch name is returned even when the command result contains only a single row. | ||
|
|
||
| ## See Also | ||
|
|
||
| - [SHOW BRANCHES](./show-branches.md) | ||
| - [DROP BRANCH](./drop-branch.md) | ||
This file contains hidden or 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,44 @@ | ||
| # DROP BRANCH | ||
|
|
||
| Remove a branch from a Lance table. | ||
|
|
||
| !!! warning "Spark Extension Required" | ||
| This feature requires the Lance Spark SQL extension to be enabled. See [Spark SQL Extensions](../../config.md#spark-sql-extensions) for configuration details. | ||
|
|
||
| ## Overview | ||
|
|
||
| The `DROP BRANCH` command deletes a named branch reference from a Lance table. This removes the branch metadata entry, but does not rewrite data on `main` or on any other existing branch. | ||
|
|
||
| ## Syntax | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| ALTER TABLE <table> DROP BRANCH [IF EXISTS] <branch_name>; | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| ALTER TABLE lance.db.users DROP BRANCH IF EXISTS feature_x; | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| The `DROP BRANCH` command returns: | ||
|
|
||
| | Column | Type | Description | | ||
| |--------|--------|--------------------------------| | ||
| | `name` | String | The name of the dropped branch | | ||
|
|
||
| ## Notes and Limitations | ||
|
|
||
| - `DROP BRANCH` is implemented as a Spark SQL extension command. | ||
| - The target table must be a Lance table. | ||
| - `IF EXISTS` can be used when dropping a branch conditionally. | ||
| - Use [SHOW BRANCHES](./show-branches.md) to inspect existing branches before deleting one. | ||
|
|
||
| ## See Also | ||
|
|
||
| - [CREATE BRANCH](./create-branch.md) | ||
| - [SHOW BRANCHES](./show-branches.md) |
This file contains hidden or 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,62 @@ | ||
| # SHOW BRANCHES | ||
|
|
||
| List branches defined on a Lance table. | ||
|
|
||
| !!! warning "Spark Extension Required" | ||
| This feature requires the Lance Spark SQL extension to be enabled. See [Spark SQL Extensions](../../config.md#spark-sql-extensions) for configuration details. | ||
|
|
||
| ## Overview | ||
|
|
||
| The `SHOW BRANCHES` command returns one row for each branch on a Lance table. It is useful for inspecting branch lineage, verifying branch creation, and understanding which version each branch points to. | ||
|
|
||
| ## Syntax | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| SHOW BRANCHES FROM <table>; | ||
| SHOW BRANCHES IN <table>; | ||
| SHOW BRANCH FROM <table>; | ||
| SHOW BRANCH IN <table>; | ||
| ``` | ||
|
|
||
| Both plural and singular forms are accepted. Both `FROM` and `IN` are accepted. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### List all branches on a table | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| SHOW BRANCHES FROM lance.db.users; | ||
| ``` | ||
|
|
||
| ### Use the singular alias | ||
|
|
||
| === "SQL" | ||
| ```sql | ||
| SHOW BRANCH IN lance.db.users; | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| The `SHOW BRANCHES` command returns the following columns: | ||
|
|
||
| | Column | Type | Description | | ||
| |--------|------|----------------------------------------------------------------------------------| | ||
| | `name` | String | Branch name | | ||
| | `parent_branch` | String | Source branch name if the branch was created from another branch; otherwise NULL | | ||
| | `parent_version` | Long | Version used as the branch starting point | | ||
| | `created_at` | Long | Branch creation timestamp as returned by Lance metadata | | ||
| | `manifest_size` | Integer | Manifest size recorded for the branch | | ||
|
|
||
| ## Notes | ||
|
|
||
| - `SHOW BRANCHES` is implemented as a Spark SQL extension command. | ||
| - The target table must be a Lance table. | ||
| - The result includes one row per branch currently registered in the table metadata. | ||
| - Use [CREATE BRANCH](./create-branch.md) to add a branch and [DROP BRANCH](./drop-branch.md) to remove one. | ||
|
|
||
| ## See Also | ||
|
|
||
| - [CREATE BRANCH](./create-branch.md) | ||
| - [DROP BRANCH](./drop-branch.md) |
This file contains hidden or 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
16 changes: 16 additions & 0 deletions
16
lance-spark-3.4_2.12/src/test/java/org/lance/spark/branch/BranchDDLTest.java
This file contains hidden or 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,16 @@ | ||
| /* | ||
| * Licensed 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. | ||
| */ | ||
| package org.lance.spark.branch; | ||
|
|
||
| public class BranchDDLTest extends BaseBranchDDLTest {} |
This file contains hidden or 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.
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.
Lacks corresponding test cases
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.
BaseBranchDDLTest's three corresponding test cases are added.