Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -134,6 +134,8 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
Integer httpConnectTimeout;
Integer httpReadTimeout;
String requestReason;
Long connectionPoolSize;
Long listenerPoolSize;

BigQueryConnection(String url) throws IOException {
this.connectionUrl = url;
Expand All @@ -142,49 +144,33 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
this.sqlWarnings = new ArrayList<>();
this.transactionStarted = false;
this.isClosed = false;
this.labels = BigQueryJdbcUrlUtility.parseLabels(url, connectionClassName);
this.maxBytesBilled =
BigQueryJdbcUrlUtility.parseMaximumBytesBilled(url, this.connectionClassName);
this.retryTimeoutInSeconds =
BigQueryJdbcUrlUtility.parseRetryTimeoutInSecs(url, this.connectionClassName);
DataSource ds = DataSource.fromUrl(url);

this.labels = ds.getLabels() != null ? ds.getLabels() : new java.util.HashMap<>();
this.maxBytesBilled = ds.getMaximumBytesBilled();
this.retryTimeoutInSeconds = ds.getTimeout();
this.retryTimeoutDuration = Duration.ofMillis(retryTimeoutInSeconds * 1000L);
this.retryInitialDelayInSeconds =
BigQueryJdbcUrlUtility.parseRetryInitialDelayInSecs(url, this.connectionClassName);
this.retryInitialDelayInSeconds = ds.getRetryInitialDelay();
this.retryInitialDelayDuration = Duration.ofMillis(retryInitialDelayInSeconds * 1000L);
this.retryMaxDelayInSeconds =
BigQueryJdbcUrlUtility.parseRetryMaxDelayInSecs(url, this.connectionClassName);
this.retryMaxDelayInSeconds = ds.getRetryMaxDelay();
this.retryMaxDelayDuration = Duration.ofMillis(retryMaxDelayInSeconds * 1000L);
this.jobTimeoutInSeconds =
BigQueryJdbcUrlUtility.parseJobTimeout(url, this.connectionClassName);
this.jobTimeoutInSeconds = ds.getJobTimeout();
this.authProperties =
BigQueryJdbcOAuthUtility.parseOAuthProperties(url, this.connectionClassName);
this.catalog =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.PROJECT_ID_PROPERTY_NAME,
BigQueryOptions.getDefaultProjectId(),
this.connectionClassName);
this.universeDomain =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.UNIVERSE_DOMAIN_OVERRIDE_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_UNIVERSE_DOMAIN_VALUE,
this.connectionClassName);
BigQueryJdbcOAuthUtility.parseOAuthProperties(ds, this.connectionClassName);
this.catalog = ds.getProjectId();
this.universeDomain = ds.getUniverseDomain();

