Presto에서 mongoDB 컬렉션 조회시 특정 컬럼 인식이 안될 때...
mongoDB는 스키마가 없습니다.
그런데 Presto에서는 조회하는 테이블(컬렉션)의 스키마를 필요로 합니다.
그래서 Presto에서 mongoDB를 연결하게 되면, "_schema" 컬렉션이 mongoDB에 생성이 됩니다.
그리고 컬렉션마다 첫번째 값 기준으로 테이블명과 필드명을 "_schema"에 추가하여 사용하게 됩니다.
즉 나중에 추가된 필드는 반영이 안되어 있기 때문에 그 필드를 Presto에서 조회할 때 인식을 못해서 에러가 나는 것입니다.
해결 책은 "_schema"에 해당 필드 정보를 추가해 주면 됩니다.
ex) "orders"라는 컬렉션에 "prdt_nm" 필드를 추가해 주는 예제 입니다.
>> 추가
db._schema.update( {table:'orders'}, {$push:{fields:{'name':'prdt_nm', 'type':'varchar', 'hidden':false}}} )
>> 삭제
db._schema.update( {table:'orders'}, {$pull:{fields:{'name':'prdt_nm', 'type':'varchar', 'hidden':false}}} )
참고
A schema collection consists of a MongoDB document for a table.
{ "table": ..., "fields": [ { "name" : ..., "type" : "varchar|bigint|boolean|double|date|array(bigint)|...", "hidden" : false }, ... ] } }
FieldRequiredTypeDescription
table | required | string | Presto table name |
fields | required | array | A list of field definitions. Each field definition creates a new column in the Presto table. |
Each field definition:
{ "name": ..., "type": ..., "hidden": ... }
FieldRequiredTypeDescription
name | required | string | Name of the column in the Presto table. |
type | required | string | Presto type of the column. |
hidden | optional | boolean | Hides the column from DESCRIBE <table name> and SELECT *. Defaults to false. |