4444import java .util .stream .Collectors ;
4545import java .util .stream .Stream ;
4646import java .util .stream .StreamSupport ;
47+ import org .embulk .config .ConfigException ;
4748import org .embulk .output .bigquery_java .config .BigqueryColumnOption ;
4849import org .embulk .output .bigquery_java .config .BigqueryTimePartitioning ;
4950import org .embulk .output .bigquery_java .config .PluginTask ;
@@ -83,7 +84,7 @@ public class BigqueryClient {
8384 public BigqueryClient (PluginTask task , Schema schema ) {
8485 this .task = task ;
8586 this .schema = schema ;
86- project = task .getProject ().orElse ( getProjectIdFromJsonKeyfile () );
87+ project = task .getProject ().orElseGet ( this :: getProjectIdFromJsonKeyfile );
8788 destinationProject = task .getDestinationProject ().orElse (project );
8889 destinationDataset = task .getDataset ();
8990 if (task .getLocation ().isPresent ()) {
@@ -102,9 +103,14 @@ public BigqueryClient(PluginTask task, Schema schema) {
102103 }
103104
104105 private String getProjectIdFromJsonKeyfile () {
105- return new JSONObject (
106- new JSONTokener (new ByteArrayInputStream (task .getJsonKeyfile ().getContent ())))
107- .getString ("project_id" );
106+ String projectId =
107+ new JSONObject (
108+ new JSONTokener (new ByteArrayInputStream (task .getJsonKeyfile ().getContent ())))
109+ .getString ("project_id" );
110+ if (projectId == null ) {
111+ throw new ConfigException ("Either project or project_id in json_keyfile is required" );
112+ }
113+ return projectId ;
108114 }
109115
110116 private BigQuery getBigQueryService () throws IOException {
0 commit comments