인턴기록지
[Druid] 이미 있는 Datasource에 데이터 추가하기 본문
Adding new data (on existing data)
Druid can insert new data to an existing datasource by appending new segments to existing segment sets. It can also add new data by merging an existing set of segments with new data and overwriting the original set.
Druid does not support single-record updates by primary key.
https://stackoverflow.com/questions/51106037/upload-data-to-druid-incrementally
https://stackoverflow.com/questions/59132597/apache-druid-issue-while-updating-the-data-in-datasource
위 링크의 댓글 보니 appentToExisting 을 true / false 를 이용한다고 한다.
dataSource의 이름만 같게 하면 append/overwrite 가능
그래서 새로 1row.txt 파일을 생성해서 8개의 데이터를 넣어줬다.
{"bike_id": "SJ-0001", "user_id": "junecy", "rental_date": "2014-10-07T10:42:00.00Z", "station_rental_id": "2390850000000C", "return_date": "2014-10-07T10:43:00.00Z", "station_return_id": "2390850000000C", "usage_time": "0.0", "distance": "0.0", "mileage": "N", "day_type": "1", "holiday": "N", "bike_type": "old", "holiday2": "N"} {"bike_id": "SJ-0001", "user_id": "junecy", "rental_date": "2014-10-07T10:44:00.00Z", "station_rental_id": "2390850000000C", "return_date": "2014-10-28T17:22:00.00Z", "station_return_id": "2390850000000A", "usage_time": "0.0", "distance": "0.0", "mileage": "N", "day_type": "1", "holiday": "N", "bike_type": "old", "holiday2": "N"} {"bike_id": "SJ-0001", "user_id": "msh2095", "rental_date": "2014-10-28T19:14:00.00Z", "station_rental_id": "2390850000000A", "return_date": "2014-10-28T19:14:00.00Z", "station_return_id": "2390850000000A", "usage_time": "0.0", "distance": "0.0", "mileage": "N", "day_type": "1", "holiday": "N", "bike_type": "old", "holiday2": "N"} {"bike_id": "SJ-0001", "user_id": "msh2095", "rental_date": "2014-10-28T19:16:00.00Z", "station_rental_id": "2390850000000A", "return_date": "2014-10-28T19:16:00.00Z", "station_return_id": "2390850000000A", "usage_time": "0.0", "distance": "0.0", "mileage": "N", "day_type": "1", "holiday": "N", "bike_type": "old", "holiday2": "N"} {"bike_id": "SJ-0001", "user_id": "tjs0135", "rental_date": "2014-10-29T11:14:00.00Z", "station_rental_id": "2390850000000A", "return_date": "2014-10-29T15:31:00.00Z", "station_return_id": "2390850000000D", "usage_time": "256.0", "distance": "4830.0", "mileage": "N", "day_type": "2", "holiday": "N", "bike_type": "old", "holiday2": "N"} {"bike_id": "SJ-0001", "user_id": "hjk0272", "rental_date": "2014-10-30T12:48:00.00Z", "station_rental_id": "2390850000000D", "return_date": "2014-10-30T12:49:00.00Z", "station_return_id": "2390850000000D", "usage_time": "0.0", "distance": "0.0", "mileage": "N", "day_type": "3", "holiday": "N", "bike_type": "old", "holiday2": "N"} {"bike_id": "SJ-0001", "user_id": "tjs0135", "rental_date": "2014-10-30T15:07:00.00Z", "station_rental_id": "2390850000000D", "return_date": "2014-10-30T15:20:00.00Z", "station_return_id": "2390850000000A", "usage_time": "13.0", "distance": "1400.0", "mileage": "N", "day_type": "3", "holiday": "N", "bike_type": "old", "holiday2": "N"} {"bike_id": "SJ-0001", "user_id": "ttiger39", "rental_date": "2014-11-03T09:55:00.00Z", "station_rental_id": "2390850000000A", "return_date": "2014-11-03T10:07:00.00Z", "station_return_id": "2.39085E+13", "usage_time": "0.0", "distance": "0.0", "mileage": "N", "day_type": "0", "holiday": "N", "bike_type": "old", "holiday2": "N"}
1. appendtoexisting = false 일때
=> 이전에 올린 드루이드 데이터에 새로추가된 데이터 8개를 넣으면 append가 아닌 overwrite되서 덮여진다.
그래서 세그먼트를 통합해줘서 따로 세그먼트 통합과정이 필요없다. (num rows보면 잘 들어간 것이 확인 가능)
"ioConfig" : { "type":"index_parallel", "inputSource" : { "type":"local", "baseDir":"quickstart/tutorial", "filter":"1row.txt" }, "inputFormat" : { "type" : "json" }, "appendToExisting":false }
curl -X 'POST' -H 'Content-Type:application/json' -d @100-index.json http://localhost:8081/druid/indexer/v1/task


2. appendtoexisting = true 일때
=> 이전에 드루이드에 올린 데이터에 그대로 2개의 데이터를 append해준다.
그래서 세그먼트를 통합해 주지 않고 다 다른 세그먼트인 것처럼 구분되서 올라간다.
"ioConfig" : { "type":"index_parallel", "inputSource" : { "type":"local", "baseDir":"quickstart/tutorial", "filter":"1row.txt" }, "inputFormat" : { "type" : "json" }, "appendToExisting":true } # 1row.txt {"bike_id": "SJ-0001", "user_id": "ysb0722", "rental_date": "2014-11-04T15:58:00.00Z", "station_rental_id": "2.39085E+13", "return_date": "2014-11-04T16:02:00.00Z", "station_return_id": "2.39085E+13", "usage_time": "3.0", "distance": "450.0", "mileage": "N", "day_type": "1", "holiday": "N", "bike_type": "old", "holiday2": "N"} {"bike_id": "SJ-0001", "user_id": "ysb0722", "rental_date": "2014-11-04T19:04:00.00Z", "station_rental_id": "2.39085E+13", "return_date": "2014-11-04T19:08:00.00Z", "station_return_id": "2.39085E+13", "usage_time": "3.0", "distance": "450.0", "mileage": "N", "day_type": "1", "holiday": "N", "bike_type": "old", "holiday2": "N"}
위의 1row.txt 를 다시 ingestion해준다.
1번의 결과화면의 세번째 세그먼트 를 보면 11.03-11.10까지가 한 세그먼트이다. 여기에 11.04의 데이터 2개를 넣으면
총 row수가 2개 늘어난 것 확인, 세그먼트도 1개 늘어난 것을 확인

위의 사진 보면 11.03-11.10의 세그먼트가 하나 더 생겨서 partition 1로 된것을 확인 할 수 있다.

에러난 것
Unknown exception / Unexpected response status [307] description [Temporary Redirect]
세그먼트 통합 튜토리얼
https://druid.apache.org/docs/latest/tutorials/tutorial-compaction.html
'Druid > Project' 카테고리의 다른 글
| python2 code convert to python3 (0) | 2020.09.21 |
|---|---|
| [Druid] post-index-task-main 코드 분석 (0) | 2020.09.21 |
| 데이터 파일 python으로 드루이드에 자동으로 올리기 (0) | 2020.09.18 |
| [Druid] Writing an ingestion spec - rollup이 된 data (0) | 2020.09.17 |
| [Druid] Writing an ingestion spec - rollup이 되지않은 data (0) | 2020.09.17 |