use of com.google.api.services.bigquery.model.QueryParameter in project java-bigquery by googleapis.
the class ConnectionImpl method dryRun.
/**
* This method runs a dry run query
*
* @param sql SQL SELECT statement
* @return BigQueryDryRunResult containing List<Parameter> and Schema
* @throws BigQuerySQLException
*/
@BetaApi
@Override
public BigQueryDryRunResult dryRun(String sql) throws BigQuerySQLException {
com.google.api.services.bigquery.model.Job dryRunJob = createDryRunJob(sql);
Schema schema = Schema.fromPb(dryRunJob.getStatistics().getQuery().getSchema());
List<QueryParameter> queryParametersPb = dryRunJob.getStatistics().getQuery().getUndeclaredQueryParameters();
List<Parameter> queryParameters = Lists.transform(queryParametersPb, QUERY_PARAMETER_FROM_PB_FUNCTION);
QueryStatistics queryStatistics = JobStatistics.fromPb(dryRunJob);
SessionInfo sessionInfo = queryStatistics.getSessionInfo() == null ? null : queryStatistics.getSessionInfo();
BigQueryResultStats bigQueryResultStats = new BigQueryResultStatsImpl(queryStatistics, sessionInfo);
return new BigQueryDryRunResultImpl(schema, queryParameters, bigQueryResultStats);
}
use of com.google.api.services.bigquery.model.QueryParameter in project java-bigquery by googleapis.
the class QueryJobConfiguration method toPb.
@Override
com.google.api.services.bigquery.model.JobConfiguration toPb() {
com.google.api.services.bigquery.model.JobConfiguration configurationPb = new com.google.api.services.bigquery.model.JobConfiguration();
JobConfigurationQuery queryConfigurationPb = new JobConfigurationQuery();
queryConfigurationPb.setQuery(query);
if (!positionalParameters.isEmpty()) {
List<QueryParameter> queryParametersPb = Lists.transform(positionalParameters, POSITIONAL_PARAMETER_TO_PB_FUNCTION);
queryConfigurationPb.setQueryParameters(queryParametersPb);
} else if (!namedParameters.isEmpty()) {
List<QueryParameter> queryParametersPb = Lists.transform(namedParameters.entrySet().asList(), NAMED_PARAMETER_TO_PB_FUNCTION);
queryConfigurationPb.setQueryParameters(queryParametersPb);
}
if (parameterMode != null) {
queryConfigurationPb.setParameterMode(parameterMode);
}
configurationPb.setDryRun(dryRun());
if (allowLargeResults != null) {
queryConfigurationPb.setAllowLargeResults(allowLargeResults);
}
if (createSession != null) {
queryConfigurationPb.setCreateSession(createSession);
}
if (createDisposition != null) {
queryConfigurationPb.setCreateDisposition(createDisposition.toString());
}
if (destinationTable != null) {
queryConfigurationPb.setDestinationTable(destinationTable.toPb());
}
if (defaultDataset != null) {
queryConfigurationPb.setDefaultDataset(defaultDataset.toPb());
}
if (flattenResults != null) {
queryConfigurationPb.setFlattenResults(flattenResults);
}
if (priority != null) {
queryConfigurationPb.setPriority(priority.toString());
}
if (tableDefinitions != null) {
queryConfigurationPb.setTableDefinitions(Maps.transformValues(tableDefinitions, ExternalTableDefinition.TO_EXTERNAL_DATA_FUNCTION));
}
if (useQueryCache != null) {
queryConfigurationPb.setUseQueryCache(useQueryCache);
}
if (userDefinedFunctions != null) {
queryConfigurationPb.setUserDefinedFunctionResources(Lists.transform(userDefinedFunctions, UserDefinedFunction.TO_PB_FUNCTION));
}
if (writeDisposition != null) {
queryConfigurationPb.setWriteDisposition(writeDisposition.toString());
}
if (useLegacySql != null) {
queryConfigurationPb.setUseLegacySql(useLegacySql);
}
if (maximumBillingTier != null) {
queryConfigurationPb.setMaximumBillingTier(maximumBillingTier);
}
if (maximumBytesBilled != null) {
queryConfigurationPb.setMaximumBytesBilled(maximumBytesBilled);
}
if (schemaUpdateOptions != null) {
ImmutableList.Builder<String> schemaUpdateOptionsBuilder = new ImmutableList.Builder<>();
for (JobInfo.SchemaUpdateOption schemaUpdateOption : schemaUpdateOptions) {
schemaUpdateOptionsBuilder.add(schemaUpdateOption.name());
}
queryConfigurationPb.setSchemaUpdateOptions(schemaUpdateOptionsBuilder.build());
}
if (destinationEncryptionConfiguration != null) {
queryConfigurationPb.setDestinationEncryptionConfiguration(destinationEncryptionConfiguration.toPb());
}
if (timePartitioning != null) {
queryConfigurationPb.setTimePartitioning(timePartitioning.toPb());
}
if (clustering != null) {
queryConfigurationPb.setClustering(clustering.toPb());
}
if (jobTimeoutMs != null) {
configurationPb.setJobTimeoutMs(jobTimeoutMs);
}
if (labels != null) {
configurationPb.setLabels(labels);
}
if (rangePartitioning != null) {
queryConfigurationPb.setRangePartitioning(rangePartitioning.toPb());
}
if (connectionProperties != null) {
queryConfigurationPb.setConnectionProperties(Lists.transform(connectionProperties, ConnectionProperty.TO_PB_FUNCTION));
}
configurationPb.setQuery(queryConfigurationPb);
return configurationPb;
}
Aggregations