中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java中怎么查詢druidAPI

發布時間:2021-07-30 11:37:03 來源:億速云 閱讀:288 作者:Leah 欄目:大數據

Java中怎么查詢druidAPI,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

maven依賴 <dependency> <groupId>in.zapr.druid</groupId> <artifactId>druidry</artifactId> <version>2.1</version> </dependency>

1 組裝json

//時間范圍:Interval DateTime start = new DateTime(DateUtils.getToday()+"T00:00:00.000+08:00"); DateTime end = new DateTime(); Interval interval = new Interval(start,end); // 粒度 Granularity granularity = new SimpleGranularity(PredefinedGranularity.ALL); // 過濾 DruidFilter todayUvEventFilter = new SelectorFilter("event","3001"); DruidFilter todayUvPageIdFilter = new SelectorFilter("page_id","101"); // and過濾 DruidFilter todayUvFilters = new AndFilter(Arrays.asList(todayUvEventFilter,todayUvPageIdFilter)); // HyperUnique 聚合 DruidAggregator todayUvAggregator = new HyperUniqueAggregator("today_uv","user_id"); // Filteres聚合 DruidAggregator todayUvAggregators = new FilteredAggregator(todayUvFilters,todayUvAggregator);

DruidFilter articleUvEventFilter = new SelectorFilter("event","3001"); DruidFilter articleUvPageIdFilter = new SelectorFilter("page_id","102"); 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","201"); 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();

//組裝DruidQuery DruidTimeSeriesQuery query = DruidTimeSeriesQuery.builder() .dataSource(druidProperties.getDataSourceOpenPlatform()) .granularity(granularity) .intervals(Collections.singletonList(interval)) .aggregators(Arrays.asList(todayUvAggregators,articleUvAggregators,ypsUvAggregators,messageUvAggregators)) .postAggregators(Arrays.asList(articleRatePostAgg,ypsRatePostAgg,messageRatePostAgg)) .build(); 2 查詢 public List<HashMap> 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<HashMap> responses = client.query(query, HashMap.class); client.close(); return responses; } 3 分析并組裝結果 try { List<HashMap> res = queryResult(query); if(res!=null){ DecimalFormat df = new DecimalFormat("0.00%"); for (HashMap hashMap : res){ Map<String,Object> event = (Map<String,Object>)hashMap.get("result");         //小數-》百分比 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; }

關于Java中怎么查詢druidAPI問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

枣阳市| 贵南县| 遵化市| 蓬溪县| 双柏县| 晋宁县| 大埔县| 静乐县| 秀山| 开远市| 洪湖市| 平度市| 鹿泉市| 株洲县| 古浪县| 江华| 横峰县| 临夏县| 陵川县| 卫辉市| 新宁县| 巫山县| 伊宁市| 宁陕县| 左云县| 绥中县| 出国| 新源县| 洱源县| 开远市| 古丈县| 宁阳县| 长泰县| 乌拉特后旗| 当阳市| 宁安市| 油尖旺区| 城口县| 苏州市| 汉中市| 醴陵市|