Skip to content

Commit

Permalink
Throw TrinoException for invalid column
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo committed Nov 11, 2024
1 parent 396d312 commit 79df77e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.trino.spi.StandardErrorCode.INVALID_COLUMN_PROPERTY;
import static io.trino.spi.StandardErrorCode.INVALID_COLUMN_REFERENCE;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.StandardErrorCode.SCHEMA_ALREADY_EXISTS;
import static io.trino.spi.StandardErrorCode.SCHEMA_NOT_FOUND;
Expand Down Expand Up @@ -263,7 +264,7 @@ public synchronized void setColumnComment(ConnectorSession session, ConnectorTab
.map(columnInfo -> {
if (columnInfo.handle().equals(column)) {
if (ROW_ID_COLUMN_NAME.equals(columnInfo.handle().name())) {
throw new IllegalArgumentException(String.format("Cannot set comment for %s column", ROW_ID_COLUMN_NAME));
throw new TrinoException(INVALID_COLUMN_REFERENCE, "Cannot set comment for %s column".formatted(ROW_ID_COLUMN_NAME));
}
return columnInfo.withComment(comment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.Test;

import static io.trino.plugin.faker.FakerSplitManager.MAX_ROWS_PER_SPLIT;
import static io.trino.spi.StandardErrorCode.INVALID_COLUMN_REFERENCE;
import static org.assertj.core.api.Assertions.assertThat;

final class TestFakerQueries
Expand Down Expand Up @@ -54,7 +55,8 @@ void testCannotCommentRowId()
{
try (TestTable table = new TestTable(getQueryRunner()::execute, "cannot_comment", "(id INTEGER, name VARCHAR)")) {
assertThat(query("COMMENT ON COLUMN \"%s\".\"$row_id\" IS 'comment text'".formatted(table.getName())))
.nonTrinoExceptionFailure()
.failure()
.hasErrorCode(INVALID_COLUMN_REFERENCE)
.hasMessageContaining("Cannot set comment for $row_id column");
}
}
Expand Down

0 comments on commit 79df77e

Please sign in to comment.