-
Notifications
You must be signed in to change notification settings - Fork 4.5k
SQL DDL documentation #37539
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
Open
ahmedabu98
wants to merge
6
commits into
apache:master
Choose a base branch
from
ahmedabu98:iceberg_getting_started
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+473
−11
Open
SQL DDL documentation #37539
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b52c85f
create catalog and iceberg table details
talatuyarer 092ea3e
Merge branch 'master' of https://github.com/ahmedabu98/beam into iceb…
ahmedabu98 257cd5a
add sql ddl website documentation
ahmedabu98 0d6ea98
add links
ahmedabu98 aa5d701
spotless
ahmedabu98 5ff507c
Merge branch 'master' of https://github.com/ahmedabu98/beam into iceb…
ahmedabu98 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
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
75 changes: 75 additions & 0 deletions
75
website/www/site/content/en/documentation/dsls/sql/ddl/alter.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,75 @@ | ||
| --- | ||
| type: languages | ||
| title: "Beam SQL DDL: Alter" | ||
| --- | ||
| <!-- | ||
| 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. | ||
| --> | ||
|
|
||
| # ALTER statements | ||
|
|
||
| The **ALTER** statement modifies the definition of an existing Catalog or Table. | ||
| For supported tables (like Iceberg), this enables **schema and partition evolution**. | ||
|
|
||
| ## ALTER CATALOG | ||
| Modifies an existing catalog's properties. | ||
|
|
||
| ```sql | ||
| ALTER CATALOG catalog_name | ||
| [ SET ( 'key' = 'val', ... ) ] | ||
| [ RESET ( 'key', ... ) ] | ||
| ``` | ||
| - **SET**: Adds new properties or updates existing ones. | ||
| - **RESET** / **UNSET**: Removes properties. | ||
|
|
||
| ## ALTER TABLE | ||
| Modifies an existing table's properties and evolves its partition and schema. | ||
|
|
||
| ```sql | ||
| ALTER TABLE table_name | ||
| [ ADD COLUMNS ( col_def, ... ) ] | ||
| [ DROP COLUMNS ( col_name, ... ) ] | ||
| [ ADD PARTITIONS ( partition_field, ... ) ] | ||
| [ DROP PARTITIONS ( partition_field, ... ) ] | ||
| [ SET ( 'key' = 'val', ... ) ] | ||
| [ ( RESET | UNSET ) ( 'key', ... ) ]; | ||
| ``` | ||
|
|
||
| *Example 1: Add or remove columns* | ||
| ```sql | ||
| -- Add columns | ||
| ALTER TABLE orders ADD COLUMNS ( | ||
| customer_email VARCHAR, | ||
| shipping_region VARCHAR | ||
| ); | ||
|
|
||
| -- Drop columns | ||
| ALTER TABLE orders DROP COLUMNS ( customer_email ); | ||
| ``` | ||
|
|
||
| *Example 2: Modify partition spec* | ||
| ```sql | ||
| -- Add a partition field | ||
| ALTER TABLE orders ADD PARTITIONS ( 'year(order_date)' ); | ||
|
|
||
| -- Remove a partition field | ||
| ALTER TABLE orders DROP PARTITIONS ( 'region_id' ); | ||
| ``` | ||
|
|
||
| *Example 3: Modify table properties* | ||
| ```sql | ||
| ALTER TABLE orders SET ( | ||
| 'write.format.default' = 'orc', | ||
| 'write.metadata.metrics.default' = 'full' ); | ||
| ALTER TABLE orders RESET ( 'write.target-file-size-bytes' ); | ||
| ``` |
120 changes: 120 additions & 0 deletions
120
website/www/site/content/en/documentation/dsls/sql/ddl/create.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,120 @@ | ||
| --- | ||
| type: languages | ||
| title: "Beam SQL DDL: Create" | ||
| --- | ||
| <!-- | ||
| 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. | ||
| --> | ||
|
|
||
| # CREATE statements | ||
|
|
||
| The **CREATE** command serves two potential functions depending on the connector: | ||
|
|
||
| - **Registration**: By default, it registers an existing external entity in the Beam SQL session. | ||
| - **Instantiation**: For supported connectors (e.g., Iceberg), it physically creates the entity | ||
| (e.g. namespace or table) in the underlying storage. | ||
|
|
||
| _**Note**: Creating a catalog or database does not automatically switch to it. Remember | ||
| to run [USE](/use) afterwards to set it as a default._ | ||
|
|
||
| ## `CREATE CATALOG` | ||
| Registers a new catalog instance. | ||
|
|
||
| ```sql | ||
| CREATE CATALOG [ IF NOT EXISTS ] catalog_name | ||
| TYPE 'type_name' | ||
| [ PROPERTIES ( 'key' = 'value' [, ...] ) ] | ||
| ``` | ||
|
|
||
| _**Example**: Creating a Hadoop Catalog (Local Storage)_ | ||
| ```sql | ||
| CREATE CATALOG local_catalog | ||
| TYPE iceberg | ||
| PROPERTIES ( | ||
| 'type' = 'hadoop', | ||
| 'warehouse' = 'file:///tmp/iceberg-warehouse' | ||
| ) | ||
| ``` | ||
|
|
||
| _**Example**: Registering a BigLake Catalog (GCS)_ | ||
| ```sql | ||
| CREATE CATALOG prod_iceberg | ||
| TYPE iceberg | ||
| PROPERTIES ( | ||
| 'type' = 'rest', | ||
| 'uri' = 'https://biglake.googleapis.com/iceberg/v1/restcatalog', | ||
| 'warehouse' = 'gs://my-company-bucket/warehouse', | ||
| 'header.x-goog-user-project' = 'my_prod_project', | ||
| 'rest.auth.type' = 'org.apache.iceberg.gcp.auth.GoogleAuthManager', | ||
| 'io-impl' = 'org.apache.iceberg.gcp.gcs.GCSFileIO', | ||
| 'rest-metrics-reporting-enabled' = 'false' | ||
| ); | ||
| ``` | ||
|
|
||
| ### `CREATE DATABASE` | ||
| Creates a new Database within the current Catalog (default), or the specified Catalog. | ||
| ```sql | ||
| CREATE DATABASE [ IF NOT EXISTS ] [ catalog_name. ]database_name; | ||
| ``` | ||
|
|
||
| _**Example**: Create a database in the current active catalog_ | ||
| ```sql | ||
| USE CATALOG my_catalog; | ||
| CREATE DATABASE sales_data; | ||
| ``` | ||
|
|
||
| _**Example**: Create a database in a specified catalog (must be registered)_ | ||
| ```sql | ||
| CREATE DATABASE other_catalog.sales_data; | ||
| ``` | ||
|
|
||
| ### `CREATE TABLE` | ||
| Creates a table within the currently active catalog and database. If the table name is fully qualified, the referenced database and catalog is used. | ||
|
|
||
| ```sql | ||
| CREATE EXTERNAL TABLE [ IF NOT EXISTS ] [ catalog. ][ db. ]table_name ( | ||
| col_name col_type [ NOT NULL ] [ COMMENT 'col_comment' ], | ||
| ... | ||
| ) | ||
| TYPE 'type_name' | ||
| [ PARTITIONED BY ( 'partition_field' [, ... ] ) ] | ||
| [ COMMENT 'table_comment' ] | ||
| [ LOCATION 'location_uri' ] | ||
| [ TBLPROPERTIES 'properties_json_string' ]; | ||
| ``` | ||
| - **TYPE**: the table type (e.g. `'iceberg'`, `'text'`, `'kafka'`) | ||
| - **PARTITIONED BY**: an ordered list of fields describing the partition spec. | ||
| - **LOCATION**: explicitly sets the location of the table (overriding the inferred `catalog.db.table_name` location) | ||
| - **TBLPROPERTIES**: configuration properties used when creating the table or setting up its IO connection. | ||
|
|
||
| _**Example**: Creating an Iceberg Table_ | ||
| ```sql | ||
| CREATE EXTERNAL TABLE prod_iceberg.sales_data.orders ( | ||
| order_id BIGINT NOT NULL COMMENT 'Unique order identifier', | ||
| amount DECIMAL(10, 2), | ||
| order_date TIMESTAMP, | ||
| region_id VARCHAR | ||
| ) | ||
| TYPE 'iceberg' | ||
| PARTITIONED BY ( 'region_id', 'day(order_date)' ) | ||
| COMMENT 'Daily sales transactions' | ||
| TBLPROPERTIES '{ | ||
| "write.format.default": "parquet", | ||
| "read.split.target-size": 268435456", | ||
| "beam.write.triggering_frequency_seconds": 60" | ||
| }'; | ||
| ``` | ||
| - This creates an Iceberg table named `orders` under the namespace `sales_data`, within the `prod_iceberg` catalog. | ||
| - The table is partitioned by `region_id`, then by the day value of `order_date` (using Iceberg's [hidden partitioning](https://iceberg.apache.org/docs/latest/partitioning/#icebergs-hidden-partitioning)). | ||
| - The table is created with the appropriate properties `"write.format.default"` and `"read.split.target-size"`. The Beam property `"beam.write.triggering_frequency_seconds"` | ||
| - Beam properties (prefixed with `"beam.write."` and `"beam.read."` are intended for the relevant IOs) | ||
50 changes: 50 additions & 0 deletions
50
website/www/site/content/en/documentation/dsls/sql/ddl/drop.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,50 @@ | ||
| --- | ||
| type: languages | ||
| title: "Beam SQL DDL: Drop" | ||
| --- | ||
| <!-- | ||
| 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. | ||
| --> | ||
|
|
||
| # DROP statements | ||
| The **DROP** command serves two potential functions depending on the connector: | ||
|
|
||
| - **Unregistration**: unregisters an entity from the current Beam SQL session. | ||
| - **Deletion**: For supported connectors (like **Iceberg**), it **physically deletes** the entity | ||
| (e.g. namespace or table) in the underlying storage. | ||
|
|
||
| **Caution:** Physical deletion can be permanent | ||
|
|
||
| ## DROP CATALOG | ||
| Unregisters a catalog from Beam SQL. This does not destroy external data, only the link within the SQL session. | ||
|
|
||
| ```sql | ||
| DROP CATALOG [ IF EXISTS ] catalog_name; | ||
| ``` | ||
|
|
||
| ## DROP DATABASE | ||
| Unregisters a database from the current session. For supported connectors, this | ||
| will also **delete** the database from the external data source. | ||
|
|
||
| ```sql | ||
| DROP DATABASE [ IF EXISTS ] database_name [ RESTRICT | CASCADE ]; | ||
| ``` | ||
| - **RESTRICT** (Default): Fails if the database is not empty. | ||
| - **CASCADE**: Drops the database and all tables contained within it. **Use with caution.** | ||
|
|
||
| ## DROP TABLE | ||
| Unregisters a table from the current session. For supported connectors, this | ||
| will also **delete** the table from the external data source. | ||
| ```sql | ||
| DROP TABLE [ IF EXISTS ] table_name; | ||
| ``` |
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.
We can use rest.auth.type='google' We dont need to give fullname of class.