Skip to content

Commit e2fbb3a

Browse files
g3n35i5bednar
andauthored
feat: Add read-only getters for Point.fields and Point.tags (#828)
* feat: Add read-only getters for `Point.fields` and `Point.tags` This makes testing easier. * docs: Add #828 to changelog * style: Fix checkstyle warning * docs: update CHANGELOG.md --------- Co-authored-by: Jakub Bednář <jakub.bednar@gmail.com>
1 parent db77cac commit e2fbb3a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## 7.5.0 [unreleased]
22

3+
### Features
4+
5+
- [#828](https://github.com/influxdata/influxdb-client-java/pull/828): Add read-only getters for `Point.fields` and `Point.tags`
6+
37
## 7.4.0 [2025-11-18]
48

59
### Features

client/src/main/java/com/influxdb/client/write/Point.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.text.NumberFormat;
2727
import java.time.Instant;
2828
import java.util.Collection;
29+
import java.util.Collections;
2930
import java.util.Locale;
3031
import java.util.Map;
3132
import java.util.Set;
@@ -95,6 +96,24 @@ public static Point measurement(@Nonnull final String measurementName) {
9596
return new Point(measurementName);
9697
}
9798

99+
/**
100+
* Returns a read-only reference to the tags.
101+
* @return The point tags as read-only map.
102+
*/
103+
@Nonnull
104+
public Map<String, String> getTags() {
105+
return Collections.unmodifiableMap(this.tags);
106+
}
107+
108+
/**
109+
* Returns a read-only reference to the fields.
110+
* @return The point fields as read-only map.
111+
*/
112+
@Nonnull
113+
public Map<String, Object> getFields() {
114+
return Collections.unmodifiableMap(this.fields);
115+
}
116+
98117
/**
99118
* Adds or replaces a tag value for this point.
100119
*

client/src/test/java/com/influxdb/client/write/PointTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@
2424
import java.math.BigDecimal;
2525
import java.math.BigInteger;
2626
import java.time.Instant;
27+
import java.util.Collections;
2728
import java.util.HashMap;
29+
import java.util.Map;
2830

2931
import com.influxdb.client.domain.WritePrecision;
3032

3133
import org.assertj.core.api.Assertions;
3234
import org.junit.jupiter.api.Test;
3335

36+
import static org.junit.jupiter.api.Assertions.assertThrows;
37+
3438
/**
3539
* @author Jakub Bednar (bednar@github) (11/10/2018 12:57)
3640
*/
@@ -438,4 +442,21 @@ void addFields() {
438442

439443
Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2o,location=europe accepted=true,level=2i,power=2.56");
440444
}
445+
446+
@Test
447+
void getFieldsGetTags() {
448+
Point point = Point.measurement("h2 o")
449+
.addTag("location", "europe")
450+
.addField("level", 2);
451+
452+
Map<String, Object> fields = point.getFields();
453+
Map<String, String> tags = point.getTags();
454+
455+
Assertions.assertThat(fields).isEqualTo(Map.of("level",2L));
456+
Assertions.assertThat(tags).isEqualTo(Map.of("location","europe"));
457+
458+
// Assert that returned maps are immutable
459+
assertThrows(UnsupportedOperationException.class, () -> fields.put("test", "value"));
460+
assertThrows(UnsupportedOperationException.class, () -> tags.put("test", "value"));
461+
}
441462
}

0 commit comments

Comments
 (0)