This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iotdb-client-go.git
The following commit(s) were added to refs/heads/main by this push:
new 2f7ff76 Print measurement for putting buffer exceptions (#136)
2f7ff76 is described below
commit 2f7ff76920ec182a543a046c7220922b02fb0d07
Author: shuwenwei <[email protected]>
AuthorDate: Fri Aug 22 16:00:51 2025 +0800
Print measurement for putting buffer exceptions (#136)
---
client/session.go | 28 ++++++++++++++--------------
test/e2e/e2e_test.go | 14 ++++++++++++++
2 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/client/session.go b/client/session.go
index 230799f..966fba4 100644
--- a/client/session.go
+++ b/client/session.go
@@ -667,7 +667,7 @@ func (s *Session) genTSInsertRecordReq(deviceId string,
time int64,
request.Timestamp = time
request.Measurements = measurements
request.IsAligned = &isAligned
- if bys, err := valuesToBytes(types, values); err == nil {
+ if bys, err := valuesToBytes(types, values, measurements); err == nil {
request.Values = bys
} else {
return nil, err
@@ -753,7 +753,7 @@ func (s *Session) InsertRecordsOfOneDevice(deviceId string,
timestamps []int64,
valuesList := make([][]byte, length)
for i := 0; i < length; i++ {
- if valuesList[i], err = valuesToBytes(dataTypesSlice[i],
valuesSlice[i]); err != nil {
+ if valuesList[i], err = valuesToBytes(dataTypesSlice[i],
valuesSlice[i], measurementsSlice[i]); err != nil {
return nil, err
}
}
@@ -795,7 +795,7 @@ func (s *Session) InsertAlignedRecordsOfOneDevice(deviceId
string, timestamps []
valuesList := make([][]byte, length)
for i := 0; i < length; i++ {
- if valuesList[i], err = valuesToBytes(dataTypesSlice[i],
valuesSlice[i]); err != nil {
+ if valuesList[i], err = valuesToBytes(dataTypesSlice[i],
valuesSlice[i], measurementsSlice[i]); err != nil {
return nil, err
}
}
@@ -1043,7 +1043,7 @@ func (s *Session) genInsertRecordsReq(deviceIds []string,
measurements [][]strin
}
v := make([][]byte, length)
for i := 0; i < len(measurements); i++ {
- if bys, err := valuesToBytes(dataTypes[i], values[i]); err ==
nil {
+ if bys, err := valuesToBytes(dataTypes[i], values[i],
measurements[i]); err == nil {
v[i] = bys
} else {
return nil, err
@@ -1053,7 +1053,7 @@ func (s *Session) genInsertRecordsReq(deviceIds []string,
measurements [][]strin
return &request, nil
}
-func valuesToBytes(dataTypes []TSDataType, values []interface{}) ([]byte,
error) {
+func valuesToBytes(dataTypes []TSDataType, values []interface{},
measurementNames []string) ([]byte, error) {
buff := &bytes.Buffer{}
for i, t := range dataTypes {
binary.Write(buff, binary.BigEndian, byte(t))
@@ -1068,35 +1068,35 @@ func valuesToBytes(dataTypes []TSDataType, values
[]interface{}) ([]byte, error)
case bool:
binary.Write(buff, binary.BigEndian, v)
default:
- return nil, fmt.Errorf("values[%d] %v(%v) must
be bool", i, v, reflect.TypeOf(v))
+ return nil, fmt.Errorf("measurement %s
values[%d] %v(%v) must be bool", measurementNames[i], i, v, reflect.TypeOf(v))
}
case INT32:
switch v.(type) {
case int32:
binary.Write(buff, binary.BigEndian, v)
default:
- return nil, fmt.Errorf("values[%d] %v(%v) must
be int32", i, v, reflect.TypeOf(v))
+ return nil, fmt.Errorf("measurement %s
values[%d] %v(%v) must be int32", measurementNames[i], i, v, reflect.TypeOf(v))
}
case INT64, TIMESTAMP:
switch v.(type) {
case int64:
binary.Write(buff, binary.BigEndian, v)
default:
- return nil, fmt.Errorf("values[%d] %v(%v) must
be int64", i, v, reflect.TypeOf(v))
+ return nil, fmt.Errorf("measurement %s
values[%d] %v(%v) must be int64", measurementNames[i], i, v, reflect.TypeOf(v))
}
case FLOAT:
switch v.(type) {
case float32:
binary.Write(buff, binary.BigEndian, v)
default:
- return nil, fmt.Errorf("values[%d] %v(%v) must
be float32", i, v, reflect.TypeOf(v))
+ return nil, fmt.Errorf("measurement %s
values[%d] %v(%v) must be float32", measurementNames[i], i, v,
reflect.TypeOf(v))
}
case DOUBLE:
switch v.(type) {
case float64:
binary.Write(buff, binary.BigEndian, v)
default:
- return nil, fmt.Errorf("values[%d] %v(%v) must
be float64", i, v, reflect.TypeOf(v))
+ return nil, fmt.Errorf("measurement %s
values[%d] %v(%v) must be float64", measurementNames[i], i, v,
reflect.TypeOf(v))
}
case TEXT, STRING:
switch s := v.(type) {
@@ -1109,7 +1109,7 @@ func valuesToBytes(dataTypes []TSDataType, values
[]interface{}) ([]byte, error)
binary.Write(buff, binary.BigEndian,
int32(size))
binary.Write(buff, binary.BigEndian, s)
default:
- return nil, fmt.Errorf("values[%d] %v(%v) must
be string or []byte", i, v, reflect.TypeOf(v))
+ return nil, fmt.Errorf("measurement %s
values[%d] %v(%v) must be string or []byte", measurementNames[i], i, v,
reflect.TypeOf(v))
}
case BLOB:
switch s := v.(type) {
@@ -1118,7 +1118,7 @@ func valuesToBytes(dataTypes []TSDataType, values
[]interface{}) ([]byte, error)
binary.Write(buff, binary.BigEndian,
int32(size))
binary.Write(buff, binary.BigEndian, s)
default:
- return nil, fmt.Errorf("values[%d] %v(%v) must
be []byte", i, v, reflect.TypeOf(v))
+ return nil, fmt.Errorf("measurement %s
values[%d] %v(%v) must be []byte", measurementNames[i], i, v, reflect.TypeOf(v))
}
case DATE:
switch s := v.(type) {
@@ -1129,10 +1129,10 @@ func valuesToBytes(dataTypes []TSDataType, values
[]interface{}) ([]byte, error)
}
binary.Write(buff, binary.BigEndian, date)
default:
- return nil, fmt.Errorf("values[%d] %v(%v) must
be time.Time", i, v, reflect.TypeOf(v))
+ return nil, fmt.Errorf("measurement %s
values[%d] %v(%v) must be time.Time", measurementNames[i], i, v,
reflect.TypeOf(v))
}
default:
- return nil, fmt.Errorf("types[%d] is incorrect, it must
in (BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT, TIMESTAMP, BLOB, DATE,
STRING)", i)
+ return nil, fmt.Errorf("measurement %s types[%d] is
incorrect, it must in (BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT, TIMESTAMP,
BLOB, DATE, STRING)", measurementNames[i], i)
}
}
return buff.Bytes(), nil
diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go
index a21a271..2557955 100644
--- a/test/e2e/e2e_test.go
+++ b/test/e2e/e2e_test.go
@@ -166,6 +166,20 @@ func (s *e2eTestSuite) Test_InsertRecords() {
assert.Equal(status, "Working")
}
+func (s *e2eTestSuite) Test_InsertRecordsWithWrongType() {
+ var (
+ deviceId = []string{"root.test.d1", "root.test.d2"}
+ measurements = [][]string{{"s1", "s2"}, {"s1"}}
+ dataTypes = [][]client.TSDataType{{client.BOOLEAN,
client.FLOAT}, {client.BOOLEAN}}
+ values = [][]interface{}{{100.0, true}, {"aaa"}}
+ timestamp = []int64{1, 2}
+ )
+ _, err := s.session.InsertRecords(deviceId, measurements, dataTypes,
values, timestamp)
+ assert := s.Require()
+ assert.NotNil(err)
+ assert.Equal("measurement s1 values[0] 100(float64) must be bool",
err.Error())
+}
+
func (s *e2eTestSuite) Test_InsertAlignedRecord() {
var (
deviceId = "root.tsg2.dev1"