Imports a single data point. @param tsdb The TSDB to import the data point into. @param words The words describing the data point to import, in the following format: [metric, timestamp, value, ..tags..] @return A deferred object that indicates the completion of the request. @throws NumberFor
(final TSDB tsdb,
final String[] words)
| 739 | * @throws NoSuchUniqueName if the metric isn't registered. |
| 740 | */ |
| 741 | protected Deferred<Object> importDataPoint(final TSDB tsdb, |
| 742 | final String[] words) { |
| 743 | words[0] = null; // Ditch the "put". |
| 744 | if (words.length < 5) { // Need at least: metric timestamp value tag |
| 745 | // ^ 5 and not 4 because words[0] is "put". |
| 746 | throw new IllegalArgumentException("not enough arguments" |
| 747 | + " (need least 4, got " |
| 748 | + (words.length - 1) + ')'); |
| 749 | } |
| 750 | final String metric = words[1]; |
| 751 | if (metric.length() <= 0) { |
| 752 | throw new IllegalArgumentException("empty metric name"); |
| 753 | } |
| 754 | final long timestamp; |
| 755 | if (words[2].contains(".")) { |
| 756 | timestamp = Tags.parseLong(words[2].replace(".", "")); |
| 757 | } else { |
| 758 | timestamp = Tags.parseLong(words[2]); |
| 759 | } |
| 760 | if (timestamp <= 0) { |
| 761 | throw new IllegalArgumentException("invalid timestamp: " + timestamp); |
| 762 | } |
| 763 | final String value = words[3]; |
| 764 | if (value.length() <= 0) { |
| 765 | throw new IllegalArgumentException("empty value"); |
| 766 | } |
| 767 | final HashMap<String, String> tags = new HashMap<String, String>(); |
| 768 | for (int i = 4; i < words.length; i++) { |
| 769 | if (!words[i].isEmpty()) { |
| 770 | Tags.parse(tags, words[i]); |
| 771 | } |
| 772 | } |
| 773 | if (Tags.looksLikeInteger(value)) { |
| 774 | return tsdb.addPoint(metric, timestamp, Tags.parseLong(value), tags); |
| 775 | } else if (Tags.fitsInFloat(value)) { // floating point value |
| 776 | return tsdb.addPoint(metric, timestamp, Float.parseFloat(value), tags); |
| 777 | } else { |
| 778 | return tsdb.addPoint(metric, timestamp, Double.parseDouble(value), tags); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /** |
| 783 | * Converts the string array to an IncomingDataPoint. WARNING: This method |
no test coverage detected