This is an automated email from the ASF dual-hosted git repository.

jackietien 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 702151e  Change the visibility of some members of the tablet to 
package (#5)
702151e is described below

commit 702151e57434f25c84277fb86b7a573bb26c9708
Author: Mark Liu <[email protected]>
AuthorDate: Mon Dec 21 14:36:38 2020 +0800

    Change the visibility of some members of the tablet to package (#5)
    
    Change the visibility of some members of the tablet to package
---
 README.md                  |  3 ---
 README_ZH.md               |  3 ---
 client/session.go          | 30 +++++++++++++-------------
 client/tablet.go           | 54 +++++++++++++++++++++++-----------------------
 client/tablet_test.go      | 24 ++++++++++-----------
 example/session_example.go |  7 +++---
 6 files changed, 57 insertions(+), 64 deletions(-)

diff --git a/README.md b/README.md
index 1a796a0..cb62ddd 100644
--- a/README.md
+++ b/README.md
@@ -34,9 +34,6 @@ Apache IoTDB Github: https://github.com/apache/iotdb
 # How to Compile the Client
 
 # How to Use the Client (Quick Start)
-```
-Create project eg:session
-
 
 With go mod
 
diff --git a/README_ZH.md b/README_ZH.md
index 1df9a16..93e2c87 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -57,9 +57,6 @@ git checkout 0.13.0
 
 mkdir -p $GOPATH/src/iotdb-client-go-example/session_example
 cd $GOPATH/src/iotdb-client-go-example/session_example
-
-               fmt.Print("Time\t\t\t\t")
-               fmt.Print("Time\t\t\t\t")
 curl -o session_example.go -L 
https://github.com/apache/iotdb-client-go/raw/main/example/session_example.go
 go run session_example.go
 ```
diff --git a/client/session.go b/client/session.go
index a8db017..99673a6 100644
--- a/client/session.go
+++ b/client/session.go
@@ -395,7 +395,7 @@ func (s *Session) genInsertTabletsReq(tablets []*Tablet) 
(*rpc.TSInsertTabletsRe
                deviceIds[index] = tablet.deviceId
                measurementsList[index] = tablet.GetMeasurements()
 
-               values, err := tablet.GetValuesBytes()
+               values, err := tablet.getValuesBytes()
                if err != nil {
                        return nil, err
                }
@@ -403,7 +403,7 @@ func (s *Session) genInsertTabletsReq(tablets []*Tablet) 
(*rpc.TSInsertTabletsRe
                valuesList[index] = values
                timestampsList[index] = tablet.GetTimestampBytes()
                typesList[index] = tablet.getDataTypes()
-               sizeList[index] = int32(tablet.RowSize)
+               sizeList[index] = int32(tablet.rowCount)
        }
        request := rpc.TSInsertTabletsReq{
                SessionId:        s.sessionId,
@@ -511,21 +511,21 @@ func (s *Session) InsertTablet(tablet *Tablet) (r 
*rpc.TSStatus, err error) {
        return s.client.InsertTablet(context.Background(), request)
 }
 
-func (s *Session) genTSInsertTabletReq(tablet *Tablet) (request 
*rpc.TSInsertTabletReq, err error) {
-       values, err := tablet.GetValuesBytes()
-       if err != nil {
+func (s *Session) genTSInsertTabletReq(tablet *Tablet) 
(*rpc.TSInsertTabletReq, error) {
+       if values, err := tablet.getValuesBytes(); err == nil {
+               request := &rpc.TSInsertTabletReq{
+                       SessionId:    s.sessionId,
+                       DeviceId:     tablet.deviceId,
+                       Measurements: tablet.GetMeasurements(),
+                       Values:       values,
+                       Timestamps:   tablet.GetTimestampBytes(),
+                       Types:        tablet.getDataTypes(),
+                       Size:         int32(tablet.rowCount),
+               }
+               return request, nil
+       } else {
                return nil, err
        }
-       request = &rpc.TSInsertTabletReq{
-               SessionId:    s.sessionId,
-               DeviceId:     tablet.deviceId,
-               Measurements: tablet.GetMeasurements(),
-               Values:       values,
-               Timestamps:   tablet.GetTimestampBytes(),
-               Types:        tablet.getDataTypes(),
-               Size:         int32(tablet.RowSize),
-       }
-       return request, nil
 }
 
 func (s *Session) GetSessionId() int64 {
diff --git a/client/tablet.go b/client/tablet.go
index a8e078a..1396f5e 100644
--- a/client/tablet.go
+++ b/client/tablet.go
@@ -36,11 +36,11 @@ type MeasurementSchema struct {
 }
 
 type Tablet struct {
-       deviceId   string
-       Schemas    []*MeasurementSchema
-       timestamps []int64
-       values     []interface{}
-       RowSize    int
+       deviceId           string
+       measurementSchemas []*MeasurementSchema
+       timestamps         []int64
+       values             []interface{}
+       rowCount           int
 }
 
 func (t *Tablet) SetTimestamp(timestamp int64, rowIndex int) {
@@ -52,15 +52,15 @@ func (t *Tablet) SetValueAt(value interface{}, columnIndex, 
rowIndex int) error
                return errors.New("Illegal argument value can't be nil")
        }
 
-       if columnIndex < 0 || columnIndex > len(t.Schemas) {
+       if columnIndex < 0 || columnIndex > len(t.measurementSchemas) {
                return fmt.Errorf("Illegal argument columnIndex %d", 
columnIndex)
        }
 
-       if rowIndex < 0 || rowIndex > int(t.RowSize) {
+       if rowIndex < 0 || rowIndex > int(t.rowCount) {
                return fmt.Errorf("Illegal argument rowIndex %d", rowIndex)
        }
 
-       switch t.Schemas[columnIndex].DataType {
+       switch t.measurementSchemas[columnIndex].DataType {
        case BOOLEAN:
                values := t.values[columnIndex].([]bool)
                switch value.(type) {
@@ -124,24 +124,24 @@ func (t *Tablet) GetTimestampBytes() []byte {
 }
 
 func (t *Tablet) GetMeasurements() []string {
-       measurements := make([]string, len(t.Schemas))
-       for i, s := range t.Schemas {
+       measurements := make([]string, len(t.measurementSchemas))
+       for i, s := range t.measurementSchemas {
                measurements[i] = s.Measurement
        }
        return measurements
 }
 
 func (t *Tablet) getDataTypes() []int32 {
-       types := make([]int32, len(t.Schemas))
-       for i, s := range t.Schemas {
+       types := make([]int32, len(t.measurementSchemas))
+       for i, s := range t.measurementSchemas {
                types[i] = int32(s.DataType)
        }
        return types
 }
 
-func (t *Tablet) GetValuesBytes() ([]byte, error) {
+func (t *Tablet) getValuesBytes() ([]byte, error) {
        buff := &bytes.Buffer{}
-       for i, schema := range t.Schemas {
+       for i, schema := range t.measurementSchemas {
                switch schema.DataType {
                case BOOLEAN:
                        binary.Write(buff, binary.BigEndian, 
t.values[i].([]bool))
@@ -165,28 +165,28 @@ func (t *Tablet) GetValuesBytes() ([]byte, error) {
        return buff.Bytes(), nil
 }
 
-func NewTablet(deviceId string, schemas []*MeasurementSchema, size int) 
(*Tablet, error) {
+func NewTablet(deviceId string, measurementSchemas []*MeasurementSchema, 
rowCount int) (*Tablet, error) {
        tablet := &Tablet{
-               deviceId: deviceId,
-               Schemas:  schemas,
-               RowSize:  size,
+               deviceId:           deviceId,
+               measurementSchemas: measurementSchemas,
+               rowCount:           rowCount,
        }
-       tablet.timestamps = make([]int64, size)
-       tablet.values = make([]interface{}, len(schemas))
-       for i, schema := range tablet.Schemas {
+       tablet.timestamps = make([]int64, rowCount)
+       tablet.values = make([]interface{}, len(measurementSchemas))
+       for i, schema := range tablet.measurementSchemas {
                switch schema.DataType {
                case BOOLEAN:
-                       tablet.values[i] = make([]bool, size)
+                       tablet.values[i] = make([]bool, rowCount)
                case INT32:
-                       tablet.values[i] = make([]int32, size)
+                       tablet.values[i] = make([]int32, rowCount)
                case INT64:
-                       tablet.values[i] = make([]int64, size)
+                       tablet.values[i] = make([]int64, rowCount)
                case FLOAT:
-                       tablet.values[i] = make([]float32, size)
+                       tablet.values[i] = make([]float32, rowCount)
                case DOUBLE:
-                       tablet.values[i] = make([]float64, size)
+                       tablet.values[i] = make([]float64, rowCount)
                case TEXT:
-                       tablet.values[i] = make([]string, size)
+                       tablet.values[i] = make([]string, rowCount)
                default:
                        return nil, fmt.Errorf("Illegal datatype %v", 
schema.DataType)
                }
diff --git a/client/tablet_test.go b/client/tablet_test.go
index f47c365..936f700 100644
--- a/client/tablet_test.go
+++ b/client/tablet_test.go
@@ -76,11 +76,11 @@ func createTablet(size int) (*Tablet, error) {
 
 func TestTablet_getDataTypes(t *testing.T) {
        type fields struct {
-               deviceId   string
-               Schemas    []*MeasurementSchema
-               timestamps []int64
-               values     []interface{}
-               RowSize    int
+               deviceId           string
+               measurementSchemas []*MeasurementSchema
+               timestamps         []int64
+               values             []interface{}
+               rowCount           int
        }
        tests := []struct {
                name   string
@@ -91,7 +91,7 @@ func TestTablet_getDataTypes(t *testing.T) {
                        name: "",
                        fields: fields{
                                deviceId: "root.ln.device5",
-                               Schemas: []*MeasurementSchema{
+                               measurementSchemas: []*MeasurementSchema{
                                        &MeasurementSchema{
                                                Measurement: "restart_count",
                                                DataType:    INT32,
@@ -139,7 +139,7 @@ func TestTablet_getDataTypes(t *testing.T) {
                                },
                                timestamps: []int64{},
                                values:     []interface{}{},
-                               RowSize:    0,
+                               rowCount:   0,
                        },
                        want: []int32{int32(INT32), int32(DOUBLE), 
int32(INT64), int32(FLOAT), int32(TEXT), int32(BOOLEAN)},
                },
@@ -147,11 +147,11 @@ func TestTablet_getDataTypes(t *testing.T) {
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
                        tablet := &Tablet{
-                               deviceId:   tt.fields.deviceId,
-                               Schemas:    tt.fields.Schemas,
-                               timestamps: tt.fields.timestamps,
-                               values:     tt.fields.values,
-                               RowSize:    tt.fields.RowSize,
+                               deviceId:           tt.fields.deviceId,
+                               measurementSchemas: 
tt.fields.measurementSchemas,
+                               timestamps:         tt.fields.timestamps,
+                               values:             tt.fields.values,
+                               rowCount:           tt.fields.rowCount,
                        }
                        if got := tablet.getDataTypes(); 
!reflect.DeepEqual(got, tt.want) {
                                t.Errorf("Tablet.getDataTypes() = %v, want %v", 
got, tt.want)
diff --git a/example/session_example.go b/example/session_example.go
index f4daff1..2df9964 100644
--- a/example/session_example.go
+++ b/example/session_example.go
@@ -80,7 +80,6 @@ func main() {
 
        insertRecord()
        deleteData()
-       deleteTimeseries("root.sg1.dev1.status")
 
        setTimeZone()
        if tz, err := getTimeZone(); err != nil {
@@ -88,10 +87,11 @@ func main() {
        }
 
        executeStatement()
-       executeQueryStatement()
+       executeQueryStatement("select count(s3) from root.sg1.dev1")
        executeRawDataQuery()
        executeBatchStatement()
 
+       deleteTimeseries("root.sg1.dev1.status")
        deleteTimeseries("root.ln.wf02.wt02.s5")
 }
 
@@ -413,8 +413,7 @@ func executeStatement() {
        }
 }
 
-func executeQueryStatement() {
-       var sql = "select count(s3) from root.sg1.dev1"
+func executeQueryStatement(sql string) {
        sessionDataSet, err := session.ExecuteQueryStatement(sql)
        if err == nil {
                printDataSet1(sessionDataSet)

Reply via email to