@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String sql = req.getParameter("sql"); String key = req.getParameter("key"); log.info("query, key[" + key + "] sql[" + sql + "]"); try { resp.getWriter().write(JSONSerDe.ser(client.query("pagecounts", key, sql, null))); } catch (JSONSerDeException e) { throw new IOException(e); } } }
@Override public int nextQuery() throws Exception { int key = ((int) (Math.random() * (maxKey - minKey))) + minKey; String strKey = String.format(paddingExp, key); return client .query(tablespace, strKey + "", "SELECT * FROM " + tablespace + " WHERE key = " + key + ";", null) .getResult().size(); } }
/** * Given a SQL query and a partition key, query Splout. We take advantage of Trident's batch and perform several * queries in a row. This could actually be a lot more efficient if we used a thread-pool here since Splout can handle * parallel queries quite well, but I kept it simple just for the sake of this example. */ public List<Object> querySplout(String tablespace, List<String> sql, List<String> keys) { List<Object> result = new ArrayList<Object>(); for(int i = 0; i < sql.size(); i++) { String partitionKey = keys.get(i); String sqlQuery = sql.get(i); try { result.add(sploutClient.query(tablespace, partitionKey, sqlQuery, null)); } catch(IOException e) { if(!failFast) { result.add(null); } else { throw new RuntimeException(e); } } } return result; } }
@SuppressWarnings("unchecked") @Override public void init(Map<String, Object> context) throws Exception { this.context = context; client = new SploutClient(20 * 1000, ((String) context.get("qnodes")).split(",")); String query = "SELECT stn, wban FROM stations"; System.out.println("Retrieving stations list"); long statTime = System.currentTimeMillis(); QueryStatus st = client.query(tablespace, "any", query, null); if (st.getResult() == null) { throw new RuntimeException("Impossible to retrieve stations list. " + st); } stations = st.getResult(); System.out.println("Loaded " + stations.size() + " stations in " + (System.currentTimeMillis() - statTime) + " ms."); }
@Override public int nextQuery() throws Exception { int rndIdx = rand.nextInt(stations.size()); int stn = stations.get(rndIdx).get("stn"); int wban = stations.get(rndIdx).get("wban"); String query; if (context.get("month").equals("false")) { query = "select year,month,day,min,max from meteo where stn=" + stn + " and wban = " + wban + " order by year,month,day"; } else { query = "select year,month,min(min) as min,max(max) as max from meteo where stn=" + stn + " and wban=" + wban + " group by year,month order by year,month"; } QueryStatus st = client.query(tablespace, stn + "" + wban, query, null); if (st.getResult() != null) { return st.getResult().size(); } else { return 0; } } }
public void start() throws InterruptedException, IOException { Map<String, Object> context = new HashMap<String, Object>(); context.put("qnodes", qNodes); Map<Integer, Long> rowIdsPerPartition = new HashMap<Integer, Long>(); context.put("rowIdsPerPartition", rowIdsPerPartition); // First get Tablespace metadata - nPartitions SploutClient client = new SploutClient(((String) context.get("qnodes")).split(",")); Tablespace tablespace = client.tablespace(TABLESPACE); int nPartitions = tablespace.getPartitionMap().getPartitionEntries().size(); // Then gather number of registers for each partition for (int partition = 0; partition < nPartitions; partition++) { String query = "SELECT MAX(rowid) FROM pagecounts;"; Map<String, Object> obj = (Map<String, Object>) client .query(TABLESPACE, null, query, partition + "").getResult().get(0); rowIdsPerPartition.put(partition, Long.parseLong(obj.get("MAX(rowid)").toString())); } SploutBenchmark benchmark = new SploutBenchmark(); for (int i = 0; i < nIterations; i++) { benchmark.stressTest(nThreads, nQueries, PageCountsStressThreadImpl.class, context); benchmark.printStats(System.out); } }
QueryStatus st = client.query(TABLESPACE, null, query, partition + ""); if (st.getResult() != null && st.getResult().size() > 0) { Map<String, Object> obj = (Map<String, Object>) st.getResult().get( + pageToQuery + "' GROUP BY hour;"; QueryStatus st = client.query(TABLESPACE, null, query, partition + ""); querySequence++; if (querySequence == 2) {
String query = "SELECT COUNT(*) FROM " + tblName; QueryStatus status = client.query(tsName, null, query, part + ""); if (status.getError() != null) { throw new Exception("Query error: " + status.getError()); + tblName + " GROUP BY key ORDER by c DESC LIMIT " + topSize; status = client.query(tsName, null, query, part + ""); if (status.getError() != null) { throw new Exception("Query error: " + status.getError());
QueryStatus qStatus = client.query("pagecountsintegration", "*", "SELECT * FROM pagecounts;", null); System.out.println(qStatus.getResult());