Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exports DefaultTags from package #59

Merged
merged 2 commits into from
Feb 9, 2024
Merged
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 @@
## 0.6.0 [unreleased]

### Bug Fixes

1. [#59](https://github.com/InfluxCommunity/influxdb3-go/pull/59): Export Default Tags from package

## 0.5.0 [2023-12-05]

### Features
Expand Down
8 changes: 4 additions & 4 deletions influxdb3/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type WriteOptions struct {
Precision lineprotocol.Precision

// Tags added to each point during writing. If a point already has a tag with the same key, it is left unchanged.
//
//
// Example using WritePointsWithOptions:
// c, _ := New(ClientConfig{
// Host: "host",
Expand All @@ -55,7 +55,7 @@ type WriteOptions struct {
// })
//
// options := WriteOptions{
// defaultTags: map[string]string{
// DefaultTags: map[string]string{
// "rack": "main",
// },
// Precision: lineprotocol.Millisecond,
Expand All @@ -74,7 +74,7 @@ type WriteOptions struct {
// Organization: "my-org",
// Database: "my-database",
// WriteOptions: &WriteOptions{
// defaultTags: map[string]string{
// DefaultTags: map[string]string{
// "rack": "main",
// },
// Precision: lineprotocol.Millisecond,
Expand All @@ -86,7 +86,7 @@ type WriteOptions struct {
//
// // Writes with rack=main tag
// c.WritePoints(context.Background(), p)
defaultTags map[string]string
DefaultTags map[string]string

// Write body larger than the threshold is gzipped. 0 to don't gzip at all
GzipThreshold int
Expand Down
9 changes: 4 additions & 5 deletions influxdb3/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,11 @@ func (p *Point) MarshalBinary(precision lineprotocol.Precision) ([]byte, error)
return p.MarshalBinaryWithDefaultTags(precision, nil)
}


// MarshalBinaryWithDefaultTags converts the Point to its binary representation in line protocol format with default tags.
//
// Parameters:
// - precision: The precision to use for timestamp encoding in line protocol format.
// - defaultTags: Tags added to each point during writing. If a point already has a tag with the same key, it is left unchanged.
// - DefaultTags: Tags added to each point during writing. If a point already has a tag with the same key, it is left unchanged.
//
// Returns:
// - The binary representation of the Point in line protocol format.
Expand All @@ -249,7 +248,7 @@ func (p *Point) MarshalBinaryWithDefaultTags(precision lineprotocol.Precision, d
enc.StartLine(p.Values.MeasurementName)

// sort Tags
tagKeys := make([]string, 0, len(p.Values.Tags) + len(defaultTags))
tagKeys := make([]string, 0, len(p.Values.Tags)+len(defaultTags))
for k := range p.Values.Tags {
tagKeys = append(tagKeys, k)
}
Expand All @@ -265,9 +264,9 @@ func (p *Point) MarshalBinaryWithDefaultTags(precision lineprotocol.Precision, d
}
for _, tagKey := range tagKeys {
if lastKey == tagKey {
continue;
continue
}
lastKey = tagKey;
lastKey = tagKey

if value, ok := p.Values.Tags[tagKey]; ok {
enc.AddTag(tagKey, value)
Expand Down
10 changes: 5 additions & 5 deletions influxdb3/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (c *Client) WritePointsWithOptions(ctx context.Context, options *WriteOptio
} else {
precision = c.config.WriteOptions.Precision
}
var defaultTags map[string]string;
if options != nil && options.defaultTags != nil {
defaultTags = options.defaultTags;
var defaultTags map[string]string
if options != nil && options.DefaultTags != nil {
defaultTags = options.DefaultTags
} else {
defaultTags = c.config.WriteOptions.defaultTags;
defaultTags = c.config.WriteOptions.DefaultTags
}

for _, p := range points {
Expand Down Expand Up @@ -283,5 +283,5 @@ func encode(x interface{}, options *WriteOptions) ([]byte, error) {
if !point.HasFields() {
return nil, fmt.Errorf("no struct field with tag 'field'")
}
return point.MarshalBinaryWithDefaultTags(options.Precision, options.defaultTags)
return point.MarshalBinaryWithDefaultTags(options.Precision, options.DefaultTags)
}
12 changes: 6 additions & 6 deletions influxdb3/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ func TestWritePointsAndBytes(t *testing.T) {

func TestWritePointsWithOptions(t *testing.T) {
points := genPoints(t, 1)
defaultTags := map[string]string{
defaultTags := map[string]string{
"defaultTag": "default",
"rack": "main",
"rack": "main",
}
lp := points2bytes(t, points, defaultTags)
correctPath := "/api/v2/write?bucket=x-db&org=&precision=ms"
Expand All @@ -408,9 +408,9 @@ func TestWritePointsWithOptions(t *testing.T) {
Database: "my-database",
})
options := WriteOptions{
Database: "x-db",
Precision: lineprotocol.Millisecond,
defaultTags: defaultTags,
Database: "x-db",
Precision: lineprotocol.Millisecond,
DefaultTags: defaultTags,
}
require.NoError(t, err)
err = c.WritePointsWithOptions(context.Background(), &options, points...)
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestWriteDataWithOptions(t *testing.T) {
options := WriteOptions{
Database: "x-db",
Precision: lineprotocol.Second,
defaultTags: map[string]string{
DefaultTags: map[string]string{
"defaultTag": "default",
},
}
Expand Down
Loading