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

feat: implement use the '-' mark to ignore writing values for field #56

Merged

Conversation

daviderli614
Copy link
Member

@daviderli614 daviderli614 commented Dec 2, 2024

What's changed and what's your intention?

Similar to the following struct, The CPU field is marked with -, will write the zero value of the type:

type Monitor struct {
	ID          int64     `greptime:"tag;column:id;type:int64"`
	Host        string    `greptime:"tag;column:host;type:string"`
	Memory      uint64    `greptime:"field;column:memory;type:uint64"`
	Cpu         float64   `greptime:"-"`
	Temperature int64     `greptime:"field;column:temperature;type:int64"`
	Running     bool      `greptime:"field;column:running;type:boolean"`
	Ts          time.Time `greptime:"timestamp;column:ts;type:timestamp;precision:millisecond"`
}

Result:

+------+-----------+--------+------+-------------+---------+----------------------------+
| id   | host      | memory | cpu  | temperature | running | ts                         |
+------+-----------+--------+------+-------------+---------+----------------------------+
|    0 | 127.0.0.1 |      1 |    0 |          -1 |       0 | 2024-12-02 07:31:46.403000 |
|    0 | 127.0.0.1 |      1 |    0 |          -1 |       0 | 2024-12-02 07:31:46.587000 |
|    1 | 127.0.0.2 |      1 |    0 |          -1 |       1 | 2024-12-02 07:31:46.403000 |
|    1 | 127.0.0.2 |      1 |    0 |          -1 |       1 | 2024-12-02 07:31:46.587000 |
|    2 | 127.0.0.3 |      2 |    0 |          -2 |       1 | 2024-12-02 07:31:46.403000 |
|    2 | 127.0.0.3 |      2 |    0 |          -2 |       1 | 2024-12-02 07:31:46.587000 |
+------+-----------+--------+------+-------------+---------+----------------------------+
6 rows in set (0.03 sec)

Checklist

  • I have added the necessary unit tests and integration tests.

Refer to a related PR or issue link (optional)

#54

@daviderli614 daviderli614 requested a review from zyy17 December 2, 2024 07:58
@zyy17
Copy link
Contributor

zyy17 commented Dec 4, 2024

IMO, the meaning of greptime:"-" should be: ignore this field when writing and read with struct.

For this PR, it just writes the zero value, it's not a field ignore.

@daviderli614
Copy link
Member Author

IMO, the meaning of greptime:"-" should be: ignore this field when writing and read with struct.

For this PR, it just writes the zero value, it's not a field ignore.

Wait for me to modify it soon.

@daviderli614
Copy link
Member Author

daviderli614 commented Dec 10, 2024

Make some changes, please review again. @zyy17
Usage Examples: README
There a unit test TestParseSchemaWithSkipFields has passed.

schema/schema.go Outdated Show resolved Hide resolved
schema/schema.go Outdated Show resolved Hide resolved
schema/field.go Outdated Show resolved Hide resolved
examples/skipfields/main.go Outdated Show resolved Hide resolved
examples/skipfields/README.md Outdated Show resolved Hide resolved
schema/schema_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@zyy17 zyy17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daviderli614 daviderli614 merged commit 380bca5 into GreptimeTeam:main Dec 13, 2024
6 checks passed
@daviderli614 daviderli614 deleted the feat/support-ignore-field branch December 13, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants