2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.dbquery.internal.dbimpl.influx2;
15 import java.util.List;
18 import java.util.function.Function;
19 import java.util.stream.Collectors;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.dbquery.internal.domain.QueryResult;
24 import org.openhab.binding.dbquery.internal.domain.ResultRow;
26 import com.influxdb.query.FluxRecord;
29 * Extracts results from Influx2 client query result to a {@link QueryResult}
31 * @author Joan Pujol - Initial contribution
34 public class Influx2QueryResultExtractor implements Function<List<FluxRecord>, QueryResult> {
37 public QueryResult apply(List<FluxRecord> records) {
38 var rows = records.stream().map(Influx2QueryResultExtractor::mapRecord2Row).collect(Collectors.toList());
39 return QueryResult.of(rows);
42 private static ResultRow mapRecord2Row(FluxRecord record) {
43 Map<String, @Nullable Object> values = record.getValues().entrySet().stream()
44 .filter(entry -> !Set.of("result", "table").contains(entry.getKey()))
45 .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
47 return new ResultRow(values);