src/main/java/org/embulk/output/BigqueryWriter.java in embulk-output-bigquery-0.1.2 vs src/main/java/org/embulk/output/BigqueryWriter.java in embulk-output-bigquery-0.1.3
- old
+ new
@@ -4,55 +4,37 @@
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import com.google.api.client.http.InputStreamContent;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.IllegalFormatException;
-import java.util.concurrent.Callable;
import java.util.concurrent.TimeoutException;
-import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableSet;
import com.google.common.base.Throwables;
import java.security.GeneralSecurityException;
-
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference;
import org.embulk.spi.Exec;
import org.slf4j.Logger;
import com.google.api.services.bigquery.Bigquery;
-import com.google.api.services.bigquery.BigqueryScopes;
-import com.google.api.services.bigquery.Bigquery.Datasets;
import com.google.api.services.bigquery.Bigquery.Tables;
import com.google.api.services.bigquery.Bigquery.Jobs.Insert;
-import com.google.api.services.bigquery.Bigquery.Jobs.GetQueryResults;
import com.google.api.services.bigquery.model.Job;
import com.google.api.services.bigquery.model.JobConfiguration;
import com.google.api.services.bigquery.model.JobConfigurationLoad;
-import com.google.api.services.bigquery.model.JobStatus;
import com.google.api.services.bigquery.model.JobStatistics;
import com.google.api.services.bigquery.model.JobReference;
-import com.google.api.services.bigquery.model.DatasetList;
import com.google.api.services.bigquery.model.Table;
-import com.google.api.services.bigquery.model.TableList;
import com.google.api.services.bigquery.model.TableSchema;
import com.google.api.services.bigquery.model.TableReference;
import com.google.api.services.bigquery.model.TableFieldSchema;
-import com.google.api.services.bigquery.model.TableCell;
-import com.google.api.services.bigquery.model.TableRow;
import com.google.api.services.bigquery.model.ErrorProto;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
-
import com.google.api.client.googleapis.media.MediaHttpUploader;
import com.google.api.client.googleapis.media.MediaHttpUploaderProgressListener;
-import com.google.api.client.googleapis.media.MediaHttpUploader.UploadState;
public class BigqueryWriter
{
private final Logger log = Exec.getLogger(BigqueryWriter.class);
@@ -84,11 +66,11 @@
this.encoding = builder.encoding.toUpperCase();
this.jobStatusMaxPollingTime = builder.jobStatusMaxPollingTime;
this.jobStatusPollingInterval = builder.jobStatusPollingInterval;
this.isSkipJobResultCheck = builder.isSkipJobResultCheck;
- BigqueryAuthentication auth = new BigqueryAuthentication(builder.serviceAccountEmail, builder.p12KeyFilePath, builder.applicationName);
+ BigqueryAuthentication auth = new BigqueryAuthentication(builder.authMethod, builder.serviceAccountEmail, builder.p12KeyFilePath, builder.applicationName);
this.bigQueryClient = auth.getBigqueryClient();
checkConfig();
if (autoCreateTable) {
this.tableSchema = createTableSchema(builder.schemaPath);
@@ -250,11 +232,11 @@
public void checkConfig() throws FileNotFoundException, IOException
{
if (autoCreateTable) {
if (!schemaPath.isPresent()) {
- throw new IOException("schema_path is empty");
+ throw new FileNotFoundException("schema_path is empty");
} else {
File file = new File(schemaPath.orNull());
if (!file.exists()) {
throw new FileNotFoundException("Can not load schema file.");
}
@@ -294,12 +276,13 @@
}
}
public static class Builder
{
- private final String serviceAccountEmail;
- private String p12KeyFilePath;
+ private final String authMethod;
+ private Optional<String> serviceAccountEmail;
+ private Optional<String> p12KeyFilePath;
private String applicationName;
private String project;
private String dataset;
private String table;
private boolean autoCreateTable;
@@ -310,16 +293,21 @@
private String encoding;
private int jobStatusMaxPollingTime;
private int jobStatusPollingInterval;
private boolean isSkipJobResultCheck;
+ public Builder(String authMethod)
+ {
+ this.authMethod = authMethod;
+ }
- public Builder(String serviceAccountEmail)
+ public Builder setServiceAccountEmail(Optional<String> serviceAccountEmail)
{
this.serviceAccountEmail = serviceAccountEmail;
+ return this;
}
- public Builder setP12KeyFilePath(String p12KeyFilePath)
+ public Builder setP12KeyFilePath(Optional<String> p12KeyFilePath)
{
this.p12KeyFilePath = p12KeyFilePath;
return this;
}
\ No newline at end of file