Skip to content
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

Utilize Metadata.isView in more places #20771

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;

import static com.google.common.util.concurrent.Futures.immediateVoidFuture;
import static io.trino.metadata.MetadataUtil.createQualifiedObjectName;
Expand Down Expand Up @@ -116,7 +117,7 @@ private void commentOnTable(Comment statement, Session session)
private void commentOnView(Comment statement, Session session)
{
QualifiedObjectName viewName = createQualifiedObjectName(session, statement, statement.getName());
if (metadata.getView(session, viewName).isEmpty()) {
if (!metadata.isView(session, viewName)) {
String additionalInformation;
if (metadata.getMaterializedView(session, viewName).isPresent()) {
additionalInformation = ", but a materialized view with that name exists. Setting comments on materialized views is unsupported.";
Expand All @@ -140,8 +141,9 @@ private void commentOnColumn(Comment statement, Session session)
.orElseThrow(() -> semanticException(MISSING_TABLE, statement, "Table must be specified"));

QualifiedObjectName originalObjectName = createQualifiedObjectName(session, statement, prefix);
if (metadata.isView(session, originalObjectName)) {
ViewDefinition viewDefinition = metadata.getView(session, originalObjectName).get();
Optional<ViewDefinition> view = metadata.getView(session, originalObjectName);
if (view.isPresent()) {
ViewDefinition viewDefinition = view.get();
ViewColumn viewColumn = findAndCheckViewColumn(statement, session, viewDefinition, originalObjectName);
metadata.setViewColumnComment(session, originalObjectName, viewColumn.getName(), statement.getComment());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ListenableFuture<Void> execute(
if (metadata.getMaterializedView(session, tableName).isPresent()) {
exceptionMessage += ", but a materialized view with that name exists.";
}
else if (metadata.getView(session, tableName).isPresent()) {
else if (metadata.isView(session, tableName)) {
exceptionMessage += ", but a view with that name exists.";
}
if (!statement.isTableExists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ListenableFuture<Void> execute(
if (metadata.getMaterializedView(session, qualifiedObjectName).isPresent()) {
exceptionMessage += ", but a materialized view with that name exists.";
}
else if (metadata.getView(session, qualifiedObjectName).isPresent()) {
else if (metadata.isView(session, qualifiedObjectName)) {
exceptionMessage += ", but a view with that name exists.";
}
if (!statement.isTableExists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void setMaterializedViewProperties(
{
if (plannerContext.getMetadata().getMaterializedView(session, materializedViewName).isEmpty()) {
String additionalInformation;
if (plannerContext.getMetadata().getView(session, materializedViewName).isPresent()) {
if (plannerContext.getMetadata().isView(session, materializedViewName)) {
additionalInformation = ", but a view with that name exists.";
}
else if (plannerContext.getMetadata().getTableHandle(session, materializedViewName).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ListenableFuture<Void> execute(
Session session = stateMachine.getSession();
QualifiedObjectName viewName = createQualifiedObjectName(session, statement, statement.getSource());
getRequiredCatalogHandle(metadata, session, statement, viewName.getCatalogName());
if (metadata.getView(session, viewName).isEmpty()) {
if (!metadata.isView(session, viewName)) {
throw semanticException(TABLE_NOT_FOUND, statement, "View '%s' does not exist", viewName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,9 +1340,9 @@ public List<QualifiedObjectName> listViews(Session session, QualifiedTablePrefix

Optional<QualifiedObjectName> objectName = prefix.asQualifiedObjectName();
if (objectName.isPresent()) {
return getView(session, objectName.get())
.map(handle -> ImmutableList.of(objectName.get()))
.orElseGet(ImmutableList::of);
return isView(session, objectName.get())
? ImmutableList.of(objectName.get())
: ImmutableList.of();
}

Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Expand Down
Loading