Skip to content

Commit

Permalink
add alter database doc for flink and spark and support comment when c…
Browse files Browse the repository at this point in the history
…reate database in flink
  • Loading branch information
jerry-024 committed Dec 16, 2024
1 parent f7a2e15 commit 6b77e13
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
8 changes: 8 additions & 0 deletions docs/content/flink/sql-alter.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,11 @@ The following SQL modifies the watermark strategy to `ts - INTERVAL '2' HOUR`.
```sql
ALTER TABLE my_table MODIFY WATERMARK FOR ts AS ts - INTERVAL '2' HOUR
```

# ALTER DATABASE

The following SQL sets one or more properties in the specified database. If a particular property is already set in the database, override the old value with the new one.

```sql
ALTER DATABASE [catalog_name.]db_name SET (key1=val1, key2=val2, ...)
```
10 changes: 10 additions & 0 deletions docs/content/spark/sql-alter.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,13 @@ The following SQL changes the type of a nested column `f2` to `BIGINT` in a stru
-- column v previously has type MAP<INT, STRUCT<f1: STRING, f2: INT>>
ALTER TABLE my_table ALTER COLUMN v.value.f2 TYPE BIGINT;
```


# ALTER DATABASE

The following SQL sets one or more properties in the specified database. If a particular property is already set in the database, override the old value with the new one.

```sql
ALTER { DATABASE | SCHEMA | NAMESPACE } my_database
SET { DBPROPERTIES | PROPERTIES } ( property_name = property_value [ , ... ] )
```
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@ public CatalogDatabase getDatabase(String databaseName)
@Override
public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
throws DatabaseAlreadyExistException, CatalogException {
Map<String, String> properties;
if (database != null) {
properties = new HashMap<>(database.getProperties());
if (database.getDescription().isPresent()
&& !database.getDescription().get().equals("")) {
throw new UnsupportedOperationException(
"Create database with description is unsupported.");
properties.put(Catalog.COMMENT_PROP, database.getDescription().get());
}
} else {
properties = Collections.emptyMap();
}

try {
catalog.createDatabase(
name,
ignoreIfExists,
database == null ? Collections.emptyMap() : database.getProperties());
catalog.createDatabase(name, ignoreIfExists, properties);
} catch (Catalog.DatabaseAlreadyExistException e) {
throw new DatabaseAlreadyExistException(getName(), e.database());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatCollection;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
Expand Down Expand Up @@ -581,11 +582,9 @@ public void testCreateDb_DatabaseWithProperties() throws Exception {
}

@Test
public void testCreateDb_DatabaseWithCommentException() {
public void testCreateDb_DatabaseWithCommentSuccessful() throws DatabaseAlreadyExistException {
CatalogDatabaseImpl database = new CatalogDatabaseImpl(Collections.emptyMap(), "haha");
assertThatThrownBy(() -> catalog.createDatabase(path1.getDatabaseName(), database, false))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Create database with description is unsupported.");
assertDoesNotThrow(() -> catalog.createDatabase(path1.getDatabaseName(), database, false));
}

@ParameterizedTest
Expand All @@ -612,6 +611,8 @@ public void testAlterDb() throws DatabaseAlreadyExistException, DatabaseNotExist
catalog.createDatabase(path1.getDatabaseName(), database, false);
Map<String, String> properties = Collections.singletonMap("haa", "ccc");
CatalogDatabaseImpl newDatabase = new CatalogDatabaseImpl(properties, "haha");
// as file system catalog don't support alter database, so we have to use mock to overview
// this method to test
Catalog mockCatalog = spy(catalog);
doNothing().when(mockCatalog).alterDatabase(path1.getDatabaseName(), newDatabase, false);
when(mockCatalog.getDatabase(path1.getDatabaseName())).thenReturn(database);
Expand Down

0 comments on commit 6b77e13

Please sign in to comment.