this.overrideProperties =
BigQueryJdbcUrlUtility.parseOverrideProperties(url, this.connectionClassName);
if (universeDomain != null) {
BigQueryJdbcUrlUtility.parseOverrideProperties(
this.connectionUrl, this.connectionClassName);
Comment thread
keshavdandeva marked this conversation as resolved.
Outdated
if (this.universeDomain != null) {
this.overrideProperties.put(
BigQueryJdbcUrlUtility.UNIVERSE_DOMAIN_OVERRIDE_PROPERTY_NAME, universeDomain);
BigQueryJdbcUrlUtility.UNIVERSE_DOMAIN_OVERRIDE_PROPERTY_NAME, this.universeDomain);
}
this.credentials =
BigQueryJdbcOAuthUtility.getCredentials(
authProperties, overrideProperties, this.connectionClassName);
String defaultDatasetString =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.DEFAULT_DATASET_PROPERTY_NAME,
null,
this.connectionClassName);
String defaultDatasetString = ds.getDefaultDataset();
if (defaultDatasetString == null || defaultDatasetString.trim().isEmpty()) {
this.defaultDataset = null;
} else {
Expand All @@ -199,94 +185,38 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
+ " projectId.datasetId");
}
}
this.location =
BigQueryJdbcUrlUtility.parseStringProperty(
url, BigQueryJdbcUrlUtility.LOCATION_PROPERTY_NAME, null, this.connectionClassName);
this.enableHighThroughputAPI =
BigQueryJdbcUrlUtility.parseBooleanProperty(
url,
BigQueryJdbcUrlUtility.ENABLE_HTAPI_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_ENABLE_HTAPI_VALUE,
this.connectionClassName);
this.highThroughputMinTableSize =
BigQueryJdbcUrlUtility.parseIntProperty(
url,
BigQueryJdbcUrlUtility.HTAPI_MIN_TABLE_SIZE_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_HTAPI_MIN_TABLE_SIZE_VALUE,
this.connectionClassName);
this.highThroughputActivationRatio =
BigQueryJdbcUrlUtility.parseIntProperty(
url,
BigQueryJdbcUrlUtility.HTAPI_ACTIVATION_RATIO_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_HTAPI_ACTIVATION_RATIO_VALUE,
this.connectionClassName);
this.useQueryCache =
BigQueryJdbcUrlUtility.parseBooleanProperty(
url,
BigQueryJdbcUrlUtility.USE_QUERY_CACHE_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_USE_QUERY_CACHE,
this.connectionClassName);
this.useStatelessQueryMode =
BigQueryJdbcUrlUtility.parseJobCreationMode(url, this.connectionClassName);
this.queryDialect =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.QUERY_DIALECT_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_QUERY_DIALECT_VALUE,
this.connectionClassName);
this.allowLargeResults =
BigQueryJdbcUrlUtility.parseBooleanProperty(
url,
BigQueryJdbcUrlUtility.ALLOW_LARGE_RESULTS_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_ALLOW_LARGE_RESULTS,
this.connectionClassName);
this.destinationTable =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.LARGE_RESULTS_TABLE_PROPERTY_NAME,
null,
this.connectionClassName);
this.destinationDataset =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.LARGE_RESULTS_DATASET_PROPERTY_NAME,
null,
this.connectionClassName);
this.destinationDatasetExpirationTime =
BigQueryJdbcUrlUtility.parseLongProperty(
url,
BigQueryJdbcUrlUtility.DESTINATION_DATASET_EXPIRATION_TIME_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_DESTINATION_DATASET_EXPIRATION_TIME_VALUE,
this.connectionClassName);
this.kmsKeyName =
BigQueryJdbcUrlUtility.parseStringProperty(
url, BigQueryJdbcUrlUtility.KMS_KEY_NAME_PROPERTY_NAME, null, this.connectionClassName);
this.location = ds.getLocation();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a though - do we really need all these property duplicates here? Can we make a copy of DataSource object & update getters instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can do that. It will be better than this but I would suggest to do it in a separate PR so it is easier to review and test. Also, might need a bit checking if it wont cause any issues

this.enableHighThroughputAPI = ds.getEnableHighThroughputAPI();
this.highThroughputMinTableSize = ds.getHighThroughputMinTableSize();
this.highThroughputActivationRatio = ds.getHighThroughputActivationRatio();
this.useQueryCache = ds.getUseQueryCache();
Integer jobCreationMode = ds.getJobCreationMode();
if (jobCreationMode == 2) {
this.useStatelessQueryMode = true;
} else if (jobCreationMode == 1) {
this.useStatelessQueryMode = false;
} else {
throw new NumberFormatException(
String.format(
"Invalid value for %s. Use 1 for JOB_CREATION_REQUIRED and 2 for"
+ " JOB_CREATION_OPTIONAL.",
BigQueryJdbcUrlUtility.JOB_CREATION_MODE_PROPERTY_NAME));
}
Comment thread
keshavdandeva marked this conversation as resolved.
Outdated

