@Test public void testPartitionBasedQuery() throws InstantiationException, IllegalAccessException { String[] partitions = new String[2]; partitions[0] = "cluster"; partitions[1] = "datacenter"; EntityDefinitionManager.registerEntity(TestLogAPIEntity.class); EntityDefinition entityDef = EntityDefinitionManager.getEntityByServiceName("TestLogAPIEntity"); entityDef.setPartitions(partitions); entityDef.setTimeSeries(true); ListQueryResource resource = new ListQueryResource(); String query = "TestLogAPIEntity[]{@cluster}"; String startTime = DateTimeUtil.secondsToHumanDate(System.currentTimeMillis() / 1000); String endTime = DateTimeUtil.secondsToHumanDate((System.currentTimeMillis() + 1000) / 1000); ListQueryAPIResponseEntity response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertFalse(response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" ]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertFalse(response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\"]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue(response.isSuccess()); query = "TestLogAPIEntity[(@cluster=\"cluster1\") OR (@cluster=\"cluster1\" AND @datacenter=\"dc1\")]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertFalse(response.isSuccess()); query = "TestLogAPIEntity[(@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND @tag1=\"value1\") OR (@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND @tag2=\"value2\")]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue(response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND (@tag1=\"value1\" OR @tag2=\"value2\")]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue(response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND (@tag1!=\"value1\" or @tag2=~\"value2\" or ((@tag3 contains \"value3\") or (@tag3 not contains \"value3\")) or @tag4 !=~ \"value4\" or @tag5 in (\"value5-1\",\"value5-2\",\"value5-3\") or @tag6 not in (\"value5-1\",\"value5-2\",\"value5-3\"))]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue(response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND (@tag5 in (\"value5-1\",\"value5,2\"))]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue(response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND (@tag1 < \"value1\")]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertFalse("Tag with unsupported operation, should get exception",response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND " + "(@field1 < 1 or @field2 = 2 or @field3 = 13456789 or @field4 = 987654321 or @field5 = 5.6 or @field7 < \"value7\")]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Field with numeric, should success",response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND (@field1 < -1)]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Field supporte negative numeric value, should get exception", response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND (@tag1 in (\"\\\"value1-part1\\\",\\\"value1-part2\\\"\",\"value2\"))]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Support escaped quotes, should success: "+query,response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND @tag1 is null ]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Support is null, should success: "+query,response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND @tag1 is not null]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Support is not null, should success: "+query,response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND @tag1 is not null]{*}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Support is not null, should success: "+query,response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND EXP{@field1 + @field2} > 0]{@cluster}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Support expression in filter, should success: "+query,response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND EXP{@field1 + @field2} > 0]{EXP{@field1 + @field2} }"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Support expression in output, should success: "+query,response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND EXP{@field1 + @field2} > 0]{EXP{@field1 + @field2} as A}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null); Assert.assertNotNull(response); Assert.assertTrue("Support expression output with alias, should success: "+query,response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND EXP{@field1 + @field2} > 0]{@cluster,EXP{@field1 + @field2} as A}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null,true); Assert.assertNotNull(response); Assert.assertTrue("Support parameter \"verbose\" is true, should success: "+query,response.isSuccess()); query = "TestLogAPIEntity[@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND EXP{@field1 + @field2} > 0]{@cluster,EXP{@field1 + @field2} as A}"; response = resource.listQuery(query, startTime, endTime, 100, null, false, true, 1, 0, false, 0, null,false); Assert.assertNotNull(response); Assert.assertTrue("Support parameter \"verbose\" is false, should success: "+query,response.isSuccess()); }
public ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query, @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime, @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top, @QueryParam("filterIfMissing") boolean filterIfMissing, @QueryParam("parallel") int parallel, @QueryParam("metricName") String metricName){ return listQuery(query, startTime, endTime, pageSize, startRowkey, treeAgg, timeSeries, intervalmin, top, filterIfMissing, parallel, metricName,true); }
ListQueryResource { public ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query, @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime, @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top, @QueryParam("filterIfMissing") boolean filterIfMissing, @QueryParam("parallel") int parallel, @QueryParam("metricName") String metricName){ return listQuery(query, startTime, endTime, pageSize, startRowkey, treeAgg, timeSeries, intervalmin, top, filterIfMissing, parallel, metricName,true); } }
ListQueryResource { public ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query, @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime, @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top, @QueryParam("filterIfMissing") boolean filterIfMissing, @QueryParam("parallel") int parallel, @QueryParam("metricName") String metricName){ return listQuery(query, startTime, endTime, pageSize, startRowkey, treeAgg, timeSeries, intervalmin, top, filterIfMissing, parallel, metricName,true); }  }
ListQueryResource { public ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query, @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime, @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top, @QueryParam("filterIfMissing") boolean filterIfMissing, @QueryParam("parallel") int parallel, @QueryParam("metricName") String metricName){ return listQuery(query, startTime, endTime, pageSize, startRowkey, treeAgg, timeSeries, intervalmin, top, filterIfMissing, parallel, metricName,true); }  ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query,
												@QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
												@QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey,
												@QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries,
												@QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
												@QueryParam("filterIfMissing") boolean filterIfMissing,
												@QueryParam("parallel") int parallel,
												@QueryParam("metricName") String metricName); @GET @Produces({MediaType.APPLICATION_JSON}) ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query, 
			@QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
			@QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, 
			@QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, 
			@QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
			@QueryParam("filterIfMissing") boolean filterIfMissing,
			@QueryParam("parallel") int parallel,
			@QueryParam("metricName") String metricName,
			@QueryParam("verbose") Boolean verbose); @GET @Path("/legacy") @Produces({MediaType.APPLICATION_JSON}) @Deprecated ListQueryAPIResponseEntity listQueryWithoutCoprocessor(@QueryParam("query") String query,
	                                                              @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
	                                                              @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey,
	                                                              @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries,
	                                                              @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
	                                                              @QueryParam("filterIfMissing") boolean filterIfMissing,
	                                                              @QueryParam("parallel") int parallel,
	                                                              @QueryParam("metricName") String metricName,
																  @QueryParam("verbose") Boolean verbose); @GET @Path("/jsonp") @Produces({"application/x-javascript", "application/json", "application/xml"}) JSONWithPadding listQueryWithJsonp(@QueryParam("query") String query, 
			@QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
			@QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, 
			@QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, 
			@QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
			@QueryParam("filterIfMissing") boolean filterIfMissing,
			@QueryParam("parallel") int parallel,
			@QueryParam("update") String callback,
			@QueryParam("verbose") boolean verbose); }
