Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 7.4.0 [unreleased]

### Features

- [#828](https://github.com/influxdata/influxdb-client-java/pull/828): Add read-only getters for `Point.fields` and `Point.tags`

## 7.3.0 [2025-05-22]

### Features
Expand Down
19 changes: 19 additions & 0 deletions client/src/main/java/com/influxdb/client/write/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.text.NumberFormat;
import java.time.Instant;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -95,6 +96,24 @@ public static Point measurement(@Nonnull final String measurementName) {
return new Point(measurementName);
}

/**
* Returns a read-only reference to the tags.
* @return The point tags as read-only map.
*/
@Nonnull
public Map<String, String> getTags() {
return Collections.unmodifiableMap(this.tags);
}

/**
* Returns a read-only reference to the fields.
* @return The point fields as read-only map.
*/
@Nonnull
public Map<String, Object> getFields() {
return Collections.unmodifiableMap(this.fields);
}

/**
* Adds or replaces a tag value for this point.
*
Expand Down
21 changes: 21 additions & 0 deletions client/src/test/java/com/influxdb/client/write/PointTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.influxdb.client.domain.WritePrecision;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author Jakub Bednar (bednar@github) (11/10/2018 12:57)
*/
Expand Down Expand Up @@ -438,4 +442,21 @@ void addFields() {

Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2o,location=europe accepted=true,level=2i,power=2.56");
}

@Test
void getFieldsGetTags() {
Point point = Point.measurement("h2 o")
.addTag("location", "europe")
.addField("level", 2);

Map<String, Object> fields = point.getFields();
Map<String, String> tags = point.getTags();

Assertions.assertThat(fields).isEqualTo(Map.of("level",2L));
Assertions.assertThat(tags).isEqualTo(Map.of("location","europe"));

// Assert that returned maps are immutable
assertThrows(UnsupportedOperationException.class, () -> fields.put("test", "value"));
assertThrows(UnsupportedOperationException.class, () -> tags.put("test", "value"));
}
}