this.queryDialect = ds.getQueryDialect();
this.allowLargeResults = ds.getAllowLargeResults();
this.destinationTable = ds.getDestinationTable();
this.destinationDataset = ds.getDestinationDataset();
this.destinationDatasetExpirationTime = ds.getDestinationDatasetExpirationTime();
this.kmsKeyName = ds.getKmsKeyName();
Map<String, String> proxyProperties =
BigQueryJdbcProxyUtility.parseProxyProperties(url, this.connectionClassName);
this.sslTrustStorePath =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.SSL_TRUST_STORE_PROPERTY_NAME,
null,
this.connectionClassName);
this.sslTrustStorePassword =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.SSL_TRUST_STORE_PWD_PROPERTY_NAME,
null,
this.connectionClassName);
this.httpConnectTimeout =
BigQueryJdbcUrlUtility.parseIntProperty(
url,
BigQueryJdbcUrlUtility.HTTP_CONNECT_TIMEOUT_PROPERTY_NAME,
null,
this.connectionClassName);
this.httpReadTimeout =
BigQueryJdbcUrlUtility.parseIntProperty(
url,
BigQueryJdbcUrlUtility.HTTP_READ_TIMEOUT_PROPERTY_NAME,
null,
this.connectionClassName);
BigQueryJdbcProxyUtility.parseProxyProperties(ds, this.connectionClassName);

this.sslTrustStorePath = ds.getSSLTrustStorePath();
this.sslTrustStorePassword = ds.getSSLTrustStorePassword();
this.httpConnectTimeout = ds.getHttpConnectTimeout();
this.httpReadTimeout = ds.getHttpReadTimeout();

this.httpTransportOptions =
BigQueryJdbcProxyUtility.getHttpTransportOptions(
proxyProperties,
Expand All @@ -301,75 +231,28 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
this.sslTrustStorePath,
this.sslTrustStorePassword,
this.connectionClassName);
this.enableSession =
BigQueryJdbcUrlUtility.parseBooleanProperty(
url,
BigQueryJdbcUrlUtility.ENABLE_SESSION_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_ENABLE_SESSION_VALUE,
this.connectionClassName);
this.unsupportedHTAPIFallback =
BigQueryJdbcUrlUtility.parseBooleanProperty(
url,
BigQueryJdbcUrlUtility.UNSUPPORTED_HTAPI_FALLBACK_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_UNSUPPORTED_HTAPI_FALLBACK_VALUE,
this.connectionClassName);
this.maxResults =
BigQueryJdbcUrlUtility.parseLongProperty(
url,
BigQueryJdbcUrlUtility.MAX_RESULTS_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_MAX_RESULTS_VALUE,
this.connectionClassName);
Map<String, String> queryPropertiesMap =
BigQueryJdbcUrlUtility.parseQueryProperties(url, this.connectionClassName);
this.enableSession = ds.getEnableSession();
this.unsupportedHTAPIFallback = ds.getUnsupportedHTAPIFallback();
this.maxResults = ds.getMaxResults();
Map<String, String> queryPropertiesMap = ds.getQueryProperties();
this.sessionInfoConnectionProperty = getSessionPropertyFromQueryProperties(queryPropertiesMap);
this.queryProperties = convertMapToConnectionPropertiesList(queryPropertiesMap);
this.enableWriteAPI =
BigQueryJdbcUrlUtility.parseBooleanProperty(
url,
BigQueryJdbcUrlUtility.ENABLE_WRITE_API_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_ENABLE_WRITE_API_VALUE,
this.connectionClassName);
this.writeAPIActivationRowCount =
BigQueryJdbcUrlUtility.parseIntProperty(
url,
BigQueryJdbcUrlUtility.SWA_ACTIVATION_ROW_COUNT_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_SWA_ACTIVATION_ROW_COUNT_VALUE,
this.connectionClassName);
this.writeAPIAppendRowCount =
BigQueryJdbcUrlUtility.parseIntProperty(
url,
BigQueryJdbcUrlUtility.SWA_APPEND_ROW_COUNT_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_SWA_APPEND_ROW_COUNT_VALUE,
this.connectionClassName);
this.enableWriteAPI = ds.getEnableWriteAPI();
this.writeAPIActivationRowCount = ds.getSwaActivationRowCount();
this.writeAPIAppendRowCount = ds.getSwaAppendRowCount();

