I am working to update existing records in druid by retrieving existing records ,updating and then ingesting back with updated records. So ,i need to fetch the granularity of existing datasource which will be used while ingesting back the updated records.
Asked
Active
Viewed 533 times
2 Answers
0
As none of the queryType is returning the granularity. I have retrieved the datasource details using http://localhost:8081/druid/coordinator/v1/metadata/datasources/wikiticker
then fetch the last or any segment's interval
JSONArray segmentArray = (JSONArray) dataSourceObj.get("segments"); JSONObject lastSegmentObject = new JSONObject(segmentArray.get(segmentArray.length()-1).toString()); String granularityInterval = lastSegmentObject.get("interval").toString();
then calculate difference between the date interval using any api eg: joda
SimpleDateFormat format = new SimpleDateFormat(Constants.DATE_FORMAT); Date intervalStart = format.parse(interval.split("/")[0]); Date intervalEnd = format.parse(interval.split("/")[1]);
DateTime startTime = new DateTime(intervalStart) ; DateTime endTime = new DateTime(intervalEnd) ;Period jodaPeriod = new Period(startTime, endTime); if(jodaPeriod.getYears() == 1){ return DesignerConstants.DRUID_GRANULARITY_YEAR; }else if(jodaPeriod.getMonths() == 1){ return DesignerConstants.DRUID_GRANULARITY_MONTH; }else if(jodaPeriod.getWeeks() == 1){ return DesignerConstants.DRUID_GRANULARITY_WEEK; }else if(jodaPeriod.getDays() == 1){ return DesignerConstants.DRUID_GRANULARITY_DAY; }else if(jodaPeriod.getHours() == 1){ return DesignerConstants.DRUID_GRANULARITY_HOUR; } return "none"; } </pre>

sidnakoppa
- 111
- 1
- 4
0
FYI a data source can have multiple segment granularity, that's why there is no query that will do that for you. Although the code above will return the granularity of the last segment which is different from the original question you have asked.

Slim Bouguerra
- 359
- 1
- 8