ListQueryResource { public ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query, @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime, @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top, @QueryParam("filterIfMissing") boolean filterIfMissing, @QueryParam("parallel") int parallel, @QueryParam("metricName") String metricName){ return listQuery(query, startTime, endTime, pageSize, startRowkey, treeAgg, timeSeries, intervalmin, top, filterIfMissing, parallel, metricName,true); }  ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query,
												@QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
												@QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey,
												@QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries,
												@QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
												@QueryParam("filterIfMissing") boolean filterIfMissing,
												@QueryParam("parallel") int parallel,
												@QueryParam("metricName") String metricName); @GET @Produces({MediaType.APPLICATION_JSON}) ListQueryAPIResponseEntity listQuery(@QueryParam("query") String query, 
			@QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
			@QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, 
			@QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, 
			@QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
			@QueryParam("filterIfMissing") boolean filterIfMissing,
			@QueryParam("parallel") int parallel,
			@QueryParam("metricName") String metricName,
			@QueryParam("verbose") Boolean verbose); @GET @Path("/legacy") @Produces({MediaType.APPLICATION_JSON}) @Deprecated ListQueryAPIResponseEntity listQueryWithoutCoprocessor(@QueryParam("query") String query,
	                                                              @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
	                                                              @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey,
	                                                              @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries,
	                                                              @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
	                                                              @QueryParam("filterIfMissing") boolean filterIfMissing,
	                                                              @QueryParam("parallel") int parallel,
	                                                              @QueryParam("metricName") String metricName,
																  @QueryParam("verbose") Boolean verbose); @GET @Path("/jsonp") @Produces({"application/x-javascript", "application/json", "application/xml"}) JSONWithPadding listQueryWithJsonp(@QueryParam("query") String query, 
			@QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
			@QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey, 
			@QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries, 
			@QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
			@QueryParam("filterIfMissing") boolean filterIfMissing,
			@QueryParam("parallel") int parallel,
			@QueryParam("update") String callback,
			@QueryParam("verbose") boolean verbose);  }