String additionalProjectsStr = ds.getAdditionalProjects();
this.additionalProjects =
BigQueryJdbcUrlUtility.parseStringListProperty(
url,
BigQueryJdbcUrlUtility.ADDITIONAL_PROJECTS_PROPERTY_NAME,
this.connectionClassName);
this.filterTablesOnDefaultDataset =
BigQueryJdbcUrlUtility.parseBooleanProperty(
url,
BigQueryJdbcUrlUtility.FILTER_TABLES_ON_DEFAULT_DATASET_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_FILTER_TABLES_ON_DEFAULT_DATASET_VALUE,
this.connectionClassName);
this.requestGoogleDriveScope =
BigQueryJdbcUrlUtility.parseIntProperty(
url,
BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_REQUEST_GOOGLE_DRIVE_SCOPE_VALUE,
this.connectionClassName);
this.metadataFetchThreadCount =
BigQueryJdbcUrlUtility.parseIntProperty(
url,
BigQueryJdbcUrlUtility.METADATA_FETCH_THREAD_COUNT_PROPERTY_NAME,
BigQueryJdbcUrlUtility.DEFAULT_METADATA_FETCH_THREAD_COUNT_VALUE,
this.connectionClassName);
this.requestReason =
BigQueryJdbcUrlUtility.parseStringProperty(
url,
BigQueryJdbcUrlUtility.REQUEST_REASON_PROPERTY_NAME,
null,
this.connectionClassName);
(additionalProjectsStr == null || additionalProjectsStr.isEmpty())
? java.util.Collections.emptyList()
: java.util.Arrays.asList(additionalProjectsStr.split(","));
Comment thread
keshavdandeva marked this conversation as resolved.
Outdated

this.filterTablesOnDefaultDataset = ds.getFilterTablesOnDefaultDataset();
this.requestGoogleDriveScope = ds.getRequestGoogleDriveScope();
this.metadataFetchThreadCount = ds.getMetadataFetchThreadCount();
this.requestReason = ds.getRequestReason();
this.connectionPoolSize = ds.getConnectionPoolSize();
this.listenerPoolSize = ds.getListenerPoolSize();

HEADER_PROVIDER = createHeaderProvider();
this.bigQuery = getBigQueryConnection();
Expand Down Expand Up @@ -760,6 +643,14 @@ Integer getHttpReadTimeout() {
return httpReadTimeout;
}

Long getConnectionPoolSize() {
return connectionPoolSize;
}

Long getListenerPoolSize() {
return listenerPoolSize;
}

@Override
public boolean isValid(int timeout) throws SQLException {
if (timeout < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,17 @@ public Connection connect(String url, Properties info) throws SQLException {
throw new BigQueryJdbcException(e.getMessage(), e);
}

DataSource ds = DataSource.fromUrl(connectionUri);

// LogLevel
String logLevelStr =
BigQueryJdbcUrlUtility.parseUriProperty(
connectionUri, BigQueryJdbcUrlUtility.LOG_LEVEL_PROPERTY_NAME);
String logLevelStr = ds.getLogLevel();
if (logLevelStr == null) {
logLevelStr = System.getenv(BigQueryJdbcUrlUtility.LOG_LEVEL_ENV_VAR);
}
Level logLevel = BigQueryJdbcUrlUtility.parseLogLevel(logLevelStr);

// LogPath
String logPath =
BigQueryJdbcUrlUtility.parseUriProperty(
connectionUri, BigQueryJdbcUrlUtility.LOG_PATH_PROPERTY_NAME);
String logPath = ds.getLogPath();
if (logPath == null) {
logPath = System.getenv(BigQueryJdbcUrlUtility.LOG_PATH_ENV_VAR);
}
Expand Down Expand Up @@ -217,7 +215,7 @@ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
propertyInfoList.add(driverProperty);
}
Map<String, String> oAuthProperties =
BigQueryJdbcOAuthUtility.parseOAuthProperties(url, this.toString());
BigQueryJdbcOAuthUtility.parseOAuthProperties(DataSource.fromUrl(url), this.toString());
Comment thread
keshavdandeva marked this conversation as resolved.
Outdated
for (Map.Entry<String, String> authProperty : oAuthProperties.entrySet()) {
propertyInfoList.add(new DriverPropertyInfo(authProperty.getKey(), authProperty.getValue()));
}
Expand Down
Loading
Loading