2
我試圖使用java api將本地csv文件導入BigQuery。無法使用Java API將本地csv文件上傳到BigQuery
但我沒能做到。在發生
如果你明白我錯在下面的代碼,請讓我知道...
TableSchema schema = new TableSchema();
ArrayList<TableFieldSchema> fields = new ArrayList<TableFieldSchema>();
fields.add(new TableFieldSchema().setName("nn").setType("String"));
fields.add(new TableFieldSchema().setName("gg").setType("String"));
fields.add(new TableFieldSchema().setName("uu").setType("String"));
schema.setFields(fields);
TableReference destTable = new TableReference();
destTable.setProjectId(projectId);
destTable.setDatasetId(datasetId);
destTable.setTableId("testUploads_fromJava");
FileContent content = new FileContent("application/octet-stream", new File(csv));
Job job = new Job();
JobConfiguration config = new JobConfiguration();
JobConfigurationLoad configLoad = new JobConfigurationLoad();
configLoad.setSchema(schema);
configLoad.setDestinationTable(destTable);
config.setLoad(configLoad);
job.setConfiguration(config);
Insert insert = bigquery.jobs().insert(projectId, job, content);
insert.setProjectId(projectId);
JobReference jobRef = insert.execute().getJobReference();
錯誤 「JobReference jobRef = insert.execute()getJobReference();」。
這是錯誤代碼。
java.lang.NullPointerException
at java.net.URI$Parser.parse(URI.java:3004)
at java.net.URI.<init>(URI.java:577)
at com.google.api.client.http.GenericUrl.<init>(GenericUrl.java:100)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:269)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:408)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:328)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:449)
at bigquery.GettingBigQueryResult.loadLocalCSVtoBQ(GettingBigQueryResult.java:117)
at main.GetBQData.main(GetBQData.java:70)
謝謝。
確保您的本地文件的URI是正確的。看起來像'NPE'來自URI。 – greeness