private Map<String, String> processArgs(final String[] args) throws ArgumentException {
    if (args.length % 2 == 1) {
      throw new ArgumentException("Invalid number of arguments.");
    }

    final HashMap<String, String> arguments = new HashMap<String, String>(args.length);
    for (int i = 0; i < args.length; i += 2) {
      String key = args[i].startsWith("-") ? args[i].substring(1) : args[i];
      arguments.put(key.trim(), args[i + 1].trim());
    }

    if (!arguments.containsKey(ARG_WORKSPACE)) {
      throw new ArgumentException("No workspace argument.");
    }

    try {
      MainTestSuite.setPathToWorkspace(new URI(arguments.get(ARG_WORKSPACE)));
    } catch (URISyntaxException e) {
      throw new ArgumentException("Invalid URI: " + arguments.get(ARG_WORKSPACE));
    }

    if (arguments.containsKey(ARG_LICESNSE)) {
      MainTestSuite.LICENSE_FILE = arguments.get(ARG_LICESNSE);
    }

    System.out.println("ws location: " + MainTestSuite.getPathToWorkspace());
    System.out.println("license file location: " + MainTestSuite.LICENSE_FILE);

    return arguments;
  }
 /**
  * tophits 查询
  *
  * <p><a>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html</a>
  *
  * @throws IOException
  * @throws SqlParseException
  */
 @Test
 public void topHitTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
   SqlElasticSearchRequestBuilder result =
       (SqlElasticSearchRequestBuilder)
           MainTestSuite.getSearchDao()
               .explain("select topHits('size'=3,age='desc') from bank  group by gender ")
               .explain();
   System.out.println(result);
 }
 /**
  * 时间范围聚合
  *
  * <p><a>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html</a>
  *
  * @throws IOException
  * @throws SqlParseException
  */
 @Test
 public void countDateRangeTest()
     throws IOException, SqlParseException, SQLFeatureNotSupportedException {
   SqlElasticSearchRequestBuilder result =
       (SqlElasticSearchRequestBuilder)
           MainTestSuite.getSearchDao()
               .explain(
                   "select online from online  group by date_range(field='insert_time','format'='yyyy-MM-dd' ,'2014-08-18','2014-08-17','now-8d','now-7d','now-6d','now') ")
               .explain();
   System.out.println(result);
 }
 /**
  * 时间 聚合 , 每天按照天聚合 参数说明:
  *
  * <p><a>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html</a>
  *
  * @throws IOException
  * @throws SqlParseException
  */
 @Test
 public void countGroupByDateTest()
     throws IOException, SqlParseException, SQLFeatureNotSupportedException {
   SqlElasticSearchRequestBuilder result =
       (SqlElasticSearchRequestBuilder)
           MainTestSuite.getSearchDao()
               .explain(
                   "select insert_time from online  group by date_histogram(field='insert_time','interval'='1.5h','format'='yyyy-MM') ")
               .explain();
   System.out.println(result);
 }
 @Test
 public void countGroupByDateTestWithAlias()
     throws IOException, SqlParseException, SQLFeatureNotSupportedException {
   SqlElasticSearchRequestBuilder result =
       (SqlElasticSearchRequestBuilder)
           MainTestSuite.getSearchDao()
               .explain(
                   "select insert_time from online  group by date_histogram(field='insert_time','interval'='1.5h','format'='yyyy-MM','alias'='myAlias') ")
               .explain();
   boolean containAlias =
       result
           .toString()
           .replaceAll("\\s+", "")
           .contains(
               "myAlias\":{\"date_histogram\":{\"field\":\"insert_time\",\"interval\":\"1.5h\",\"format\":\"yyyy-MM\"}}");
   Assert.assertTrue(containAlias);
 }
Esempio n. 6
0
 private SearchHits query(String query)
     throws SqlParseException, SQLFeatureNotSupportedException, SQLFeatureNotSupportedException {
   SearchDao searchDao = MainTestSuite.getSearchDao();
   SearchRequestBuilder select = (SearchRequestBuilder) searchDao.explain(query);
   return select.get().getHits();
 }
 private SqlElasticSearchRequestBuilder getSearchRequestBuilder(String query)
     throws SqlParseException, SQLFeatureNotSupportedException {
   SearchDao searchDao = MainTestSuite.getSearchDao();
   return (SqlElasticSearchRequestBuilder) searchDao.explain(query).explain();
 }