private void fromJson(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd, MetricTimeSeries.Builder builder) { String jsonString = binaryTimeSeries.get(DATA_AS_JSON_FIELD).toString(); //Second deserialize JsonKassiopeiaSimpleSerializer serializer = new JsonKassiopeiaSimpleSerializer(); serializer.fromJson(jsonString.getBytes(Charset.forName(JsonKassiopeiaSimpleSerializer.UTF_8)), queryStart, queryEnd, builder); }
private void fromProtocolBuffers(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd, MetricTimeSeries.Builder builder) { final InputStream decompressed = Compression.decompressToStream(binaryTimeSeries.getPoints()); ProtoBufMetricTimeSeriesSerializer.from(decompressed, binaryTimeSeries.getStart(), binaryTimeSeries.getEnd(), queryStart, queryEnd, builder); IOUtils.closeQuietly(decompressed); }
@Override public MetricTimeSeries from(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd) { LOGGER.debug("Converting {} to MetricTimeSeries starting at {} and ending at {}", binaryTimeSeries, queryStart, queryEnd); //get the metric String metric = binaryTimeSeries.get(MetricTSSchema.METRIC).toString(); //Third build a minimal time series MetricTimeSeries.Builder builder = new MetricTimeSeries.Builder(metric); //add all user defined attributes binaryTimeSeries.getFields().forEach((field, value) -> { if (MetricTSSchema.isUserDefined(field)) { builder.attribute(field, value); } }); //Default serialization is protocol buffers. if (binaryTimeSeries.getPoints().length > 0) { fromProtocolBuffers(binaryTimeSeries, queryStart, queryEnd, builder); } else if (binaryTimeSeries.getFields().containsKey(DATA_AS_JSON_FIELD)) { //do it from json fromJson(binaryTimeSeries, queryStart, queryEnd, builder); } else { //we have no data //set the start and end builder.start(binaryTimeSeries.getStart()); builder.end(binaryTimeSeries.getEnd()); } return builder.build(); }
/** * Converts a time series of type <T> to SolInputDocument * * @param ts - the time series * @return a filled SolrInputDocument */ private static <T> SolrInputDocument convert(T ts, TimeSeriesConverter<T> converter) { BinaryTimeSeries series = converter.to(ts); SolrInputDocument solrDocument = new SolrInputDocument(); series.getFields().entrySet().forEach(entry -> solrDocument.addField(entry.getKey(), entry.getValue())); return solrDocument; } }
@Override public MetricTimeSeries from(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd) { LOGGER.debug("Converting {} to MetricTimeSeries starting at {} and ending at {}", binaryTimeSeries, queryStart, queryEnd); //get the metric String metric = binaryTimeSeries.get(MetricTSSchema.METRIC).toString(); //Third build a minimal time series MetricTimeSeries.Builder builder = new MetricTimeSeries.Builder(metric); //add all user defined attributes binaryTimeSeries.getFields().forEach((field, value) -> { if (MetricTSSchema.isUserDefined(field)) { builder.attribute(field, value); } }); //Default serialization is protocol buffers. if (binaryTimeSeries.getPoints().length > 0) { fromProtocolBuffers(binaryTimeSeries, queryStart, queryEnd, builder); } else if (binaryTimeSeries.getFields().containsKey(DATA_AS_JSON_FIELD)) { //do it from json fromJson(binaryTimeSeries, queryStart, queryEnd, builder); } else { //we have no data //set the start and end builder.start(binaryTimeSeries.getStart()); builder.end(binaryTimeSeries.getEnd()); } return builder.build(); }
/** * Converts a time series of type <T> to SolInputDocument * * @param ts - the time series * @return a filled SolrInputDocument */ private static <T> SolrInputDocument convert(T ts, TimeSeriesConverter<T> converter) { BinaryTimeSeries series = converter.to(ts); SolrInputDocument solrDocument = new SolrInputDocument(); series.getFields().entrySet().forEach(entry -> solrDocument.addField(entry.getKey(), entry.getValue())); return solrDocument; } }
/** * Converts a time series to a solr input document. * <p> * In order to avoid write conflicts, the resulting document does not contain * the attribute "_version_" and the attribute "id" is set to a random UUID. * * @param mts the time series * @return solr input document representing the given time series */ public SolrInputDocument toInputDocument(MetricTimeSeries mts) { SolrInputDocument inputDocument = new SolrInputDocument(); converter.to(mts) .getFields().entrySet() .stream() .filter(it -> !"_version_".equals(it.getKey())) .forEach(it -> inputDocument.addField(it.getKey(), it.getValue())); inputDocument.setField("id", UUID.randomUUID().toString()); return inputDocument; }
private void fromProtocolBuffers(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd, MetricTimeSeries.Builder builder) { final InputStream decompressed = Compression.decompressToStream(binaryTimeSeries.getPoints()); ProtoBufKassiopeiaSimpleSerializer.from(decompressed, binaryTimeSeries.getStart(), binaryTimeSeries.getEnd(), queryStart, queryEnd, builder); }
private void fromJson(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd, MetricTimeSeries.Builder builder) { String jsonString = binaryTimeSeries.get(DATA_AS_JSON_FIELD).toString(); //Second deserialize JsonMetricTimeSeriesSerializer serializer = new JsonMetricTimeSeriesSerializer(); serializer.fromJson(jsonString.getBytes(Charset.forName(JsonMetricTimeSeriesSerializer.UTF_8)), queryStart, queryEnd, builder); }
/** * Converts a time series of type <T> to lucene document. * Handles the default java object types (e.g. double, int, array, collections, ...) * and wraps them into the matching lucene fields (int -> IntField). * * @param ts the time series of type <T> * @return a filled lucene document */ private static <T> Document convert(T ts, TimeSeriesConverter<T> converter) { BinaryTimeSeries series = converter.to(ts); Document document = new Document(); series.getFields().entrySet().forEach(entry -> { if (entry.getValue() instanceof Number) { handleNumbers(document, entry.getKey(), entry.getValue()); } else if (entry.getValue() instanceof String || entry.getValue() instanceof byte[]) { handleStringsAndBytes(document, entry.getKey(), entry.getValue()); } else if (entry.getValue() instanceof Collection || entry.getValue() instanceof Object[]) { handleArraysAndIterable(document, entry.getKey(), entry.getValue()); } else { LOGGER.debug("Field {} could not be handled. Type is not supported", entry); } }); return document; }
@Override public SimpleTimeSeries from(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd) { SimpleTimeSeries doc = new SimpleTimeSeries(); binaryTimeSeries.getFields().forEach(doc::add); return doc; }
for (MetricTimeSeries series : formatParser.parse(stream)) { SolrInputDocument document = new SolrInputDocument(); converter.to(series).getFields().forEach(document::addField); storeDocument(document, processor, req);