use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class WindowedStreamTest method setUp.
@Before
public void setUp() {
queryBuilder = new MISTQueryBuilder();
queryBuilder.setApplicationId(TestParameters.SUPER_GROUP_ID);
timeWindowedStream = queryBuilder.socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF).map(s -> new Tuple2<>(s, 1)).window(new TimeWindowInformation(5000, 1000));
}
use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class CepUtils method translate.
/**
* Translate cep query into MIST query.
* @return MIST query
*/
public static <T> MISTQueryBuilder translate(final MISTCepQuery query) throws IOException {
final String superGroupId = query.getSuperGroupId();
final CepInput<T> cepInput = query.getCepInput();
final List<CepEventPattern<T>> cepEventPatterns = query.getCepEventPatternSequence();
final CepQualifier<T> cepQualifier = query.getCepQualifier();
final long windowTime = query.getWindowTime();
final CepAction cepAction = query.getCepAction();
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
final ContinuousStream<T> inputMapStream = convertCepInputToSourceStream(queryBuilder, cepInput);
final ContinuousStream<Map<String, List<T>>> qualifierFilterStream = inputMapStream.cepOperator(cepEventPatterns, windowTime).filter(cepQualifier);
cepActionTranslator(qualifierFilterStream, cepAction);
return queryBuilder;
}
use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class JoinAndApplyStateful method submitQuery.
/**
* Submit a query joining two sources and apply stateful operation on them.
* The query reads strings from two source servers, windows them, and
* prints out the result of apply stateful operation on the window
* that contains the data which satisfies a predicate.
* @return result of the submission
* @throws IOException
* @throws InjectionException
*/
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
final Injector injector = Tang.Factory.getTang().newInjector(configuration);
final String source1Socket = injector.getNamedInstance(UnionLeftSourceAddress.class);
final String source2Socket = injector.getNamedInstance(UnionRightSourceAddress.class);
final SourceConfiguration localTextSocketSource1Conf = MISTExampleUtils.getLocalTextSocketSourceConf(source1Socket);
final SourceConfiguration localTextSocketSource2Conf = MISTExampleUtils.getLocalTextSocketSourceConf(source2Socket);
final MISTBiPredicate<String, String> joinPred = (s1, s2) -> s1.equals(s2);
final ApplyStatefulFunction<Tuple2<String, String>, String> applyStatefulFunction = new FoldStringTupleFunction();
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
final ContinuousStream sourceStream1 = queryBuilder.socketTextStream(localTextSocketSource1Conf);
final ContinuousStream sourceStream2 = queryBuilder.socketTextStream(localTextSocketSource2Conf);
sourceStream1.join(sourceStream2, joinPred, new TimeWindowInformation(5000, 5000)).applyStatefulWindow(applyStatefulFunction).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
return MISTExampleUtils.submit(queryBuilder, configuration);
}
use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class KMeansClustering method submitQuery.
/**
* Submit a query doing k-means clustering.
* The query receives inputs in a form of two-dimensional double point "x1.x2,y1.y2",
* conducts online k-means clustering, and displays the result of clustering.
* @return result of the submission
* @throws IOException
* @throws InjectionException
*/
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
final SourceConfiguration localTextSocketSourceConf = MISTExampleUtils.getLocalTextSocketSourceConf(sourceSocket);
final MISTFunction<List<Cluster>, List<String>> flatMapFunc = // parse clustering result into String list
(clusterList) -> {
final List<String> results = new LinkedList<>();
for (final Cluster cluster : clusterList) {
String clusterResult = "Cluster id: " + cluster.getId() + ", cluster center: " + cluster.getCenter().toString() + "\n";
for (final Point point : cluster.getClusteredPoints()) {
clusterResult += point.toString() + "\n";
}
results.add(clusterResult);
}
return results;
};
final ApplyStatefulFunction<Point, List<Cluster>> applyStatefulFunction = new KMeansFunction();
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
queryBuilder.socketTextStream(localTextSocketSourceConf).map(s -> s.replaceAll(" ", "")).filter(s -> Pattern.matches("-?\\d+\\.\\d+,-?\\d+\\.\\d+", s)).map(s -> {
final String[] array = s.split(",");
return new Point(Double.parseDouble(array[0]), Double.parseDouble(array[1]));
}).applyStateful(applyStatefulFunction).flatMap(flatMapFunc).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
return MISTExampleUtils.submit(queryBuilder, configuration);
}
use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class KafkaSource method submitQuery.
/**
* Submit a query fetching data from a kafka source.
* The query reads strings from a kafka topic and send them to a sink server.
* @return result of the submission
* @throws IOException
* @throws InjectionException
*/
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(KafkaSourceAddress.class);
final SourceConfiguration localKafkaSourceConf = MISTExampleUtils.getLocalKafkaSourceConf("KafkaSource", sourceSocket);
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
queryBuilder.kafkaStream(localKafkaSourceConf).map(consumerRecord -> ((ConsumerRecord) consumerRecord).value()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
return MISTExampleUtils.submit(queryBuilder, configuration);
}
Aggregations