diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java index 7175576a1b41..0ee751b4fce1 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java @@ -16,7 +16,6 @@ package com.google.cloud.bigquery.jdbc.it; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -29,7 +28,6 @@ import java.nio.file.Files; import java.sql.Connection; import java.sql.DriverManager; -import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Arrays; @@ -47,14 +45,8 @@ private void validateConnection(String connection_uri) throws SQLException { Connection connection = DriverManager.getConnection(connection_uri); assertNotNull(connection); assertFalse(connection.isClosed()); - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; Statement statement = connection.createStatement(); - ResultSet jsonResultSet = statement.executeQuery(query); - int totalRows = 0; - while (jsonResultSet.next()) { - totalRows += 1; - } - assertEquals(totalRows, 850); + validateStatement(statement, 850); connection.close(); } @@ -177,11 +169,7 @@ public void testValidGoogleUserAccountAuthentication() throws SQLException { assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - ResultSet resultSet = - statement.executeQuery( - "SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50"); - - assertEquals(50, resultSetRowCount(resultSet)); + validateStatement(statement, 50); connection.close(); } @@ -204,11 +192,7 @@ public void testValidExternalAccountAuthentication() throws SQLException { assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - ResultSet resultSet = - statement.executeQuery( - "SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50"); - - assertEquals(50, resultSetRowCount(resultSet)); + validateStatement(statement, 50); connection.close(); } @@ -227,11 +211,7 @@ public void testValidExternalAccountAuthenticationFromFile() throws SQLException assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - ResultSet resultSet = - statement.executeQuery( - "SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50"); - - assertEquals(50, resultSetRowCount(resultSet)); + validateStatement(statement, 50); connection.close(); } @@ -261,11 +241,7 @@ public void testValidExternalAccountAuthenticationRawJson() throws SQLException assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - ResultSet resultSet = - statement.executeQuery( - "SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50"); - - assertEquals(50, resultSetRowCount(resultSet)); + validateStatement(statement, 50); connection.close(); } @@ -275,6 +251,7 @@ public void testValidExternalAccountAuthenticationRawJson() throws SQLException "https://www.googleapis.com/auth/bigquery, false" }) @Tag("advanced") + @Tag("disable_tpc") public void testValidPreGeneratedAccessTokenAuthentication(String scope, boolean isReadOnly) throws Exception { final JsonObject authJson = getAuthJson(); @@ -316,11 +293,7 @@ public void testValidRefreshTokenAuthentication() throws SQLException { assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - ResultSet resultSet = - statement.executeQuery( - "SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50"); - - assertEquals(50, resultSetRowCount(resultSet)); + validateStatement(statement, 50); connection.close(); } diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java index 366d1f70a353..c796eea0f9ba 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java @@ -16,6 +16,7 @@ package com.google.cloud.bigquery.jdbc.it; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -429,4 +430,16 @@ public static List getInfoBySQL(Connection connection, String sqlCmd) } return result; } + + public static void validateStatement(Statement stmt, int expectedRows) throws SQLException { + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, " + expectedRows + "))"; + assertTrue(stmt.execute(query)); + int count = 0; + try (ResultSet rs = stmt.getResultSet()) { + while (rs.next()) { + count++; + } + } + assertEquals(expectedRows, count); + } } diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java index aa44e64d7438..e0d41f713719 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java @@ -104,6 +104,7 @@ public static void afterClass() throws SQLException { @Test @Tag("known_issue") // b/539615199 + @Tag("disable_tpc") public void testValidAllDataTypesSerializationFromSelectQueryArrowDataset() throws SQLException { String DATASET = "JDBC_INTEGRATION_DATASET"; String TABLE_NAME = "JDBC_INTEGRATION_ARROW_TEST_TABLE"; @@ -144,7 +145,7 @@ public void testValidAllDataTypesSerializationFromSelectQueryArrowDataset() thro @Test public void testFastQueryPathSmall() throws SQLException { - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 850))"; ResultSet jsonResultSet = bigQueryStatement.executeQuery(query); assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); assertEquals(850, resultSetRowCount(jsonResultSet)); @@ -152,20 +153,17 @@ public void testFastQueryPathSmall() throws SQLException { @Test public void testFastQueryPathEmpty() throws SQLException { - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 0"; Connection connection = DriverManager.getConnection(String.format(connectionUrl, DEFAULT_CATALOG)); Statement bigQueryStatement = connection.createStatement(); - ResultSet jsonResultSet = bigQueryStatement.executeQuery(query); - assertEquals(0, resultSetRowCount(jsonResultSet)); + validateStatement(bigQueryStatement, 0); connection.close(); } @Test public void testSmallSelectAndVerifyResults() throws SQLException { String query = - "SELECT word FROM `bigquery-public-data.samples.shakespeare` WHERE" - + " word LIKE 'X%' LIMIT 10"; + "SELECT CONCAT('X', cast(word as STRING)) FROM UNNEST(GENERATE_ARRAY(1, 10)) AS word LIMIT 10"; ResultSet resultSet = bigQueryStatement.executeQuery(query); int rowCount = 0; @@ -179,6 +177,7 @@ public void testSmallSelectAndVerifyResults() throws SQLException { @Test // reads without using ReadAPI and makes sure that they are in order, which implies threads worked // correctly + @Tag("disable_tpc") public void testIterateOrderJsonMultiThread_NoReadApi() throws SQLException { int expectedCnt = 10000; String query = String.format(BASE_QUERY, expectedCnt); @@ -197,6 +196,7 @@ public void testIterateOrderJsonMultiThread_NoReadApi() throws SQLException { @Test // reads using ReadAPI and makes sure that they are in order, which implies threads worked // correctly + @Tag("disable_tpc") public void testIterateOrderArrowMultiThread() throws SQLException { int expectedCnt = 200000; String longQuery = String.format(BASE_QUERY, expectedCnt); @@ -217,6 +217,7 @@ public void testIterateOrderArrowMultiThread() throws SQLException { } @Test + @Tag("disable_tpc") public void testReadAPIPathLarge() throws SQLException { Properties withReadApi = new Properties(); withReadApi.setProperty("EnableHighThroughputAPI", "1"); @@ -236,6 +237,7 @@ public void testReadAPIPathLarge() throws SQLException { } @Test + @Tag("disable_tpc") public void testReadAPIPathLargeWithThresholdParameters() throws SQLException { String connectionUri = ITBigQueryJDBCTest.connection_uri @@ -254,6 +256,7 @@ public void testReadAPIPathLargeWithThresholdParameters() throws SQLException { } @Test + @Tag("disable_tpc") public void testReadAPIPathLargeWithThresholdNotMet() throws SQLException { String connectionUri = ITBigQueryJDBCTest.connection_uri @@ -279,14 +282,9 @@ public void testStatelessQueryPathSmall() throws SQLException { Statement statement = connectionUseStateless.createStatement(); - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; - ResultSet jsonResultSet = statement.executeQuery(query); - assertEquals(850, resultSetRowCount(jsonResultSet)); + validateStatement(statement, 850); - String queryEmpty = - "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 0"; - ResultSet jsonResultSetEmpty = statement.executeQuery(queryEmpty); - assertEquals(0, resultSetRowCount(jsonResultSetEmpty)); + validateStatement(statement, 0); connectionUseStateless.close(); } @@ -312,8 +310,7 @@ public void testDriver() throws SQLException { Connection connection = driver.connect(connection_uri, new Properties()); assertNotNull(connection); Statement st = connection.createStatement(); - boolean rs = st.execute("Select * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"); - assertTrue(rs); + validateStatement(st, 180); connection.close(); } @@ -358,6 +355,7 @@ public void testDefaultDatasetWithProject() throws SQLException { } @Test + @Tag("disable_tpc") public void testLocation() throws SQLException { String connection_uri = ITBigQueryJDBCTest.connection_uri + "LOCATION=EU"; @@ -370,10 +368,7 @@ public void testLocation() throws SQLException { Statement statement = connection.createStatement(); // Query a dataset in the EU - String query = - "SELECT name FROM `bigquery-public-data.covid19_italy_eu.data_by_province` LIMIT 100"; - ResultSet resultSet = statement.executeQuery(query); - assertEquals(100, resultSetRowCount(resultSet)); + validateStatement(statement, 100); String connection_uri_null_location = ITBigQueryJDBCTest.connection_uri; @@ -387,6 +382,7 @@ public void testLocation() throws SQLException { } @Test + @Tag("disable_tpc") public void testIncorrectLocation() throws SQLException { String connection_uri = ITBigQueryJDBCTest.connection_uri + "LOCATION=europe-west3"; @@ -397,9 +393,12 @@ public void testIncorrectLocation() throws SQLException { // Query a dataset in the US Statement statement = connection.createStatement(); - String query = "SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"; BigQueryJdbcException ex = - assertThrows(BigQueryJdbcException.class, () -> statement.executeQuery(query)); + assertThrows( + BigQueryJdbcException.class, + () -> + statement.executeQuery( + "SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180")); BigQueryError error = ex.getBigQueryException().getError(); assertNotNull(error); assertEquals("accessDenied", error.getReason()); @@ -933,15 +932,14 @@ public void testExecuteQueryWithInsert() throws SQLException { @Test public void testExecuteQueryWithMultipleReturns() throws SQLException { - String query = String.format("SELECT * FROM bigquery-public-data.samples.shakespeare LIMIT 1;"); + String query = String.format("SELECT * FROM UNNEST(GENERATE_ARRAY(1, 1));"); assertThrows(BigQueryJdbcException.class, () -> bigQueryStatement.executeQuery(query + query)); } @Test public void testExecuteUpdateWithSelect() throws SQLException { - String selectQuery = - String.format("SELECT * FROM bigquery-public-data.samples.shakespeare LIMIT 1;"); + String selectQuery = String.format("SELECT * FROM UNNEST(GENERATE_ARRAY(1, 1));"); assertThrows(BigQueryJdbcException.class, () -> bigQueryStatement.executeUpdate(selectQuery)); } @@ -1101,9 +1099,7 @@ public void testSetFetchDirectionFetchUnknownThrowsUnsupported() { public void testExecuteBatchQueryTypeSelectThrowsUnsupported() throws SQLException { Driver driver = BigQueryDriver.getRegisteredDriver(); Connection connection = driver.connect(connection_uri, new Properties()); - String query = - "SELECT word FROM `bigquery-public-data.samples.shakespeare` WHERE" - + " word LIKE 'X%' LIMIT 10"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 10));"; Statement statement = connection.createStatement(); assertThrows(IllegalArgumentException.class, () -> statement.addBatch(query)); @@ -1274,6 +1270,7 @@ public void testAllValidStatementTypesForAddBatch() throws SQLException { } @Test + @Tag("disable_tpc") public void testUnsupportedHTAPIFallbacksToStandardQueriesWithRange() throws SQLException { String selectQuery = "select * from `DATATYPERANGETEST.RangeIntervalTestTable` LIMIT 5000;"; String connection_uri = @@ -1298,6 +1295,7 @@ public void testUnsupportedHTAPIFallbacksToStandardQueriesWithRange() throws SQL } @Test + @Tag("disable_tpc") public void testIntervalDataTypeWithArrowResultSet() throws SQLException { String selectQuery = "select * from `DATATYPERANGETEST.RangeIntervalTestTable` order by intColumn limit 5000;"; @@ -1323,6 +1321,7 @@ public void testIntervalDataTypeWithArrowResultSet() throws SQLException { } @Test + @Tag("disable_tpc") public void testIntervalDataTypeWithJsonResultSet() throws SQLException { String selectQuery = "select * from `DATATYPERANGETEST.RangeIntervalTestTable` order by intColumn limit 10 ;"; @@ -1348,6 +1347,7 @@ public void testIntervalDataTypeWithJsonResultSet() throws SQLException { } @Test + @Tag("disable_tpc") public void testValidLEPEndpointQuery() throws SQLException { String DATASET = "JDBC_REGIONAL_DATASET"; String TABLE_NAME = "REGIONAL_TABLE"; @@ -1380,6 +1380,7 @@ public void testValidEndpointWithInvalidBQPortThrows() throws SQLException { } @Test + @Tag("disable_tpc") public void testLEPEndpointDataNotFoundThrows() throws SQLException { String DATASET = "JDBC_REGIONAL_DATASET"; String TABLE_NAME = "REGIONAL_TABLE"; @@ -1396,6 +1397,7 @@ public void testLEPEndpointDataNotFoundThrows() throws SQLException { } @Test + @Tag("disable_tpc") public void testValidREPEndpointQuery() throws SQLException { String DATASET = "JDBC_REGIONAL_DATASET"; String TABLE_NAME = "REGIONAL_TABLE"; @@ -1430,7 +1432,7 @@ public void testREPEndpointDataNotFoundThrows() throws SQLException { @Test public void testCloseStatement() throws SQLException { - String query = "SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 10"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 10))"; Statement statement = bigQueryConnection.createStatement(); ResultSet jsonResultSet = statement.executeQuery(query); assertEquals(10, resultSetRowCount(jsonResultSet)); @@ -1440,7 +1442,7 @@ public void testCloseStatement() throws SQLException { @Test public void testCloseableStatementSingleResult() throws SQLException { - String query = "SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 10"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 10))"; Statement statement = bigQueryConnection.createStatement(); statement.closeOnCompletion(); assertTrue(statement.isCloseOnCompletion()); @@ -1452,7 +1454,7 @@ public void testCloseableStatementSingleResult() throws SQLException { @Test public void testCloseableStatementMultiResult() throws SQLException { - String query = "SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 10;"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 10));"; Statement statement = bigQueryConnection.createStatement(); statement.closeOnCompletion(); assertTrue(statement.isCloseOnCompletion()); @@ -1470,7 +1472,7 @@ public void testCloseableStatementMultiResult() throws SQLException { @Test public void testCloseableStatementMultiResultExplicitClose() throws SQLException { - String query = "SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 10;"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 10));"; Statement statement = bigQueryConnection.createStatement(); statement.closeOnCompletion(); assertTrue(statement.isCloseOnCompletion()); @@ -1517,7 +1519,7 @@ public void testDataSourceOAuthPvtKeyPath() throws SQLException, IOException { @Test public void testPreparedStatementSmallSelect() throws SQLException { String query = - "SELECT * FROM `bigquery-public-data.samples.shakespeare` where corpus=? LIMIT 1000"; + "SELECT num FROM UNNEST(GENERATE_ARRAY(1, 1000)) AS num WHERE CAST(? AS STRING) = 'hamlet'"; PreparedStatement preparedStatement = bigQueryConnection.prepareStatement(query); preparedStatement.setString(1, "hamlet"); @@ -1683,6 +1685,7 @@ public void testPreparedStatementDateTimeValues() throws SQLException { } @Test + @Tag("disable_tpc") public void testValidDestinationTableSavesQueriesWithLegacySQL() throws SQLException { // setup String connection_uri = @@ -1727,6 +1730,7 @@ public void testNonEnabledUseLegacySQLThrowsSyntaxError() throws SQLException { } @Test + @Tag("disable_tpc") public void testUseLegacySQLWithLargeResultsNotAllowedQueries() throws SQLException { // setup String connection_uri = @@ -1745,6 +1749,7 @@ public void testUseLegacySQLWithLargeResultsNotAllowedQueries() throws SQLExcept } @Test + @Tag("disable_tpc") public void testValidDestinationTableSavesQueriesWithStandardSQL() throws SQLException { // setup String connection_uri = @@ -1774,6 +1779,7 @@ public void testValidDestinationTableSavesQueriesWithStandardSQL() throws SQLExc } @Test + @Tag("disable_tpc") public void testDestinationTableAndDestinationDatasetThatDoesNotExistsCreates() throws SQLException { // setup @@ -1808,6 +1814,7 @@ public void testDestinationTableAndDestinationDatasetThatDoesNotExistsCreates() } @Test + @Tag("disable_tpc") public void testUseLegacySQLWithLargeResultsAllowedWithNoDestinationTableDefaults() throws SQLException { // setup @@ -1827,6 +1834,7 @@ public void testUseLegacySQLWithLargeResultsAllowedWithNoDestinationTableDefault } @Test + @Tag("disable_tpc") public void testDestinationTableWithMissingDestinationDatasetDefaults() throws SQLException { // setup String connection_uri = @@ -1958,6 +1966,7 @@ public void testRangeDataTypeWithJsonResultSet() throws SQLException { } @Test + @Tag("disable_tpc") public void testRangeDataTypeWithArrowResultSet() throws SQLException { String selectQuery = "select * from `DATATYPERANGETEST.RangeIntervalTestTable` order by intColumn limit 5000;"; @@ -2066,7 +2075,7 @@ public void testQueryPropertyDataSetProjectIdQueriesToIncorrectDatasetThrows() public void testQueryPropertyTimeZoneQueries() throws SQLException { String connection_uri = ITBigQueryJDBCTest.connection_uri + "QueryProperties=time_zone=America/New_York;"; - String query = "SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 180))"; Driver driver = BigQueryDriver.getRegisteredDriver(); Connection connection = driver.connect(connection_uri, new Properties()); Statement statement = connection.createStatement(); @@ -2081,6 +2090,7 @@ public void testQueryPropertyTimeZoneQueries() throws SQLException { } @Test + @Tag("disable_tpc") public void testQueryPropertySessionIdSetsStatementSession() throws SQLException, InterruptedException { String sessionId = getSessionId(); @@ -2107,9 +2117,12 @@ public void testQueryPropertySessionIdSetsStatementSession() } @Test + @Tag("disable_tpc") public void testEncryptedTableWithKmsQueries() throws SQLException { // setup - String KMSKeyName = requireEnvVar("KMS_RESOURCE_PATH"); + org.junit.jupiter.api.Assumptions.assumeTrue( + System.getenv("KMS_RESOURCE_PATH") != null, "KMS_RESOURCE_PATH is missing"); + String KMSKeyName = System.getenv("KMS_RESOURCE_PATH"); String connection_uri = ITBigQueryJDBCTest.connection_uri + "KMSKeyName=" + KMSKeyName + ";"; String selectQuery = "SELECT * FROM `JDBC_INTEGRATION_DATASET.KMS_Test_table`;"; Driver driver = BigQueryDriver.getRegisteredDriver(); @@ -2127,8 +2140,11 @@ public void testEncryptedTableWithKmsQueries() throws SQLException { } @Test + @Tag("disable_tpc") public void testIncorrectKmsThrows() throws SQLException { - String KMSKeyName = requireEnvVar("KMS_RESOURCE_PATH"); + org.junit.jupiter.api.Assumptions.assumeTrue( + System.getenv("KMS_RESOURCE_PATH") != null, "KMS_RESOURCE_PATH is missing"); + String KMSKeyName = System.getenv("KMS_RESOURCE_PATH"); String connection_uri = ITBigQueryJDBCTest.connection_uri + "KMSKeyName=" + KMSKeyName + ";"; String selectQuery = "INSERT INTO `bigquery-devtools-drivers.JDBC_INTEGRATION_DATASET.No_KMS_Test_table` (id," @@ -2143,6 +2159,7 @@ public void testIncorrectKmsThrows() throws SQLException { } @Test + @Tag("disable_tpc") public void testQueryPropertyServiceAccountFollowsIamPermission() throws SQLException { final String SERVICE_ACCOUNT_EMAIL = requireEnvVar("SA_EMAIL"); String connection_uri = @@ -2164,6 +2181,7 @@ public void testQueryPropertyServiceAccountFollowsIamPermission() throws SQLExce } @Test + @Tag("disable_tpc") public void testValidLegacySQLStatement() throws SQLException { String legacyJoinQuery = "SELECT\n" diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITCallableStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITCallableStatementTest.java index d70f0cb77a9b..82f1b142838e 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITCallableStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITCallableStatementTest.java @@ -604,9 +604,7 @@ public void testCallableStatementScriptExecuteLargeUpdate() throws SQLException @Test public void testScript() throws SQLException { - String BASE_QUERY = - "SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 order by" - + " trip_distance asc LIMIT %s;"; + String BASE_QUERY = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, %s));"; String query1 = String.format(BASE_QUERY, 5000); String query2 = String.format(BASE_QUERY, 7000); String query3 = String.format(BASE_QUERY, 9000); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionPoolingTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionPoolingTest.java index 0da773d7c965..823b232e9967 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionPoolingTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionPoolingTest.java @@ -28,12 +28,12 @@ import com.google.cloud.bigquery.jdbc.PooledConnectionListener; import com.google.cloud.bigquery.jdbc.utils.TestUtilities.TestConnectionListener; import java.sql.Connection; -import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import javax.sql.PooledConnection; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; public class ITConnectionPoolingTest extends ITBase { @@ -267,6 +267,7 @@ public void testPooledConnectionListenerConnectionError() throws SQLException { } @Test + @Tag("disable_tpc") public void testExecuteQueryWithConnectionPoolingEnabledDefaultPoolSize() throws SQLException { String connectionURL = ITBase.connectionUrl; @@ -274,6 +275,7 @@ public void testExecuteQueryWithConnectionPoolingEnabledDefaultPoolSize() throws } @Test + @Tag("disable_tpc") public void testExecuteQueryWithConnectionPoolingEnabledCustomPoolSize() throws SQLException { String connectionURL = ITBase.connectionUrl + "ConnectionPoolSize=" + CUSTOM_CONN_POOL_SIZE + ";"; @@ -299,10 +301,8 @@ private void assertConnectionPoolingResults(String connectionURL, Long connectio assertFalse(connection.isClosed()); // Execute query with physical connection - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; Statement statement = connection.createStatement(); - ResultSet jsonResultSet = statement.executeQuery(query); - assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); + ITBase.validateStatement(statement, 850); // Close physical connection connection.close(); @@ -319,8 +319,8 @@ private void assertConnectionPoolingResults(String connectionURL, Long connectio assertEquals(connectionPoolSize, listener.getConnectionPoolSize()); // Execute query with reusable physical connection - jsonResultSet = statement.executeQuery(query); - assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); + statement = connection.createStatement(); + ITBase.validateStatement(statement, 850); // Return connection back to the pool. connection.close(); @@ -328,7 +328,6 @@ private void assertConnectionPoolingResults(String connectionURL, Long connectio assertEquals(1, listener.getConnectionPoolCurrentCapacity()); assertEquals(connectionPoolSize, listener.getConnectionPoolSize()); pooledConnection.close(); - jsonResultSet.close(); statement.close(); connection.close(); } diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java index 99eeb5339f8b..525078d3ec90 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java @@ -226,26 +226,26 @@ public void testCommitAndRollback() throws SQLException { Statement statement1 = connection1.createStatement(); statement.execute( String.format( - "CREATE TABLE IF NOT EXISTS %s.%s.autocommit_test_table (id INT)", + "CREATE TABLE IF NOT EXISTS `%s.%s.autocommit_test_table` (id INT)", DEFAULT_CATALOG, DATASET)); connection1.commit(); statement1.executeUpdate( String.format( - "INSERT INTO %s.%s.autocommit_test_table (id) VALUES (1)", DEFAULT_CATALOG, DATASET)); + "INSERT INTO `%s.%s.autocommit_test_table` (id) VALUES (1)", DEFAULT_CATALOG, DATASET)); connection1.rollback(); ResultSet resultSet = statement1.executeQuery( String.format( - "SELECT COUNT(*) FROM %s.%s.autocommit_test_table", DEFAULT_CATALOG, DATASET)); + "SELECT COUNT(*) FROM `%s.%s.autocommit_test_table`", DEFAULT_CATALOG, DATASET)); resultSet.next(); assertEquals(0, resultSet.getInt(1)); // Table should be empty due to rollback connection1.setAutoCommit(true); statement1.executeUpdate( String.format( - "DROP TABLE IF EXISTS %s.%s.autocommit_test_table", DEFAULT_CATALOG, DATASET)); + "DROP TABLE IF EXISTS `%s.%s.autocommit_test_table`", DEFAULT_CATALOG, DATASET)); statement1.close(); connection1.close(); statement.close(); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDatabaseMetadataTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDatabaseMetadataTest.java index e7e080c427de..c372b033d48f 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDatabaseMetadataTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDatabaseMetadataTest.java @@ -726,6 +726,7 @@ public void testDatabaseMetadataGetColumns() throws SQLException { } @Test + @Tag("disable_tpc") public void testDatabaseMetadataGetTables() throws SQLException { Connection connection = DriverManager.getConnection(ITBase.connectionUrl); DatabaseMetaData databaseMetaData = connection.getMetaData(); @@ -826,6 +827,7 @@ public void testDatabaseMetadataGetTables() throws SQLException { } @Test + @Tag("disable_tpc") public void testDatabaseMetadataGetSchemas() throws SQLException { Connection connection = DriverManager.getConnection(ITBase.connectionUrl); DatabaseMetaData databaseMetaData = connection.getMetaData(); @@ -898,6 +900,7 @@ public void testDatabaseMetadataGetSchemasNoArgs() throws SQLException { } @Test + @Tag("disable_tpc") public void testDatabaseMetaDataGetFunctions() throws SQLException { Connection connection = DriverManager.getConnection(ITBase.connectionUrl); DatabaseMetaData databaseMetaData = connection.getMetaData(); @@ -1137,6 +1140,7 @@ public void testDatabaseMetadataGetFunctionColumns() throws SQLException { } @Test + @Tag("disable_tpc") public void testAdditionalProjectsInMetadata() throws SQLException { String additionalProjectsValue = "bigquery-public-data"; String datasetInAdditionalProject = "baseball"; @@ -1193,6 +1197,7 @@ public void testAdditionalProjectsInMetadata() throws SQLException { @Test @Tag("advanced") + @Tag("disable_tpc") public void testFilterTablesOnDefaultDataset_getTables() throws SQLException { String defaultDatasetValue = CONSTRAINTS_DATASET; @@ -1264,6 +1269,7 @@ public void testFilterTablesOnDefaultDataset_getTables() throws SQLException { @Test @Tag("advanced") + @Tag("disable_tpc") public void testFilterTablesOnDefaultDataset_getColumns() throws SQLException { String defaultDatasetValue = CONSTRAINTS_DATASET; String tableInDefaultDataset = CONSTRAINTS_TABLE_NAME; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDriverTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDriverTest.java index 93d8727482f9..fe00631cb624 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDriverTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDriverTest.java @@ -32,6 +32,7 @@ import java.util.Properties; import java.util.Random; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; public class ITDriverTest extends ITBase { @@ -90,6 +91,7 @@ public void testGetDriverMethod() throws SQLException, InterruptedException { } @Test + @Tag("disable_tpc") public void testDriverLocation() throws SQLException, InterruptedException { String datasetUS = "JDBC_DRIVER_US_TEST_DATASET" + random.nextInt(999); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java index 2cf37f221d05..ddddc5fb3537 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java @@ -61,9 +61,7 @@ public class ITNightlyBigQueryTest extends ITBase { static Statement bigQueryStatement; private static final Random random = new Random(); private static final int randomNumber = random.nextInt(9999); - private static final String BASE_QUERY = - "SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 order by" - + " trip_distance asc LIMIT %s"; + private static final String BASE_QUERY = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, %s));"; private static final String CONSTRAINTS_DATASET = "JDBC_CONSTRAINTS_TEST_DATASET"; private static final String CONSTRAINTS_TABLE_NAME = "JDBC_CONSTRAINTS_TEST_TABLE"; private static final String CONSTRAINTS_TABLE_NAME2 = "JDBC_CONSTRAINTS_TEST_TABLE2"; @@ -185,10 +183,10 @@ public void testMergeInExecuteBatch() throws SQLException { } @Test + @Tag("disable_tpc") public void testValidLongRunningQuery() throws SQLException { // setup - String selectQuery = - "SELECT * FROM `bigquery-public-data.deepmind_alphafold.metadata` LIMIT 50000"; + String selectQuery = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 50000))"; // Read data via JDBC ResultSet resultSet = bigQueryStatement.executeQuery(selectQuery); @@ -269,6 +267,7 @@ public void testQueryInterruptGracefullyStopsOptionalJob() } @Test + @Tag("disable_tpc") public void testWideColumnQueries() throws SQLException { String selectQuery = "SELECT * FROM `bigquery-public-data.covid19_open_data_eu.covid19_open_data` LIMIT 50000"; @@ -287,6 +286,7 @@ public void testWideColumnQueries() throws SQLException { } @Test + @Tag("disable_tpc") public void testExecuteLargeUpdate() throws SQLException { String tableName = "JDBC_LARGE_UPDATE_TABLE_" + randomNumber; String createQuery = @@ -299,8 +299,7 @@ public void testExecuteLargeUpdate() throws SQLException { String insertQuery = String.format( "INSERT INTO %s.%s (gbifid, scientificname, individualcount) " - + "SELECT gbifid, scientificname, individualcount FROM " - + "bigquery-public-data.gbif.occurrences;", + + "(SELECT 1 as gbifid, \"name\" as scientificname, 1 as individualcount FROM UNNEST(GENERATE_ARRAY(1, 10)));", DATASET, tableName); String updateQuery = String.format( @@ -325,6 +324,7 @@ public void testExecuteLargeUpdate() throws SQLException { } @Test + @Tag("disable_tpc") public void testHTAPIWithValidDestinationTableSavesQueriesWithStandardSQL() throws SQLException { // setup String connection_uri = @@ -333,8 +333,7 @@ public void testHTAPIWithValidDestinationTableSavesQueriesWithStandardSQL() thro + "LargeResultTable=destination_table_test;" + "LargeResultDataset=INTEGRATION_TESTS;" + "EnableHighThroughputAPI=1;"; - String selectLegacyQuery = - "SELECT * FROM `bigquery-public-data.deepmind_alphafold.metadata` LIMIT 200000;"; + String selectLegacyQuery = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 200000))"; Driver driver = BigQueryDriver.getRegisteredDriver(); Connection connection = driver.connect(connection_uri, new Properties()); Statement statement = connection.createStatement(); @@ -712,6 +711,7 @@ public void testFailedStatementInTheMiddleOfExecuteBatchStopsExecuting() throws } @Test + @Tag("disable_tpc") public void testHTAPIWithValidDestinationTableSavesQueriesWithLegacy() throws SQLException { // setup String connection_uri = @@ -720,8 +720,7 @@ public void testHTAPIWithValidDestinationTableSavesQueriesWithLegacy() throws SQ + "LargeResultTable=destination_table_test;" + "LargeResultDataset=INTEGRATION_TESTS;" + "EnableHighThroughputAPI=1;"; - String selectLegacyQuery = - "SELECT * FROM [bigquery-public-data.deepmind_alphafold.metadata] LIMIT 200000;"; + String selectLegacyQuery = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 200000))"; Driver driver = BigQueryDriver.getRegisteredDriver(); Connection connection = driver.connect(connection_uri, new Properties()); Statement statement = connection.createStatement(); @@ -1040,6 +1039,7 @@ public void testMultipleExecuteBatches() throws SQLException { @Test @Tag("known_issue") // b/539615199 + @Tag("disable_tpc") public void testValidAllDataTypesSerializationFromSelectQuery() throws SQLException { String DATASET = "JDBC_INTEGRATION_DATASET"; String TABLE_NAME = "JDBC_DATATYPES_INTEGRATION_TEST_TABLE"; @@ -1072,6 +1072,7 @@ public void testValidAllDataTypesSerializationFromSelectQuery() throws SQLExcept } @Test + @Tag("disable_tpc") public void testRepeatedStructFromSelectQuery() throws SQLException { String DATASET = "JDBC_INTEGRATION_DATASET"; String TABLE_NAME = "JDBC_REPEATED_STRUCT_INTEGRATION_TEST"; @@ -1097,6 +1098,7 @@ public void testRepeatedStructFromSelectQuery() throws SQLException { @Test @Tag("known_issue") // b/539615199 + @Tag("disable_tpc") public void testValidAllDataTypesSerializationFromSelectQueryArrowDataset() throws SQLException { String DATASET = "JDBC_INTEGRATION_DATASET"; String TABLE_NAME = "JDBC_INTEGRATION_ARROW_TEST_TABLE"; @@ -1536,13 +1538,12 @@ public void testStatelessQueryPathSmall() throws SQLException { Statement statement = bigQueryConnectionUseStateless.createStatement(); - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 850))"; ResultSet jsonResultSet = statement.executeQuery(query); assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); assertEquals(850, resultSetRowCount(jsonResultSet)); - String queryEmpty = - "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 0"; + String queryEmpty = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 0))"; ResultSet jsonResultSetEmpty = statement.executeQuery(queryEmpty); assertTrue(jsonResultSetEmpty.getClass().getName().contains("BigQueryJsonResultSet")); assertEquals(0, resultSetRowCount(jsonResultSetEmpty)); @@ -1551,7 +1552,7 @@ public void testStatelessQueryPathSmall() throws SQLException { @Test public void testFastQueryPathMedium() throws SQLException { - String query = "SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 9000"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 9000))"; ResultSet jsonResultSet = bigQueryStatement.executeQuery(query); assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); assertEquals(9000, resultSetRowCount(jsonResultSet)); @@ -1559,13 +1560,14 @@ public void testFastQueryPathMedium() throws SQLException { @Test public void testFastQueryPathLarge() throws SQLException { - String query = "SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 18000"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 18000))"; ResultSet jsonResultSet = bigQueryStatement.executeQuery(query); assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); assertEquals(18000, resultSetRowCount(jsonResultSet)); } @Test + @Tag("disable_tpc") // reads using ReadAPI and makes sure that they are in order, which implies threads worked // correctly public void testIterateOrderArrowMultiThread() throws SQLException { @@ -1584,6 +1586,7 @@ public void testIterateOrderArrowMultiThread() throws SQLException { } @Test + @Tag("disable_tpc") public void testNonEnabledUseLegacySQLThrowsSyntaxError() throws SQLException { // setup String connection_uri = ITNightlyBigQueryTest.connection_uri; @@ -1601,13 +1604,14 @@ public void testNonEnabledUseLegacySQLThrowsSyntaxError() throws SQLException { @Test public void testFastQueryPathEmpty() throws SQLException { - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 0"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 0))"; ResultSet jsonResultSet = bigQueryStatement.executeQuery(query); assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); assertEquals(0, resultSetRowCount(jsonResultSet)); } @Test + @Tag("disable_tpc") public void testReadAPIPathLarge() throws SQLException { Properties withReadApi = new Properties(); withReadApi.setProperty("EnableHighThroughputAPI", "1"); @@ -1627,6 +1631,7 @@ public void testReadAPIPathLarge() throws SQLException { } @Test + @Tag("disable_tpc") public void testReadAPIPathLargeWithThresholdParameters() throws SQLException { String connectionUri = ITNightlyBigQueryTest.connection_uri diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITPSCBigQueryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITPSCBigQueryTest.java index 55ceeb5d7dd5..aa62a7cf3d7a 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITPSCBigQueryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITPSCBigQueryTest.java @@ -70,9 +70,8 @@ public void testNoOverrideTimesOut() throws SQLException { "APPLICATION_DEFAULT_CREDENTIALS", connection.unwrap(BigQueryConnection.class).getAuthProperties().get("OAuthType")); - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; Statement statement = connection.createStatement(); - assertThrows(BigQueryException.class, () -> statement.executeQuery(query)); + assertThrows(BigQueryException.class, () -> ITBase.validateStatement(statement, 850)); } @Test @@ -91,10 +90,8 @@ public void testValidADCAuthenticationInPSC() throws SQLException { "APPLICATION_DEFAULT_CREDENTIALS", connection.unwrap(BigQueryConnection.class).getAuthProperties().get("OAuthType")); - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; Statement statement = connection.createStatement(); - ResultSet jsonResultSet = statement.executeQuery(query); - assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); + ITBase.validateStatement(statement, 850); connection.close(); } @@ -115,10 +112,8 @@ public void testValidOAuthType2AuthenticationInPSC() throws SQLException { "PRE_GENERATED_TOKEN", connection.unwrap(BigQueryConnection.class).getAuthProperties().get("OAuthType")); - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; Statement statement = connection.createStatement(); - ResultSet jsonResultSet = statement.executeQuery(query); - assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); + ITBase.validateStatement(statement, 850); connection.close(); } @@ -165,10 +160,8 @@ public void testValidServiceAccountAuthenticationViaEmailInPSC() throws SQLExcep assertEquals( "GOOGLE_SERVICE_ACCOUNT", connection.unwrap(BigQueryConnection.class).getAuthProperties().get("OAuthType")); - String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850"; Statement statement = connection.createStatement(); - ResultSet jsonResultSet = statement.executeQuery(query); - assertTrue(jsonResultSet.getClass().getName().contains("BigQueryJsonResultSet")); + ITBase.validateStatement(statement, 850); connection.close(); } @@ -286,11 +279,7 @@ public void testValidExternalAccountAuthenticationInPSC() throws SQLException { connection.unwrap(BigQueryConnection.class).getAuthProperties().get("OAuthType")); Statement statement = connection.createStatement(); - ResultSet resultSet = - statement.executeQuery( - "SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50"); - - assertNotNull(resultSet); + ITBase.validateStatement(statement, 50); connection.close(); } } diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITProxyBigQueryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITProxyBigQueryTest.java index e0b02ce66bd8..b72f0851d158 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITProxyBigQueryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITProxyBigQueryTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.exception.BigQueryJdbcException; @@ -66,15 +65,13 @@ public void testValidAuthenticatedProxy() throws SQLException { assertNotNull(connection); assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - boolean result = - statement.execute("Select * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"); - assertTrue(result); + ITBase.validateStatement(statement, 180); connection.close(); } @Test public void testAuthenticatedProxyWithOutAuthDetailsThrows() throws SQLException { - String query = "Select * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 180))"; String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + "ProjectId=" @@ -94,7 +91,7 @@ public void testAuthenticatedProxyWithOutAuthDetailsThrows() throws SQLException @Test public void testNonExistingProxyTimesOut() throws SQLException { - String query = "Select * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"; + String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 180))"; String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + "ProjectId=" @@ -129,9 +126,7 @@ public void testNonAuthenticatedProxy() throws SQLException { assertNotNull(connection); assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - boolean result = - statement.execute("Select * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"); - assertTrue(result); + ITBase.validateStatement(statement, 180); connection.close(); } @@ -147,9 +142,7 @@ public void testValidNonProxyConnectionQueries() throws SQLException { assertNotNull(connection); assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - boolean result = - statement.execute("Select * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"); - assertTrue(result); + ITBase.validateStatement(statement, 180); connection.close(); } @@ -175,10 +168,7 @@ public void testReadAPIEnabledWithProxySettings() throws SQLException { assertNotNull(connection); assertFalse(connection.isClosed()); Statement statement = connection.createStatement(); - boolean result = - statement.execute( - "SELECT * FROM `bigquery-public-data.covid19_open_data_eu.covid19_open_data` LIMIT 200000"); - assertTrue(result); + ITBase.validateStatement(statement, 200000); connection.close(); } } diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java index 5d69867b01fe..462d40cea44a 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java @@ -46,6 +46,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; public class ITStatementTest extends ITBase { @@ -110,8 +111,7 @@ public void testExecute() throws SQLException { public void testExecuteQuery() throws SQLException { Connection connection = DriverManager.getConnection(ITBase.connectionUrl); Statement statement = connection.createStatement(); - String selectQuery = - "SELECT * FROM bigquery-public-data.chicago_taxi_trips.taxi_trips LIMIT 1000;"; + String selectQuery = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, 1000))"; ResultSet selectQueryResult = statement.executeQuery(selectQuery); ResultSet statementResult = statement.getResultSet(); @@ -230,9 +230,7 @@ public void testScript() throws SQLException { withReadApi.setProperty("EnableHighThroughputAPI", "1"); Connection connection = DriverManager.getConnection(connection_uri, withReadApi); Statement statement = connection.createStatement(); - String BASE_QUERY = - "SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 order by" - + " trip_distance asc LIMIT %s;"; + String BASE_QUERY = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, %s));"; int expectedCnt = 500000; String longQuery = String.format(BASE_QUERY, expectedCnt); String longerQuery = String.format(BASE_QUERY, 700000); @@ -354,11 +352,11 @@ public void testRangeSelectDataset() throws SQLException { // execute try { statement.execute( - "CREATE TABLE " + "CREATE TABLE `" + DEFAULT_CATALOG + "." + DATASET - + ".RangeTable (x RANGE OPTIONS (description = 'An optional RANGE" + + ".RangeTable` (x RANGE OPTIONS (description = 'An optional RANGE" + " field'), y STRUCT > OPTIONS (description = 'An array of" + " RANGE field')>);"); ResultSet selectQueryResult = @@ -369,13 +367,14 @@ public void testRangeSelectDataset() throws SQLException { } finally { // clean up statement.execute( - String.format("DROP TABLE IF EXISTS %s.%s.RangeTable;", DEFAULT_CATALOG, DATASET)); + String.format("DROP TABLE IF EXISTS `%s.%s.RangeTable`;", DEFAULT_CATALOG, DATASET)); statement.close(); } connection.close(); } @Test + @Tag("disable_tpc") public void testTemporaryDatasetLocation() throws SQLException, InterruptedException { String location = "europe-west3"; String randomSuffix = String.valueOf(100 + new Random().nextInt(900));