diff --git a/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/BaseBigQueryConnectorTest.java b/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/BaseBigQueryConnectorTest.java index 3e3522fb7faf..2d1a9439cf89 100644 --- a/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/BaseBigQueryConnectorTest.java +++ b/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/BaseBigQueryConnectorTest.java @@ -234,7 +234,7 @@ protected Optional filterCaseSensitiveDataMappingTestData( @Override protected boolean isColumnNameRejected(Exception exception, String columnName, boolean delimited) { - return nullToEmpty(exception.getMessage()).matches(".*(Fields must contain only letters, numbers, and underscores, start with a letter or underscore, and be at most 300 characters long).*"); + return nullToEmpty(exception.getMessage()).matches(".*Invalid field name \"%s\". Fields must contain the allowed characters, and be at most 300 characters long..*".formatted(columnName.replace("\\", "\\\\"))); } @Test diff --git a/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryAvroConnectorTest.java b/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryAvroConnectorTest.java index 15ebcc2af21a..e1e5cbd9b81b 100644 --- a/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryAvroConnectorTest.java +++ b/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryAvroConnectorTest.java @@ -14,11 +14,32 @@ package io.trino.plugin.bigquery; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import io.trino.testing.QueryRunner; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.Optional; +import java.util.Set; + +import static io.trino.testing.DataProviders.toDataProvider; +import static io.trino.testing.TestingNames.randomNameSuffix; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class TestBigQueryAvroConnectorTest extends BaseBigQueryConnectorTest { + private static final Set UNSUPPORTED_COLUMN_NAMES = ImmutableSet.builder() + .add("a-hyphen-minus") + .add("a space") + .add("atrailingspace ") + .add(" aleadingspace") + .add("a:colon") + .add("an'apostrophe") + .add("0startwithdigit") + .build(); + @Override protected QueryRunner createQueryRunner() throws Exception @@ -28,4 +49,41 @@ protected QueryRunner createQueryRunner() ImmutableMap.of(), REQUIRED_TPCH_TABLES); } + + @Override + protected Optional filterColumnNameTestData(String columnName) + { + if (UNSUPPORTED_COLUMN_NAMES.contains(columnName)) { + return Optional.empty(); + } + return Optional.of(columnName); + } + + // TODO: Disable all operations for unsupported column names + @Test(dataProvider = "unsupportedColumnNameDataProvider") + public void testSelectFailsForColumnName(String columnName) + { + String tableName = "test.test_unsupported_column_name" + randomNameSuffix(); + + assertUpdate("CREATE TABLE " + tableName + "(\"" + columnName + "\" varchar(50))"); + try { + assertUpdate("INSERT INTO " + tableName + " VALUES ('test value')", 1); + // The storage API can't read the table, but query based API can read it + assertThatThrownBy(() -> query("SELECT * FROM " + tableName)) + .cause() + .hasMessageMatching(".*(Illegal initial character|Invalid name).*"); + assertThat(bigQuerySqlExecutor.executeQuery("SELECT * FROM " + tableName).getValues()) + .extracting(field -> field.get(0).getStringValue()) + .containsExactly("test value"); + } + finally { + assertUpdate("DROP TABLE " + tableName); + } + } + + @DataProvider + public Object[][] unsupportedColumnNameDataProvider() + { + return UNSUPPORTED_COLUMN_NAMES.stream().collect(toDataProvider()); + } }