Search in sources :

Example 6 with QueryParameter

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);
}
Also used : QueryParameter(com.google.api.services.bigquery.model.QueryParameter) ArrowSchema(com.google.cloud.bigquery.storage.v1.ArrowSchema) SessionInfo(com.google.cloud.bigquery.JobStatistics.SessionInfo) QueryStatistics(com.google.cloud.bigquery.JobStatistics.QueryStatistics) QueryParameter(com.google.api.services.bigquery.model.QueryParameter) BetaApi(com.google.api.core.BetaApi)

Example 7 with QueryParameter

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;
}
Also used : QueryParameter(com.google.api.services.bigquery.model.QueryParameter) JobConfigurationQuery(com.google.api.services.bigquery.model.JobConfigurationQuery) ImmutableList(com.google.common.collect.ImmutableList) SchemaUpdateOption(com.google.cloud.bigquery.JobInfo.SchemaUpdateOption) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

QueryParameter (com.google.api.services.bigquery.model.QueryParameter)7 JobConfigurationQuery (com.google.api.services.bigquery.model.JobConfigurationQuery)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 BetaApi (com.google.api.core.BetaApi)1 QueryRequest (com.google.api.services.bigquery.model.QueryRequest)1 SchemaUpdateOption (com.google.cloud.bigquery.JobInfo.SchemaUpdateOption)1 QueryStatistics (com.google.cloud.bigquery.JobStatistics.QueryStatistics)1 SessionInfo (com.google.cloud.bigquery.JobStatistics.SessionInfo)1 ArrowSchema (com.google.cloud.bigquery.storage.v1.ArrowSchema)1 List (java.util.List)1