diff --git a/examples/object/README.md b/examples/object/README.md index faaa719..1c82fdb 100644 --- a/examples/object/README.md +++ b/examples/object/README.md @@ -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) ``` diff --git a/examples/object/main.go b/examples/object/main.go index f25dc70..0f6b0d8 100644 --- a/examples/object/main.go +++ b/examples/object/main.go @@ -53,9 +53,16 @@ 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(), @@ -63,7 +70,7 @@ func initData() []Monitor { }, { ID: 2, - Host: "127.0.0.2", + Host: "127.0.0.3", Memory: 2, Cpu: 2.0, Temperature: -2, @@ -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, @@ -81,6 +88,7 @@ func initData() []Monitor { }, } } + func writeObject(data []Monitor) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*3) defer cancel() @@ -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:]) } diff --git a/request/request.go b/request/request.go index d46366d..686b676 100644 --- a/request/request.go +++ b/request/request.go @@ -51,12 +51,12 @@ func (r *Request) WithTables(tables ...*table.Table) *Request { return r } -func (r *Request) IsZero() bool { - return r.tables == nil || len(r.tables) == 0 +func (r *Request) IsNilTable() bool { + return r.tables == nil } func (r *Request) Build() (*gpb.GreptimeRequest, error) { - if r.IsZero() { + if r.IsNilTable() { return nil, errs.ErrEmptyTable } diff --git a/schema/field.go b/schema/field.go index d8c2579..5fbb9c4 100644 --- a/schema/field.go +++ b/schema/field.go @@ -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() { return nil, nil }