Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .kokoro/presubmit/bigquery-graalvm-native-presubmit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ env_vars: {
value: "gcloud-devel"
}

env_vars: {
key: "INTEGRATION_TEST_ARGS"
value: "-Dbigquery.endpoint=https://us-east7-bigquery.googleapis.com -Dbigquery.storage.endpoint=us-east7-bigquerystorage.googleapis.com:443"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-it-service-account"
Expand Down
5 changes: 5 additions & 0 deletions .kokoro/presubmit/bigquery-integration.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ env_vars: {
value: "gcloud-devel"
}

env_vars: {
key: "INTEGRATION_TEST_ARGS"
value: "-Dbigquery.endpoint=https://us-east7-bigquery.googleapis.com -Dbigquery.storage.endpoint=us-east7-bigquerystorage.googleapis.com:443"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-it-service-account"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ env_vars: {
value: "gcloud-devel"
}



env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-it-service-account"
Expand All @@ -44,5 +46,5 @@ env_vars: {

env_vars: {
key: "INTEGRATION_TEST_ARGS"
value: "-Dit.test=!ITBigQueryWrite*RetryTest -Dsurefire.failIfNoSpecifiedTests=false -Dfailsafe.failIfNoSpecifiedTests=false"
value: "-Dit.test=!ITBigQueryWrite*RetryTest -Dsurefire.failIfNoSpecifiedTests=false -Dfailsafe.failIfNoSpecifiedTests=false -Dbigquery.storage.endpoint=us-east7-bigquerystorage.googleapis.com:443 -Dbigquery.endpoint=https://us-east7-bigquery.googleapis.com"
}
4 changes: 3 additions & 1 deletion .kokoro/presubmit/bigquerystorage-integration.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ env_vars: {
value: "gcloud-devel"
}



env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-it-service-account"
Expand All @@ -39,5 +41,5 @@ env_vars: {

env_vars: {
key: "INTEGRATION_TEST_ARGS"
value: "-Dit.test=!ITBigQueryWrite*RetryTest -Dsurefire.failIfNoSpecifiedTests=false -Dfailsafe.failIfNoSpecifiedTests=false"
value: "-Dit.test=!ITBigQueryWrite*RetryTest -Dsurefire.failIfNoSpecifiedTests=false -Dfailsafe.failIfNoSpecifiedTests=false -Dbigquery.storage.endpoint=us-east7-bigquerystorage.googleapis.com:443 -Dbigquery.endpoint=https://us-east7-bigquery.googleapis.com"
}
19 changes: 19 additions & 0 deletions java-bigquery/google-cloud-bigquery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
</parent>
<properties>
<site.installationModule>google-cloud-bigquery</site.installationModule>
<bigquery.endpoint></bigquery.endpoint>
<bigquery.storage.endpoint></bigquery.storage.endpoint>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -326,5 +328,22 @@
</build>

</profile>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<environmentVariables>
<BIGQUERY_ENDPOINT>${bigquery.endpoint}</BIGQUERY_ENDPOINT>
<BIGQUERY_STORAGE_ENDPOINT>${bigquery.storage.endpoint}</BIGQUERY_STORAGE_ENDPOINT>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
// Dummy comment to trigger Kokoro presubmit for testing regional endpoints.
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -105,7 +106,7 @@ public static RemoteBigQueryHelper create(String projectId, InputStream keyStrea
.setProjectId(projectId)
.setRetrySettings(retrySettings())
.setTransportOptions(transportOptions);
String endpoint = System.getenv("BIGQUERY_ENDPOINT");
String endpoint = System.getProperty("bigquery.endpoint", System.getenv("BIGQUERY_ENDPOINT"));
if (endpoint != null) {
builder.setHost(endpoint);
}
Expand Down Expand Up @@ -143,7 +144,7 @@ public static RemoteBigQueryHelper create(BigQueryOptions.Builder bigqueryOption
bigqueryOptionsBuilder
.setRetrySettings(retrySettings())
.setTransportOptions(transportOptions);
String endpoint = System.getenv("BIGQUERY_ENDPOINT");
String endpoint = System.getProperty("bigquery.endpoint", System.getenv("BIGQUERY_ENDPOINT"));
if (endpoint != null) {
builder.setHost(endpoint);
}
Expand Down Expand Up @@ -184,4 +185,15 @@ public static BigQueryHelperException translate(Exception ex) {
return new BigQueryHelperException(ex.getMessage(), ex);
}
}

/**
* Helper to check if the provided BigQuery client is configured to target a regional endpoint.
*/
public static boolean isRegionalEndpoint(BigQuery bigquery) {
if (bigquery == null || bigquery.getOptions() == null) {
return false;
}
String host = bigquery.getOptions().getHost();
return host != null && (host.contains("-bigquery.googleapis.com") || host.contains("us-east7"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand Down Expand Up @@ -1271,6 +1272,7 @@ void testLosslessMaxTimestampIntegration() throws InterruptedException {

@Test
void testListDatasets() {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
Page<Dataset> datasets = bigquery.listDatasets("bigquery-public-data");
Iterator<Dataset> iterator = datasets.iterateAll().iterator();
Set<String> datasetNames = new HashSet<>();
Expand Down Expand Up @@ -2131,6 +2133,7 @@ void testCreateTableWithDefaultValueExpression() {

@Test
void testCreateAndUpdateTableWithPolicyTags() throws IOException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
// Set up policy tags in the datacatalog service
try (PolicyTagManagerClient policyTagManagerClient = PolicyTagManagerClient.create()) {
CreateTaxonomyRequest createTaxonomyRequest =
Expand Down Expand Up @@ -2515,6 +2518,7 @@ void testCreateExternalTable() throws InterruptedException {

@Test
void testSetPermExternalTableSchema() {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
String tableName = "test_create_external_table_perm";
TableId tableId = TableId.of(DATASET, tableName);
ExternalTableDefinition externalTableDefinition =
Expand Down Expand Up @@ -2926,6 +2930,7 @@ void testDeleteNonExistingTable() {

@Test
void testDeleteJob() {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
String query = "SELECT 17 as foo";
QueryJobConfiguration config = QueryJobConfiguration.of(query);
String jobName = "jobId_" + UUID.randomUUID().toString();
Expand Down Expand Up @@ -3188,6 +3193,7 @@ void testListAllTableData() {

@Test
void testListPageWithStartIndex() {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
String tableName = "midyear_population_agespecific";
TableId tableId = TableId.of(PUBLIC_PROJECT, PUBLIC_DATASET, tableName);
Table table = bigquery.getTable(tableId);
Expand Down Expand Up @@ -3659,6 +3665,7 @@ void testQueryStatistics() throws InterruptedException {

@Test
void testExecuteSelectDefaultConnectionSettings() throws SQLException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
// Use the default connection settings
Connection connection = bigquery.createConnection();
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
Expand All @@ -3669,6 +3676,7 @@ void testExecuteSelectDefaultConnectionSettings() throws SQLException {

@Test
void testExecuteSelectWithReadApi() throws SQLException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
final int rowLimit = 5000;
final String QUERY =
"SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 LIMIT %s";
Expand Down Expand Up @@ -3699,6 +3707,7 @@ void testExecuteSelectWithReadApi() throws SQLException {

@Test
void testExecuteSelectWithFastQueryReadApi() throws SQLException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
final int rowLimit = 5000;
final String QUERY =
"SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 LIMIT %s";
Expand Down Expand Up @@ -4785,6 +4794,7 @@ void testProjectIDFastSQLQueryWithJobId() {

@Test
void testLocationFastSQLQueryWithJobId() throws InterruptedException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
TableId tableIdFastQueryUk = TableId.of(UK_DATASET, "fastquery_testing_table");
DatasetInfo infoUK =
DatasetInfo.newBuilder(UK_DATASET)
Expand Down Expand Up @@ -4960,6 +4970,7 @@ void testFastDDLQuery() throws InterruptedException {

@Test
void testFastQuerySlowDDL() throws InterruptedException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
String tableName = generateRandomName("test_table_fast_query_ddl_slow_");
// This query take more than 10s to run and should fall back on the old query path
String slowDdlQuery =
Expand Down Expand Up @@ -5061,6 +5072,7 @@ void testQuerySessionSupport() throws InterruptedException {

@Test
void testLoadSessionSupportWriteChannelConfiguration() throws InterruptedException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
TableId sessionTableId = TableId.of("_SESSION", "test_temp_destination_table_from_file");

WriteChannelConfiguration configuration =
Expand Down Expand Up @@ -5288,6 +5300,7 @@ void testTransactionInfo() throws InterruptedException {
/* TODO(prasmish): replicate the entire test case for executeSelect */
@Test
void testScriptStatistics() throws InterruptedException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
String script =
"-- Declare a variable to hold names as an array.\n"
+ "DECLARE top_names ARRAY<STRING>;\n"
Expand Down Expand Up @@ -6541,6 +6554,7 @@ void testCancelJob() throws InterruptedException, TimeoutException {

@Test
void testCancelNonExistingJob() {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
assertFalse(bigquery.cancel("test_cancel_non_existing_job"));
}

Expand Down Expand Up @@ -6677,6 +6691,7 @@ void testInsertWithDecimalTargetTypes()

@Test
void testLocation() throws Exception {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
String location = "EU";
String wrongLocation = "US";

Expand Down Expand Up @@ -7443,6 +7458,7 @@ void testTableResultJobIdAndQueryId() throws InterruptedException {

@Test
void testStatelessQueriesWithLocation() throws Exception {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
// This test validates BigQueryOption location is used for stateless query by verifying that the
// stateless query fails when the BigQueryOption location does not match the dataset location.
String location = "EU";
Expand Down Expand Up @@ -7608,6 +7624,7 @@ void testInvalidUniverseDomainWithMismatchCredentials() {

@Test
void testUniverseDomainWithMatchingDomain() {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
// Test a valid domain using the default credentials and Google default universe domain.
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
BigQueryOptions bigQueryOptions =
Expand Down Expand Up @@ -7701,6 +7718,7 @@ void testExternalMetadataCacheModeFailForNonBiglake() {

@Test
void testObjectTable() throws InterruptedException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
String tableName = generateRandomName("test_object_table");
TableId tableId = TableId.of(DATASET, tableName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.util.logging.Logger;
import org.apache.arrow.vector.util.JsonStringArrayList;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand Down Expand Up @@ -507,6 +508,7 @@ void testPositionalParams()
// table-not-found exception. Ref: b/241134681 . This exception has been seen while reading data
// in bulk
void testForTableNotFound() throws SQLException {
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
int recordCnt = 50000000; // 5Mil
String query =
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public void testListDatasetsTraced() {
assertEquals("GET", attrs.get(HttpTracingRequestInitializer.HTTP_REQUEST_METHOD));
assertEquals("DatasetService", attrs.get(AttributeKey.stringKey("bq.rpc.service")));
assertEquals("ListDatasets", attrs.get(AttributeKey.stringKey("bq.rpc.method")));
assertEquals(
"bigquery.googleapis.com", attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
assertEquals(getExpectedHost(), attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
assertEquals(200L, attrs.get(HttpTracingRequestInitializer.HTTP_RESPONSE_STATUS_CODE));
assertEquals("bigquery.googleapis.com", attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
assertEquals(getExpectedHost(), attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
assertEquals(
"https://bigquery.googleapis.com/bigquery/v2/projects/"
getExpectedFullHost()
+ "/bigquery/v2/projects/"
+ bigqueryHelper.getOptions().getProjectId()
+ "/datasets?prettyPrint=false",
attrs.get(HttpTracingRequestInitializer.URL_FULL));
Expand Down Expand Up @@ -150,13 +150,13 @@ public void testGetDatasetNotFoundTraced() {
"projects/{+projectId}/datasets/{+datasetId}",
attrs.get(BigQueryTelemetryTracer.URL_TEMPLATE));
assertEquals(
"https://bigquery.googleapis.com/bigquery/v2/projects/"
getExpectedFullHost()
+ "/bigquery/v2/projects/"
+ bigqueryHelper.getOptions().getProjectId()
+ "/datasets/non_existent_dataset?prettyPrint=false",
attrs.get(HttpTracingRequestInitializer.URL_FULL));
assertEquals(
"bigquery.googleapis.com", attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
assertEquals("bigquery.googleapis.com", attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
assertEquals(getExpectedHost(), attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
assertEquals(getExpectedHost(), attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
assertEquals(
"//bigquery.googleapis.com/projects/"
+ bigqueryHelper.getOptions().getProjectId()
Expand Down Expand Up @@ -320,4 +320,26 @@ private void checkGeneralAttributes(Map<AttributeKey<?>, Object> attrs) {
attrs.get(BigQueryTelemetryTracer.GCP_CLIENT_ARTIFACT));
assertNotNull(attrs.get(BigQueryTelemetryTracer.GCP_CLIENT_VERSION));
}

private static String getExpectedHost() {
String host = bigqueryHelper.getOptions().getHost();
if (host == null || host.isEmpty() || host.equals("https://www.googleapis.com")) {
return "bigquery.googleapis.com";
}
if (host.startsWith("https://")) {
return host.substring("https://".length());
}
if (host.startsWith("http://")) {
return host.substring("http://".length());
}
return host;
}

private static String getExpectedFullHost() {
String host = bigqueryHelper.getOptions().getHost();
if (host == null || host.isEmpty() || host.equals("https://www.googleapis.com")) {
return "https://bigquery.googleapis.com";
}
return host;
}
}
6 changes: 6 additions & 0 deletions java-bigquerystorage/google-cloud-bigquerystorage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
</parent>
<properties>
<site.installationModule>google-cloud-bigquerystorage</site.installationModule>
<bigquery.endpoint></bigquery.endpoint>
<bigquery.storage.endpoint></bigquery.storage.endpoint>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -409,6 +411,10 @@
<buildArg>--no-fallback</buildArg>
<buildArg>--no-server</buildArg>
</buildArgs>
<environmentVariables>
<BIGQUERY_ENDPOINT>${bigquery.endpoint}</BIGQUERY_ENDPOINT>
<BIGQUERY_STORAGE_ENDPOINT>${bigquery.storage.endpoint}</BIGQUERY_STORAGE_ENDPOINT>
</environmentVariables>
</configuration>
</plugin>
</plugins>
Expand Down
Loading
Loading