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: write failed when value is zero #38

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 7 additions & 5 deletions examples/object/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ mysql> select * from monitors_with_tag;
+------+-----------+--------+------+-------------+---------+----------------------------+
| id | host | memory | cpu | temperature | running | ts |
+------+-----------+--------+------+-------------+---------+----------------------------+
| 1 | 127.0.0.1 | 1 | 1.1 | -1 | 1 | 2024-03-23 14:36:06.591000 |
| 1 | 127.0.0.1 | 1 | 1.1 | -1 | 1 | 2024-03-23 14:36:06.732000 |
| 2 | 127.0.0.2 | 2 | 2 | -2 | 1 | 2024-03-23 14:36:06.591000 |
| 2 | 127.0.0.2 | 2 | 2 | -2 | 1 | 2024-03-23 14:36:06.732000 |
| 0 | 127.0.0.1 | 1 | 1.3 | -1 | 0 | 2024-08-14 09:20:04.475000 |
| 0 | 127.0.0.1 | 1 | 1.3 | -1 | 0 | 2024-08-14 09:20:04.664000 |
| 1 | 127.0.0.2 | 1 | 1.1 | -1 | 1 | 2024-08-14 09:20:04.475000 |
| 1 | 127.0.0.2 | 1 | 1.1 | -1 | 1 | 2024-08-14 09:20:04.664000 |
| 2 | 127.0.0.3 | 2 | 2 | -2 | 1 | 2024-08-14 09:20:04.475000 |
| 2 | 127.0.0.3 | 2 | 2 | -2 | 1 | 2024-08-14 09:20:04.664000 |
+------+-----------+--------+------+-------------+---------+----------------------------+
4 rows in set (0.12 sec)
6 rows in set (0.03 sec)
```
22 changes: 15 additions & 7 deletions examples/object/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,24 @@ func (Monitor) TableName() string {
func initData() []Monitor {
return []Monitor{
{
ID: 1,
Host: "127.0.0.1",
Memory: 1,
Cpu: 1.3,
Temperature: -1,
Ts: time.Now(),
},
{
ID: 1,
Host: "127.0.0.2",
Memory: 1,
Cpu: 1.0,
Temperature: -1,
Ts: time.Now(),
Running: true,
},
{
ID: 2,
Host: "127.0.0.2",
Host: "127.0.0.3",
Memory: 2,
Cpu: 2.0,
Temperature: -2,
Expand All @@ -72,7 +79,7 @@ func initData() []Monitor {
},
{
ID: 3,
Host: "127.0.0.3",
Host: "127.0.0.4",
Memory: 3,
Cpu: 3.0,
Temperature: -3,
Expand All @@ -81,6 +88,7 @@ func initData() []Monitor {
},
}
}

func writeObject(data []Monitor) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
Expand Down Expand Up @@ -136,19 +144,19 @@ func main() {
// insert
writeObject(data)
// update
data[0].Cpu = 1.1
data[1].Cpu = 1.1
writeObject(data)
// delete
deleteObject(data[2:])
deleteObject(data[3:])

time.Sleep(time.Millisecond * 100)

data = initData()
// stream insert
streamWriteObject(data)
data[0].Cpu = 1.1
data[1].Cpu = 1.1
// stream update
streamWriteObject(data)
// stream delete
streamDeleteObject(data[2:])
streamDeleteObject(data[3:])
}
2 changes: 1 addition & 1 deletion request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (r *Request) WithTables(tables ...*table.Table) *Request {
}

func (r *Request) IsZero() bool {
return r.tables == nil || len(r.tables) == 0
return r.tables == nil
daviderli614 marked this conversation as resolved.
Show resolved Hide resolved
}

func (r *Request) Build() (*gpb.GreptimeRequest, error) {
Expand Down
2 changes: 1 addition & 1 deletion schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func parseIntOrTimeValue(typ gpb.ColumnDataType, val reflect.Value) (*gpb.Value,

func parseValue(typ gpb.ColumnDataType, val reflect.Value) (*gpb.Value, error) {
val = reflect.Indirect(val)
if !val.IsValid() || val.IsZero() {
if !val.IsValid() {
yuanbohan marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil
}

Expand Down
Loading