In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to query druidAPI in Java? in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Maven relies on in.zapr.druid druidry 2.1
1 assemble json
/ / time range: Interval DateTime start = new DateTime (DateUtils.getToday () + "T0000Rod 00.000mm 08VOO"); DateTime end = new DateTime (); Interval interval = new Interval (start,end); / / granularity Granularity granularity = new SimpleGranularity (PredefinedGranularity.ALL); / / filter DruidFilter todayUvEventFilter = new SelectorFilter ("event", "3001"); DruidFilter todayUvPageIdFilter = new SelectorFilter ("page_id", "101l"); / / and filter DruidFilter todayUvFilters = new AndFilter (Arrays.asList (todayUvEventFilter,todayUvPageIdFilter)) / / HyperUnique aggregation DruidAggregator todayUvAggregator = new HyperUniqueAggregator ("today_uv", "user_id"); / / Filteres aggregation DruidAggregator todayUvAggregators = new FilteredAggregator (todayUvFilters,todayUvAggregator)
DruidFilter articleUvEventFilter = new SelectorFilter ("event", "3001"); DruidFilter articleUvPageIdFilter = new SelectorFilter ("page_id", "3001"); DruidFilter articleUvFilters = new AndFilter (Arrays.asList (articleUvEventFilter,articleUvPageIdFilter)); DruidAggregator articleUvAggregator = new HyperUniqueAggregator ("article_uv", "user_id"); DruidAggregator articleUvAggregators = new FilteredAggregator (articleUvFilters,articleUvAggregator)
DruidFilter ypsUvEventFilter = new SelectorFilter ("event", "3001"); DruidFilter ypsUvPageIdFilter = new SelectorFilter ("page_id", "2011"); DruidFilter ypsUvFilters = new AndFilter (Arrays.asList (ypsUvEventFilter,ypsUvPageIdFilter)); DruidAggregator ypsUvAggregator = new HyperUniqueAggregator (" yps_uv "," user_id "); DruidAggregator ypsUvAggregators = new FilteredAggregator (ypsUvFilters,ypsUvAggregator)
DruidFilter messageUvButtonIdFilter = new SelectorFilter ("button_id", "10102"); DruidFilter messageUvFilters = new AndFilter (Arrays.asList (messageUvButtonIdFilter)); DruidAggregator messageUvAggregator = new HyperUniqueAggregator ("message_uv", "user_id"); DruidAggregator messageUvAggregators = new FilteredAggregator (messageUvFilters,messageUvAggregator)
/ / PostAggregator DruidPostAggregator articleUvArticleField = new HyperUniqueCardinalityPostAggregator ("article_uv", "article_uv"); DruidPostAggregator todayUvArticleField = new HyperUniqueCardinalityPostAggregator ("today_uv", "today_uv"); DruidPostAggregator articleRatePostAgg = ArithmeticPostAggregator.builder (). Name ("article_rate") .function (ArithmeticFunction.DIVIDE) .fields (Arrays.asList (articleUvArticleField,todayUvArticleField)). Build ()
DruidPostAggregator ypsUvYpsField = new HyperUniqueCardinalityPostAggregator ("yps_uv", "yps_uv"); DruidPostAggregator todayUvYpsField = new HyperUniqueCardinalityPostAggregator ("today_uv", "today_uv"); DruidPostAggregator ypsRatePostAgg = ArithmeticPostAggregator.builder (). Name ("yps_rate") .function (ArithmeticFunction.DIVIDE) .fields (Arrays.asList (ypsUvYpsField,todayUvYpsField)). Build ()
DruidPostAggregator messageUvMessageField = new HyperUniqueCardinalityPostAggregator ("message_uv", "message_uv"); DruidPostAggregator todayUvMessageField = new HyperUniqueCardinalityPostAggregator ("today_uv", "today_uv"); DruidPostAggregator messageRatePostAgg = ArithmeticPostAggregator.builder (). Name ("message_rate") .function (ArithmeticFunction.DIVIDE) .fields (Arrays.asList (messageUvMessageField,todayUvMessageField)). Build ()
/ assemble DruidQuery DruidTimeSeriesQuery query = DruidTimeSeriesQuery.builder () .dataSource (druidProperties.getDataSourceOpenPlatform ()) .exclusiveness (granularity) .interoperability (Collections.singletonList (interval)) .aggregators (Arrays.asList (todayUvAggregators,articleUvAggregators,ypsUvAggregators,messageUvAggregators)) .postAggregators (Arrays.asList (articleRatePostAgg,ypsRatePostAgg,messageRatePostAgg)) .build (); 2 query public List queryResult (DruidQuery query) throws ConnectionException, JsonProcessingException, QueryException {ObjectMapper mapper = new ObjectMapper (); String requiredJson = mapper.writeValueAsString (query); log.info (requiredJson); DruidClient client = dataSourceDruidConfig.druidClient () Client.connect (); List responses = client.query (query, HashMap.class); client.close (); return responses;} 3 analyze and assemble the results try {List res = queryResult (query); if (resurgent null) {DecimalFormat df = new DecimalFormat ("0.005%"); for (HashMap hashMap: res) {Map event = (Map) hashMap.get ("result"); / / decimal-"percentage String yps_rate = String.valueOf (event.get (" yps_rate ")) EntiretUvRateParam.setYps_rate (df.format (Double.parseDouble (yps_rate);} catch (ConnectionException e) {e.printStackTrace (); return null;} catch (QueryException e) {e.printStackTrace (); return null;} catch (JsonProcessingException e) {e.printStackTrace (); return null;} catch (Exception e) {e.printStackTrace (); return null;}
This is the answer to the question about how to query druidAPI in Java. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.