use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class RunningQueryTest method testStartTime.
@Test
public void testStartTime() {
long start = System.currentTimeMillis();
BulletConfig config = new BulletConfig();
Query query = new Query(new Projection(), null, new Raw(null), null, new Window(), null);
query.configure(config);
RunningQuery runningQuery = new RunningQuery("foo", query, new Metadata(null, null));
long end = System.currentTimeMillis();
Assert.assertTrue(runningQuery.getStartTime() >= start);
Assert.assertTrue(runningQuery.getStartTime() <= end);
Assert.assertFalse(runningQuery.isTimedOut());
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class ByteArrayPubSubMessageSerDeTest method testLazyMessage.
@Test
public void testLazyMessage() {
ByteArrayPubSubMessageSerDe serDe = new ByteArrayPubSubMessageSerDe(null);
Query query = new Query(new Projection(), null, new Raw(1), null, new Window(), 1L);
PubSubMessage converted = serDe.toMessage("id", query, "foo");
PubSubMessage reverted = serDe.fromMessage(converted);
Assert.assertSame(reverted, converted);
// Starts off as byte[]
Assert.assertEquals(reverted.getContent(), SerializerDeserializer.toBytes(query));
// Payload is now made a Query
Query revertedQuery = reverted.getContentAsQuery();
Assert.assertEquals(revertedQuery.getProjection().getType(), Projection.Type.PASS_THROUGH);
Assert.assertEquals(revertedQuery.getAggregation().getType(), AggregationType.RAW);
Assert.assertEquals((long) revertedQuery.getAggregation().getSize(), 1L);
Assert.assertEquals((long) revertedQuery.getDuration(), 1L);
Assert.assertSame(reverted.getContent(), revertedQuery);
// Payload is now made a byte[]
byte[] revertedByteArray = reverted.getContentAsByteArray();
Assert.assertEquals(revertedByteArray, SerializerDeserializer.toBytes(query));
Assert.assertSame(reverted.getContent(), revertedByteArray);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class ByteArrayPubSubMessageSerDeTest method testConvertingQuery.
@Test
public void testConvertingQuery() {
ByteArrayPubSubMessageSerDe serDe = new ByteArrayPubSubMessageSerDe(null);
Query query = new Query(new Projection(), null, new Raw(1), null, new Window(), 1L);
PubSubMessage actual = serDe.toMessage("id", query, "foo");
Assert.assertEquals(actual.getId(), "id");
Assert.assertEquals(actual.getContent(), SerializerDeserializer.toBytes(query));
Assert.assertEquals(actual.getMetadata().getContent(), "foo");
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class Querier method start.
// ********************************* Monoidal Interface Overrides *********************************
/**
* Starts the query.
*/
private void start() {
// Is an empty map if metadata was disabled
metaKeys = (Map<String, String>) config.getAs(BulletConfig.RESULT_METADATA_METRICS, Map.class);
boolean isRateLimitEnabled = config.getAs(BulletConfig.RATE_LIMIT_ENABLE, Boolean.class);
if (isRateLimitEnabled) {
int maxEmit = config.getAs(BulletConfig.RATE_LIMIT_MAX_EMIT_COUNT, Integer.class);
int timeInterval = config.getAs(BulletConfig.RATE_LIMIT_TIME_INTERVAL, Integer.class);
rateLimit = new RateLimiter(maxEmit, timeInterval);
}
Query query = runningQuery.getQuery();
Expression filter = query.getFilter();
if (filter != null) {
this.filter = new Filter(filter);
}
TableFunction tableFunction = query.getTableFunction();
if (tableFunction != null) {
tableFunctor = tableFunction.getTableFunctor();
}
com.yahoo.bullet.query.Projection projection = query.getProjection();
if (projection.getType() != PASS_THROUGH) {
this.projection = new Projection(projection.getFields());
}
// Aggregation and Strategy are guaranteed to not be null.
Strategy strategy = query.getAggregation().getStrategy(config);
List<PostAggregation> postAggregations = query.getPostAggregations();
if (postAggregations != null && !postAggregations.isEmpty()) {
postStrategies = postAggregations.stream().map(PostAggregation::getPostStrategy).collect(Collectors.toList());
}
// Scheme is guaranteed to not be null. It is constructed in its "start" state.
window = query.getWindow().getScheme(strategy, config);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QueryManager method removeAndGetQuery.
/**
* Removes and returns a {@link Querier} from the manager. The manager does not have any information pertaining to
* the query any longer.
*
* @param id The query ID to remove.
* @return The removed {@link Querier} instance.
*/
public Querier removeAndGetQuery(String id) {
Querier querier = queries.remove(id);
if (querier != null) {
Query query = querier.getQuery();
Set<String> keys = partitioner.getKeys(query);
for (String key : keys) {
Set<String> partition = partitioning.get(key);
partition.remove(id);
if (partition.isEmpty()) {
log.debug("Partition: {} is empty. Removing...", key);
partitioning.remove(key);
}
log.debug("Removed query: {} from partition: {}", id, key);
}
}
return querier;
}
Aggregations