/** * 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 the solr document given in the constructor into a time series of type <T> * * @return a time series of type <T> * @throws Exception if bad things happen. */ @Override @SuppressWarnings("PMD.SignatureDeclareThrowsException") public T call() throws Exception { BinaryTimeSeries.Builder timeSeriesBuilder = new BinaryTimeSeries.Builder(); document.forEach(attributeField -> timeSeriesBuilder.field(attributeField.getKey(), attributeField.getValue())); LOGGER.debug("Calling document converter with {}", document); T timeSeries = documentConverter.from(timeSeriesBuilder.build(), queryStart, queryEnd); LOGGER.debug("Returning time series {} to callee", timeSeries); return timeSeries; } }
/** * Converts the solr document given in the constructor into a time series of type <T> * * @return a time series of type <T> * @throws Exception if bad things happen. */ @Override @SuppressWarnings("PMD.SignatureDeclareThrowsException") public T call() throws Exception { BinaryTimeSeries.Builder timeSeriesBuilder = new BinaryTimeSeries.Builder(); document.forEach(attributeField -> timeSeriesBuilder.field(attributeField.getKey(), attributeField.getValue())); LOGGER.debug("Calling document converter with {}", document); T timeSeries = documentConverter.from(timeSeriesBuilder.build(), queryStart, queryEnd); LOGGER.debug("Returning time series {} to callee", timeSeries); return timeSeries; } }
/** * 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 the solr document given in the constructor into a time series of type <T> * * @return a time series of type <T> * @throws Exception if bad things happen. */ @Override @SuppressWarnings("PMD.SignatureDeclareThrowsException") public T call() throws Exception { BinaryTimeSeries.Builder timeSeriesBuilder = new BinaryTimeSeries.Builder(); Map<String, List<Object>> multivalued = new HashMap<>(); document.forEach(attributeField -> { String key = attributeField.name(); if (key.contains(ChronixLuceneStorageConstants.MULTI_VALUE_FIELD_DELIMITER)) { key = key.substring(0, key.indexOf(ChronixLuceneStorageConstants.MULTI_VALUE_FIELD_DELIMITER)); //Handle multivalued fields if (!multivalued.containsKey(key)) { multivalued.put(key, new ArrayList<>()); } multivalued.get(key).add(convert(attributeField)); } else { timeSeriesBuilder.field(key, convert(attributeField)); } }); multivalued.forEach(timeSeriesBuilder::field); LOGGER.debug("Calling document converter with {}", document); T timeSeries = documentConverter.from(timeSeriesBuilder.build(), queryStart, queryEnd); LOGGER.debug("Returning time series {} to callee", timeSeries); return timeSeries; }
/** * 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; }