Search in sources :

Example 1 with SchemaUpdateOption

use of com.google.cloud.bigquery.JobInfo.SchemaUpdateOption in project google-cloud-java by GoogleCloudPlatform.

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);
    configurationPb.setDryRun(dryRun());
    if (allowLargeResults != null) {
        queryConfigurationPb.setAllowLargeResults(allowLargeResults);
    }
    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 (schemaUpdateOptions != null) {
        ImmutableList.Builder<String> schemaUpdateOptionsBuilder = new ImmutableList.Builder<>();
        for (JobInfo.SchemaUpdateOption schemaUpdateOption : schemaUpdateOptions) {
            schemaUpdateOptionsBuilder.add(schemaUpdateOption.name());
        }
        queryConfigurationPb.setSchemaUpdateOptions(schemaUpdateOptionsBuilder.build());
    }
    return configurationPb.setQuery(queryConfigurationPb);
}
Also used : JobConfigurationQuery(com.google.api.services.bigquery.model.JobConfigurationQuery) ImmutableList(com.google.common.collect.ImmutableList) SchemaUpdateOption(com.google.cloud.bigquery.JobInfo.SchemaUpdateOption)

Example 2 with SchemaUpdateOption

use of com.google.cloud.bigquery.JobInfo.SchemaUpdateOption in project google-cloud-java by GoogleCloudPlatform.

the class WriteChannelConfiguration method toPb.

com.google.api.services.bigquery.model.JobConfiguration toPb() {
    JobConfigurationLoad loadConfigurationPb = new JobConfigurationLoad();
    loadConfigurationPb.setDestinationTable(destinationTable.toPb());
    if (createDisposition != null) {
        loadConfigurationPb.setCreateDisposition(createDisposition.toString());
    }
    if (writeDisposition != null) {
        loadConfigurationPb.setWriteDisposition(writeDisposition.toString());
    }
    if (nullMarker != null) {
        loadConfigurationPb.setNullMarker(nullMarker);
    }
    if (getCsvOptions() != null) {
        CsvOptions csvOptions = getCsvOptions();
        loadConfigurationPb.setFieldDelimiter(csvOptions.getFieldDelimiter()).setAllowJaggedRows(csvOptions.allowJaggedRows()).setAllowQuotedNewlines(csvOptions.allowQuotedNewLines()).setEncoding(csvOptions.getEncoding()).setQuote(csvOptions.getQuote());
        if (csvOptions.getSkipLeadingRows() != null) {
            // todo(mziccard) remove checked cast or comment when #1044 is closed
            loadConfigurationPb.setSkipLeadingRows(Ints.checkedCast(csvOptions.getSkipLeadingRows()));
        }
    }
    if (schema != null) {
        loadConfigurationPb.setSchema(schema.toPb());
    }
    if (formatOptions != null) {
        loadConfigurationPb.setSourceFormat(formatOptions.getType());
    }
    loadConfigurationPb.setMaxBadRecords(maxBadRecords);
    loadConfigurationPb.setIgnoreUnknownValues(ignoreUnknownValues);
    if (getDatastoreBackupOptions() != null) {
        DatastoreBackupOptions backupOptions = getDatastoreBackupOptions();
        loadConfigurationPb.setProjectionFields(backupOptions.getProjectionFields());
    }
    if (schemaUpdateOptions != null) {
        ImmutableList.Builder<String> schemaUpdateOptionsBuilder = new ImmutableList.Builder<>();
        for (JobInfo.SchemaUpdateOption schemaUpdateOption : schemaUpdateOptions) {
            schemaUpdateOptionsBuilder.add(schemaUpdateOption.name());
        }
        loadConfigurationPb.setSchemaUpdateOptions(schemaUpdateOptionsBuilder.build());
    }
    loadConfigurationPb.setAutodetect(autodetect);
    return new com.google.api.services.bigquery.model.JobConfiguration().setLoad(loadConfigurationPb);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SchemaUpdateOption(com.google.cloud.bigquery.JobInfo.SchemaUpdateOption) JobConfigurationLoad(com.google.api.services.bigquery.model.JobConfigurationLoad)

Aggregations

SchemaUpdateOption (com.google.cloud.bigquery.JobInfo.SchemaUpdateOption)2 ImmutableList (com.google.common.collect.ImmutableList)2 JobConfigurationLoad (com.google.api.services.bigquery.model.JobConfigurationLoad)1 JobConfigurationQuery (com.google.api.services.bigquery.model.JobConfigurationQuery)1