[英]how to get granularity of existing druid data source
I am working to update existing records in druid by retrieving existing records ,updating and then ingesting back with updated records. 我正在通过检索现有记录,更新然后使用更新后的记录提取回来来更新druid中的现有记录。 So ,i need to fetch the granularity of existing datasource which will be used while ingesting back the updated records. 因此,我需要获取将在提取回更新记录时使用的现有数据源的粒度。
As none of the queryType is returning the granularity. 由于没有任何queryType返回粒度。 I have retrieved the datasource details using http://localhost:8081/druid/coordinator/v1/metadata/datasources/wikiticker 我已经使用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 然后使用任何api计算日期间隔之间的差异,例如: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>
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. 尽管上面的代码将返回最后一段的粒度,该粒度与您最初询问的问题不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.