forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-34918][table] Support
ALTER CATALOG COMMENT
syntax
- Loading branch information
1 parent
adfbbbd
commit 2385cc0
Showing
18 changed files
with
418 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
57 changes: 57 additions & 0 deletions
57
...link-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterCatalogComment.java
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,57 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.flink.sql.parser.ddl; | ||
|
||
import org.apache.calcite.sql.SqlIdentifier; | ||
import org.apache.calcite.sql.SqlNode; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
import org.apache.calcite.util.ImmutableNullableList; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** ALTER CATALOG catalog_name COMMENT 'comment'. */ | ||
public class SqlAlterCatalogComment extends SqlAlterCatalog { | ||
|
||
private final SqlNode comment; | ||
|
||
public SqlAlterCatalogComment( | ||
SqlParserPos position, SqlIdentifier catalogName, SqlNode comment) { | ||
super(position, catalogName); | ||
this.comment = requireNonNull(comment, "comment cannot be null"); | ||
} | ||
|
||
@Override | ||
public List<SqlNode> getOperandList() { | ||
return ImmutableNullableList.of(catalogName, comment); | ||
} | ||
|
||
public SqlNode getComment() { | ||
return comment; | ||
} | ||
|
||
@Override | ||
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { | ||
super.unparse(writer, leftPrec, rightPrec); | ||
writer.keyword("COMMENT"); | ||
comment.unparse(writer, leftPrec, rightPrec); | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
...ava/src/main/java/org/apache/flink/table/operations/ddl/AlterCatalogCommentOperation.java
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,70 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.flink.table.operations.ddl; | ||
|
||
import org.apache.flink.annotation.Internal; | ||
import org.apache.flink.table.api.ValidationException; | ||
import org.apache.flink.table.api.internal.TableResultImpl; | ||
import org.apache.flink.table.api.internal.TableResultInternal; | ||
import org.apache.flink.table.catalog.CatalogChange; | ||
import org.apache.flink.table.catalog.exceptions.CatalogException; | ||
import org.apache.flink.table.utils.EncodingUtils; | ||
|
||
import static org.apache.flink.util.Preconditions.checkNotNull; | ||
|
||
/** Operation to describe a ALTER CATALOG COMMENT statement. */ | ||
@Internal | ||
public class AlterCatalogCommentOperation implements AlterOperation { | ||
|
||
private final String catalogName; | ||
private final String comment; | ||
|
||
public AlterCatalogCommentOperation(String catalogName, String comment) { | ||
this.catalogName = checkNotNull(catalogName); | ||
this.comment = comment; | ||
} | ||
|
||
public String getCatalogName() { | ||
return catalogName; | ||
} | ||
|
||
public String getComment() { | ||
return comment; | ||
} | ||
|
||
@Override | ||
public String asSummaryString() { | ||
return String.format( | ||
"ALTER CATALOG %s COMMENT '%s'", | ||
catalogName, EncodingUtils.escapeSingleQuotes(comment)); | ||
} | ||
|
||
@Override | ||
public TableResultInternal execute(Context ctx) { | ||
try { | ||
ctx.getCatalogManager() | ||
.alterCatalog(catalogName, new CatalogChange.CatalogCommentChange(comment)); | ||
|
||
return TableResultImpl.TABLE_RESULT_OK; | ||
} catch (CatalogException e) { | ||
throw new ValidationException( | ||
String.format("Could not execute %s", asSummaryString()), e); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.