Skip to content

Commit 091ab44

Browse files
CREATE NAMESPACE command and SupportsNamespaces
1 parent d0dba06 commit 091ab44

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

docs/connector/catalog/SupportsNamespaces.md

+34-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@
44

55
## Contract (Subset)
66

7-
### listNamespaces { #listNamespaces }
7+
### Create Namespace { #createNamespace }
8+
9+
```java
10+
void createNamespace(
11+
String[] namespace,
12+
Map<String, String> metadata)
13+
```
14+
15+
Creates a multi-part namespace in this catalog
16+
17+
Used when:
18+
19+
* `DelegatingCatalogExtension` is requested to [createNamespace](DelegatingCatalogExtension.md#createNamespace)
20+
* `CREATE NAMESPACE` command is executed
21+
22+
### List Namespaces { #listNamespaces }
823

924
```java
1025
String[][] listNamespaces()
@@ -17,7 +32,7 @@ Used when:
1732
* `DelegatingCatalogExtension` is requested to [listNamespaces](DelegatingCatalogExtension.md#listNamespaces)
1833
* `SHOW NAMESPACES` command is executed
1934

20-
### loadNamespaceMetadata { #loadNamespaceMetadata }
35+
### Load Namespace Metadata { #loadNamespaceMetadata }
2136

2237
```java
2338
Map<String, String> loadNamespaceMetadata(
@@ -33,6 +48,23 @@ Used when:
3348
* `DESCRIBE NAMESPACE` command is executed
3449
* `CatalogImpl` is requested to [getNamespace](../../CatalogImpl.md#getNamespace)
3550

51+
### Check If Namespace Exists { #namespaceExists }
52+
53+
```java
54+
boolean namespaceExists(
55+
String[] namespace)
56+
```
57+
58+
By default, `namespaceExists` tries to [load the namespace metadata](#loadNamespaceMetadata) in this catalog. For a successful load, `namespaceExists` is positive (`true`).
59+
60+
Used when:
61+
62+
* `CatalogManager` is requested to [setCurrentNamespace](CatalogManager.md#setCurrentNamespace)
63+
* `CatalogImpl` is requested to [databaseExists](../../CatalogImpl.md#databaseExists)
64+
* `DelegatingCatalogExtension` is requested to [namespaceExists](DelegatingCatalogExtension.md#namespaceExists)
65+
* `CREATE NAMESPACE` command is executed
66+
* `DROP NAMESPACE` command is executed
67+
3668
## Implementations
3769

3870
* [CatalogExtension](CatalogExtension.md)
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: CreateNamespace
3+
---
4+
5+
# CreateNamespace Unary Logical Operator
6+
7+
`CreateNamespace` is a unary logical operator (`UnaryCommand`) that represents the following high-level operator in logical query plans:
8+
9+
* [CREATE NAMESPACE](../sql/AstBuilder.md#visitCreateNamespace) SQL command
10+
11+
## Creating Instance
12+
13+
`CreateNamespace` takes the following to be created:
14+
15+
* <span id="name"> Name ([LogicalPlan](LogicalPlan.md))
16+
* <span id="ifNotExists"> `ifNotExists` flag
17+
* <span id="properties"> Properties (`Map[String, String]`)
18+
19+
`CreateNamespace` is created when:
20+
21+
* `AstBuilder` is requested to [parse CREATE NAMESPACE command](../sql/AstBuilder.md#visitCreateNamespace)
22+
23+
## Resolution Rules
24+
25+
`CreateNamespace` is resolved using the following resolution rules:
26+
27+
Resolution Rule | Operator
28+
-|-
29+
[ResolveSessionCatalog](../logical-analysis-rules/ResolveSessionCatalog.md) logical analysis rule for the [session catalog (`spark_catalog`)](../connector/catalog/CatalogV2Util.md#isSessionCatalog) | `CreateDatabaseCommand` logical command
30+
[DataSourceV2Strategy](../execution-planning-strategies/DataSourceV2Strategy.md) execution planning strategy | [CreateNamespaceExec](../physical-operators/CreateNamespaceExec.md) physical command
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: CreateNamespaceExec
3+
---
4+
5+
# CreateNamespaceExec Physical Command Operator
6+
7+
`CreateNamespaceExec` is a leaf [V2CommandExec](V2CommandExec.md) that represents [CreateNamespace](../logical-operators/CreateNamespace.md) logical operator at execution (for non-[session catalogs](../connector/catalog/CatalogV2Util.md#isSessionCatalog)).
8+
9+
## Executing Command { #run }
10+
11+
??? note "V2CommandExec"
12+
13+
```scala
14+
run(): Seq[InternalRow]
15+
```
16+
17+
`run` is part of the [V2CommandExec](V2CommandExec.md#run) abstraction.
18+
19+
`run` requests the given [SupportsNamespaces](../connector/catalog/SupportsNamespaces.md) catalog to [check if the multi-part namespace exists](../connector/catalog/SupportsNamespaces.md#namespaceExists).
20+
21+
Unless the namespace exists, `run` requests the [SupportsNamespaces](../connector/catalog/SupportsNamespaces.md) catalog to [create it](../connector/catalog/SupportsNamespaces.md#createNamespace) (with the `owner` property being the current user).

docs/sql/AstBuilder.md

+18
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ Used when:
109109
* [withSelectQuerySpecification](#withSelectQuerySpecification)
110110
* [withTransformQuerySpecification](#withTransformQuerySpecification)
111111

112+
### visitCreateNamespace { #visitCreateNamespace }
113+
114+
Creates a [CreateNamespace](../logical-operators/CreateNamespace.md) logical operator
115+
116+
```sql
117+
CREATE (NAMESPACE | DATABASE | SCHEMA) [IF NOT EXISTS] identifierReference
118+
[COMMENT comment]
119+
[LOCATION location]
120+
[WITH (DBPROPERTIES | PROPERTIES) propertyList]
121+
122+
identifierReference
123+
: IDENTIFIER_KW LEFT_PAREN expression RIGHT_PAREN
124+
| multipartIdentifier
125+
;
126+
```
127+
128+
ANTLR labeled alternative: `#createNamespace`
129+
112130
### visitCreateTable { #visitCreateTable }
113131

114132
Creates a [CreateTableAsSelect](../logical-operators/CreateTableAsSelect.md) (for CTAS queries with `AS` clause) or [CreateTable](../logical-operators/CreateTable.md) logical operator

0 commit comments

Comments
 (0)