1

내가처럼 보이는 중첩 된 필드 '위치'가 함께 일하고 데이터 :BigQuery에서 중첩 된 필드의 스키마를 지정하는 방법은 무엇입니까?

"location": { 
    "city": "Amherst", 
    "region": "NS", 
    "country": "CA" 
}, 

어떻게 자바 API를 사용하여 중첩 된 필드에 대한 스키마를 지정할 수 있습니까?

현재, 내 코드 같이 보인다 :

List<TableFieldSchema> fields = new ArrayList<TableFieldSchema>(); 
TableFieldSchema fieldLocation = new TableFieldSchema(); 
fieldFoo.setName("location"); 
fieldFoo.setType("record"); 
TableFieldSchema fieldLocationCity = new TableFieldSchema(); 
fieldBar.setName("location.city"); 
fieldBar.setType("string"); 
... 
fields.add(fieldLocation); 
fields.add(fieldLocationCity); 
TableSchema schema = new TableSchema(); 
schema.setFields(fields); 

나는 다음과 같은 오류가 점점 오전으로이 작동하지 않습니다 난 당신이 다음과 같은 일을 할 거라고 생각

CONFIG: { 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "invalid", 
    "message": "Record field location must have a schema." 
    } 
    ], 
    "code": 400, 
    "message": "Record field location must have a schema." 
} 

답변

2

을 :

List<TableFieldSchema> inner = new ArrayList<TableFieldSchema>(); 
List<TableFieldSchema> outer = new ArrayList<TableFieldSchema>(); 

TableFieldSchema fieldLocationCity = new TableFieldSchema(); 
fieldLocationCity.setName("city"); 
fieldLocationCity.setType("string"); 
// Add the inner fields to the list of fields in the record. 
inner.add(fieldLocationCity); 
...(add region & country, etc)... 

TableFieldSchema fieldLocation = new TableFieldSchema(); 
fieldLocation.setName("location"); 
fieldLocation.setType("record"); 
// Add the inner fields to the location record. 
fieldLocation.setFields(inner); 

outer.add(fieldLocation); 

TableSchema schema = new TableSchema(); 
schema.setFields(outer); 
관련 문제