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-24939][table] Introduce "SHOW CREATE CATALOG" Syntax
- Loading branch information
1 parent
7d0111d
commit b2d161b
Showing
10 changed files
with
215 additions
and
8 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
67 changes: 67 additions & 0 deletions
67
.../flink-sql-parser/src/main/java/org/apache/flink/sql/parser/dql/SqlShowCreateCatalog.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,67 @@ | ||
/* | ||
* 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.dql; | ||
|
||
import org.apache.calcite.sql.SqlIdentifier; | ||
import org.apache.calcite.sql.SqlKind; | ||
import org.apache.calcite.sql.SqlNode; | ||
import org.apache.calcite.sql.SqlOperator; | ||
import org.apache.calcite.sql.SqlSpecialOperator; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** SHOW CREATE CATALOG sql call. */ | ||
public class SqlShowCreateCatalog extends SqlShowCreate { | ||
|
||
public static final SqlSpecialOperator OPERATOR = | ||
new SqlSpecialOperator("SHOW CREATE CATALOG", SqlKind.OTHER_DDL); | ||
|
||
protected final SqlIdentifier catalogName; | ||
|
||
public SqlShowCreateCatalog(SqlParserPos pos, SqlIdentifier catalogName) { | ||
super(pos, catalogName); | ||
this.catalogName = catalogName; | ||
} | ||
|
||
public String[] getCatalogName() { | ||
return Objects.isNull(this.catalogName) | ||
? new String[] {} | ||
: catalogName.names.toArray(new String[0]); | ||
} | ||
|
||
@Override | ||
public SqlOperator getOperator() { | ||
return OPERATOR; | ||
} | ||
|
||
@Override | ||
public List<SqlNode> getOperandList() { | ||
return Collections.singletonList(sqlIdentifier); | ||
} | ||
|
||
@Override | ||
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { | ||
writer.keyword("SHOW CREATE CATALOG"); | ||
sqlIdentifier.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
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
65 changes: 65 additions & 0 deletions
65
...-api-java/src/main/java/org/apache/flink/table/operations/ShowCreateCatalogOperation.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,65 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.flink.annotation.Internal; | ||
import org.apache.flink.table.api.ValidationException; | ||
import org.apache.flink.table.api.internal.ShowCreateUtil; | ||
import org.apache.flink.table.api.internal.TableResultInternal; | ||
import org.apache.flink.table.catalog.CatalogDescriptor; | ||
|
||
import static org.apache.flink.table.api.internal.TableResultUtils.buildStringArrayResult; | ||
import static org.apache.flink.util.Preconditions.checkNotNull; | ||
|
||
/** Operation to describe a SHOW CREATE CATALOG statement. */ | ||
@Internal | ||
public class ShowCreateCatalogOperation implements ShowOperation { | ||
|
||
private final String catalogName; | ||
|
||
public ShowCreateCatalogOperation(String catalogName) { | ||
this.catalogName = checkNotNull(catalogName, "Catalog name must not be null"); | ||
} | ||
|
||
public String getCatalogName() { | ||
return catalogName; | ||
} | ||
|
||
@Override | ||
public String asSummaryString() { | ||
return String.format("SHOW CREATE CATALOG %s", catalogName); | ||
} | ||
|
||
@Override | ||
public TableResultInternal execute(Context ctx) { | ||
CatalogDescriptor catalogDescriptor = | ||
ctx.getCatalogManager() | ||
.getCatalogStore() | ||
.getCatalog(catalogName) | ||
.orElseThrow( | ||
() -> | ||
new ValidationException( | ||
String.format( | ||
"Cannot obtain metadata from Catalog %s.", | ||
catalogName))); | ||
String resultRow = ShowCreateUtil.buildShowCreateCatalogRow(catalogDescriptor); | ||
|
||
return buildStringArrayResult("result", new String[] {resultRow}); | ||
} | ||
} |
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