-
Notifications
You must be signed in to change notification settings - Fork 14k
[FLINK-38262][table] show create connection operation #28791
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
Shekharrajak
wants to merge
3
commits into
apache:master
Choose a base branch
from
Shekharrajak:FLINK-38262-show-create-connection-operation
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.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0b21c6e
[FLINK-38262][table] Add SHOW CREATE CONNECTION operation
Shekharrajak 2f7431a
Update flink-table/flink-table-api-java/src/main/java/org/apache/flin…
Shekharrajak 426a7cd
Update flink-table/flink-table-api-java/src/main/java/org/apache/flin…
Shekharrajak 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import org.apache.flink.table.api.TableException; | ||
| import org.apache.flink.table.catalog.CatalogBaseTable; | ||
| import org.apache.flink.table.catalog.CatalogBaseTable.TableKind; | ||
| import org.apache.flink.table.catalog.CatalogConnection; | ||
| import org.apache.flink.table.catalog.CatalogDescriptor; | ||
| import org.apache.flink.table.catalog.CatalogView; | ||
| import org.apache.flink.table.catalog.Column; | ||
|
|
@@ -64,6 +65,7 @@ public class ShowCreateUtil { | |
| private static final DateTimeFormatter TIMESTAMP_FORMATTER = | ||
| DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss"); | ||
| private static final String PRINT_INDENT = " "; | ||
| private static final String CONNECTION_SECRET_REFERENCE_KEY = "__flink.encrypted-secret-key__"; | ||
|
|
||
| private ShowCreateUtil() {} | ||
|
|
||
|
|
@@ -98,6 +100,29 @@ public static String buildShowCreateModelRow( | |
| return sb.toString(); | ||
| } | ||
|
|
||
| public static String buildShowCreateConnectionRow( | ||
| CatalogConnection connection, | ||
| ObjectIdentifier connectionIdentifier, | ||
| boolean isTemporary, | ||
| List<String> additionalSensitiveKeys) { | ||
| StringBuilder sb = | ||
| new StringBuilder() | ||
| .append( | ||
| buildCreateFormattedPrefix( | ||
| "CONNECTION", | ||
| isTemporary, | ||
| connectionIdentifier, | ||
| false, | ||
| false)); | ||
| extractComment(connection).ifPresent(c -> sb.append(formatComment(c)).append("\n")); | ||
| extractFormattedOptions( | ||
| withoutConnectionInternalOptions(connection.getOptions()), | ||
| PRINT_INDENT, | ||
| additionalSensitiveKeys) | ||
| .ifPresent(v -> sb.append("WITH (\n").append(v).append("\n)\n")); | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| public static String buildShowCreateTableRow( | ||
| ResolvedCatalogBaseTable<?> table, | ||
| ObjectIdentifier tableIdentifier, | ||
|
|
@@ -349,6 +374,18 @@ static Optional<String> extractComment(ResolvedCatalogModel model) { | |
| : Optional.of(model.getComment()); | ||
| } | ||
|
|
||
| static Optional<String> extractComment(CatalogConnection connection) { | ||
| return StringUtils.isEmpty(connection.getComment()) | ||
| ? Optional.empty() | ||
| : Optional.of(connection.getComment()); | ||
| } | ||
|
|
||
| static Map<String, String> withoutConnectionInternalOptions(Map<String, String> options) { | ||
| return options.entrySet().stream() | ||
| .filter(entry -> !CONNECTION_SECRET_REFERENCE_KEY.equals(entry.getKey())) | ||
| .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
| } | ||
|
Comment on lines
+377
to
+387
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can be private |
||
|
|
||
| static Optional<String> extractFormattedDistributedInfo(ResolvedCatalogTable catalogTable) { | ||
| return catalogTable.getDistribution().map(TableDistribution::toString); | ||
| } | ||
|
|
||
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
54 changes: 54 additions & 0 deletions
54
...able-api-java/src/main/java/org/apache/flink/table/catalog/ContextResolvedConnection.java
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,54 @@ | ||
| /* | ||
| * 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.catalog; | ||
|
|
||
| import org.apache.flink.annotation.Internal; | ||
|
|
||
| /** Contextual metadata for a resolved connection. */ | ||
| @Internal | ||
| public final class ContextResolvedConnection { | ||
|
|
||
| private final ObjectIdentifier identifier; | ||
| private final CatalogConnection connection; | ||
| private final boolean temporary; | ||
|
|
||
| private ContextResolvedConnection( | ||
| ObjectIdentifier identifier, CatalogConnection connection, boolean temporary) { | ||
| this.identifier = identifier; | ||
| this.connection = connection; | ||
| this.temporary = temporary; | ||
| } | ||
|
|
||
| public static ContextResolvedConnection of( | ||
| ObjectIdentifier identifier, CatalogConnection connection, boolean temporary) { | ||
| return new ContextResolvedConnection(identifier, connection, temporary); | ||
| } | ||
|
|
||
| public ObjectIdentifier getIdentifier() { | ||
| return identifier; | ||
| } | ||
|
|
||
| public CatalogConnection getConnection() { | ||
| return connection; | ||
| } | ||
|
|
||
| public boolean isTemporary() { | ||
| return temporary; | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
...i-java/src/main/java/org/apache/flink/table/operations/ShowCreateConnectionOperation.java
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,74 @@ | ||
| /* | ||
| * 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.configuration.SecurityOptions; | ||
| import org.apache.flink.table.api.internal.ShowCreateUtil; | ||
| import org.apache.flink.table.api.internal.TableResultInternal; | ||
| import org.apache.flink.table.catalog.CatalogConnection; | ||
| import org.apache.flink.table.catalog.ObjectIdentifier; | ||
|
|
||
| import static org.apache.flink.table.api.internal.TableResultUtils.buildStringArrayResult; | ||
|
|
||
| /** Operation to describe a SHOW CREATE CONNECTION statement. */ | ||
| @Internal | ||
| public class ShowCreateConnectionOperation implements ShowOperation { | ||
|
|
||
| private final ObjectIdentifier connectionIdentifier; | ||
| private final CatalogConnection connection; | ||
| private final boolean isTemporary; | ||
|
|
||
| public ShowCreateConnectionOperation( | ||
| ObjectIdentifier connectionIdentifier, | ||
| CatalogConnection connection, | ||
| boolean isTemporary) { | ||
| this.connectionIdentifier = connectionIdentifier; | ||
| this.connection = connection; | ||
| this.isTemporary = isTemporary; | ||
| } | ||
|
|
||
| public ObjectIdentifier getConnectionIdentifier() { | ||
| return connectionIdentifier; | ||
| } | ||
|
|
||
| public CatalogConnection getConnection() { | ||
| return connection; | ||
| } | ||
|
|
||
| public boolean isTemporary() { | ||
| return isTemporary; | ||
| } | ||
|
|
||
| @Override | ||
| public String asSummaryString() { | ||
| return String.format("SHOW CREATE CONNECTION %s", connectionIdentifier.asSummaryString()); | ||
| } | ||
|
|
||
| @Override | ||
| public TableResultInternal execute(Context ctx) { | ||
| String resultRow = | ||
| ShowCreateUtil.buildShowCreateConnectionRow( | ||
| connection, | ||
| connectionIdentifier, | ||
| isTemporary, | ||
| ctx.getTableConfig().get(SecurityOptions.ADDITIONAL_SENSITIVE_KEYS)); | ||
| return buildStringArrayResult("result", new String[] {resultRow}); | ||
| } | ||
| } |
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
55 changes: 55 additions & 0 deletions
55
...rg/apache/flink/table/planner/operations/converters/SqlShowCreateConnectionConverter.java
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,55 @@ | ||
| /* | ||
| * 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.planner.operations.converters; | ||
|
|
||
| import org.apache.flink.sql.parser.dql.SqlShowCreateConnection; | ||
| import org.apache.flink.table.api.ValidationException; | ||
| import org.apache.flink.table.catalog.ContextResolvedConnection; | ||
| import org.apache.flink.table.catalog.ObjectIdentifier; | ||
| import org.apache.flink.table.catalog.UnresolvedIdentifier; | ||
| import org.apache.flink.table.operations.Operation; | ||
| import org.apache.flink.table.operations.ShowCreateConnectionOperation; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| /** A converter for {@link SqlShowCreateConnection}. */ | ||
| public class SqlShowCreateConnectionConverter implements SqlNodeConverter<SqlShowCreateConnection> { | ||
|
|
||
| @Override | ||
| public Operation convertSqlNode( | ||
| SqlShowCreateConnection showCreateConnection, ConvertContext context) { | ||
| UnresolvedIdentifier unresolvedIdentifier = | ||
| UnresolvedIdentifier.of(showCreateConnection.getConnectionName().names); | ||
| ObjectIdentifier identifier = | ||
| context.getCatalogManager().qualifyIdentifier(unresolvedIdentifier); | ||
| Optional<ContextResolvedConnection> connection = | ||
| context.getCatalogManager().getResolvedConnection(identifier); | ||
|
|
||
| if (connection.isEmpty()) { | ||
| throw new ValidationException( | ||
| String.format( | ||
| "Could not execute SHOW CREATE CONNECTION. Connection with identifier %s does not exist.", | ||
| identifier.asSerializableString())); | ||
| } | ||
|
|
||
| ContextResolvedConnection resolvedConnection = connection.get(); | ||
| return new ShowCreateConnectionOperation( | ||
| identifier, resolvedConnection.getConnection(), resolvedConnection.isTemporary()); | ||
| } | ||
| } |
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
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.
Can you elaborate what this const is? Maybe add a one line comment why we filtering it out.