0
getqueryResults로 bigquery 작업에서 List를 가져오고 있으며 JSON으로의 변환이 실패한 것 같습니다. 내가 this을 발견했습니다 다음과 같이 주석 그것을 시도 : 성공하지오류 : com.fasterxml.jackson.databind.JsonMappingException : serializer가 없습니다.
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
비록. 여기
코드의 조각 :
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.bigquery.Bigquery;
import com.google.api.services.bigquery.BigqueryScopes;
import com.google.api.services.bigquery.model.*;
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class Query {
private String id;
private String sql;
private List<TableRow> results;
private static Bigquery createAuthorizedClient() throws IOException {
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
// Depending on the environment that provides the default credentials (e.g. Compute Engine, App
// Engine), the credentials may require us to specify the scopes we need explicitly.
// Check for this case, and inject the Bigquery scope if required.
if (credential.createScopedRequired()) {
credential = credential.createScoped(BigqueryScopes.all());
}
return new Bigquery.Builder(transport, jsonFactory, credential).setApplicationName(" ...OMITTED... ").build();
}
public String getId() { return this.id;}
public void setId(String id) { this.id = id; }
public String getSql() { return this.sql; }
public void setSql(String sql) { this.sql = sql;}
public List<TableRow> getResults() { return this.results; }
public void setResults(List<TableRow> r) { this.results = r; }
public void update() {
this.results = new ArrayList<TableRow>();
if (!this.sql.isEmpty()){
try {
Bigquery bq = createAuthorizedClient();
this.results = executeQuery(bq, this.sql);
} catch (IOException e) {
e.printStackTrace();
}
}
}
private List<TableRow> executeQuery(Bigquery bq, String querySql) throws IOException {
QueryResponse query = bq.jobs().query(" ...OMITTED... ", new QueryRequest().setQuery(querySql)).execute();
// Execute it
GetQueryResultsResponse queryResult = bq.jobs()
.getQueryResults(query.getJobReference().getProjectId(), query.getJobReference().getJobId()).execute();
List<TableRow> rows = queryResult.getRows();
return rows;
}
내가 주석에 익숙하지 그리고 난 BigQuery에서이 JSON 변환에서 응답을 얻는 방법을 모른다, 누군가가 도와 드릴까요?