You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/12/29 10:27:02 UTC

[iotdb-client-go] branch rel/0.13 updated: [To rel/0.13] Fix some bugs about time zone (#70)

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

haonan pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb-client-go.git


The following commit(s) were added to refs/heads/rel/0.13 by this push:
     new a891d01  [To rel/0.13] Fix some bugs about time zone (#70)
a891d01 is described below

commit a891d01e9cacaf32ab3c225300474769351030f4
Author: 橘子 <70...@users.noreply.github.com>
AuthorDate: Thu Dec 29 02:26:58 2022 -0800

    [To rel/0.13] Fix some bugs about time zone (#70)
    
    * set DefaultTimeZone if GetTimeZone returns an error
    
    1. If the error is not handled, the TimeZone in the config may be directly set to a empty string value
    2. In previous file 'session_example.go', the time zone was printed only when there was an error. It should be a logical error
    
    * [To rel/0.13] cleanup invalid codes from session
    
    The changes are almost the same as this PR:https://github.com/apache/iotdb-client-go/pull/68
---
 client/session.go          | 30 +++++++++++-------------------
 example/session_example.go |  6 ++++--
 2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/client/session.go b/client/session.go
index 4572e27..36c6d1c 100644
--- a/client/session.go
+++ b/client/session.go
@@ -108,12 +108,7 @@ func (s *Session) Open(enableRPCCompression bool, connectionTimeoutInMs int) err
 	}
 	s.sessionId = resp.GetSessionId()
 	s.requestStatementId, err = s.client.RequestStatementId(context.Background(), s.sessionId)
-	if err != nil {
-		return err
-	}
 
-	s.SetTimeZone(s.config.TimeZone)
-	s.config.TimeZone, err = s.GetTimeZone()
 	return err
 }
 
@@ -154,19 +149,14 @@ func (s *Session) OpenCluster(enableRPCCompression bool) error {
 	s.client = rpc.NewTSIServiceClient(thrift.NewTStandardClient(iprot, oprot))
 	req := rpc.TSOpenSessionReq{ClientProtocol: rpc.TSProtocolVersion_IOTDB_SERVICE_PROTOCOL_V3, ZoneId: s.config.TimeZone, Username: &s.config.UserName,
 		Password: &s.config.Password}
-	fmt.Println(req)
+
 	resp, err := s.client.OpenSession(context.Background(), &req)
 	if err != nil {
 		return err
 	}
 	s.sessionId = resp.GetSessionId()
 	s.requestStatementId, err = s.client.RequestStatementId(context.Background(), s.sessionId)
-	if err != nil {
-		return err
-	}
 
-	s.SetTimeZone(s.config.TimeZone)
-	s.config.TimeZone, err = s.GetTimeZone()
 	return err
 }
 
@@ -405,7 +395,7 @@ func (s *Session) InsertStringRecord(deviceId string, measurements []string, val
 func (s *Session) GetTimeZone() (string, error) {
 	resp, err := s.client.GetTimeZone(context.Background(), s.sessionId)
 	if err != nil {
-		return "", err
+		return DefaultTimeZone, err
 	}
 	return resp.TimeZone, nil
 }
@@ -1025,8 +1015,15 @@ func (s *Session) initClusterConn(node endPoint) error {
 			}
 		}
 	}
-	var protocolFactory thrift.TProtocolFactory
-	protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
+
+	if s.config.FetchSize <= 0 {
+		s.config.FetchSize = DefaultFetchSize
+	}
+	if s.config.TimeZone == "" {
+		s.config.TimeZone = DefaultTimeZone
+	}
+
+	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
 	iprot := protocolFactory.GetProtocol(s.trans)
 	oprot := protocolFactory.GetProtocol(s.trans)
 	s.client = rpc.NewTSIServiceClient(thrift.NewTStandardClient(iprot, oprot))
@@ -1039,12 +1036,7 @@ func (s *Session) initClusterConn(node endPoint) error {
 	}
 	s.sessionId = resp.GetSessionId()
 	s.requestStatementId, err = s.client.RequestStatementId(context.Background(), s.sessionId)
-	if err != nil {
-		return err
-	}
 
-	s.SetTimeZone(s.config.TimeZone)
-	s.config.TimeZone, err = s.GetTimeZone()
 	return err
 
 }
diff --git a/example/session_example.go b/example/session_example.go
index 1d88c7a..83848d8 100644
--- a/example/session_example.go
+++ b/example/session_example.go
@@ -99,8 +99,10 @@ func main() {
 	deleteData()
 
 	setTimeZone()
-	if tz, err := getTimeZone(); err != nil {
-		fmt.Printf("TimeZone: %s", tz)
+	if tz, err := getTimeZone(); err == nil {
+		fmt.Printf("TimeZone: %s\n", tz)
+	} else {
+		fmt.Printf("getTimeZone ERROR: %v\n", err)
 	}
 
 	executeStatement()