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 2024/09/26 07:10:58 UTC

(iotdb-client-go) branch new_datatype created (now 83fe9c6)

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

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


      at 83fe9c6  dev STRING BLOB

This branch includes the following new commits:

     new c92755d  init
     new 83fe9c6  dev STRING BLOB

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(iotdb-client-go) 02/02: dev STRING BLOB

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 83fe9c6ac1308a0d9abfc2ec8e240847d4cd924e
Author: HTHou <hh...@outlook.com>
AuthorDate: Thu Sep 26 15:10:44 2024 +0800

    dev STRING BLOB
---
 client/field.go      |  4 +++
 client/rpcdataset.go | 38 +++++++++++++++-----------
 client/session.go    | 75 +++++-----------------------------------------------
 client/tablet.go     | 43 +++++++++++++++++-------------
 client/utils.go      | 10 +++++++
 5 files changed, 69 insertions(+), 101 deletions(-)

diff --git a/client/field.go b/client/field.go
index 3e79445..e01beaa 100644
--- a/client/field.go
+++ b/client/field.go
@@ -92,3 +92,7 @@ func (f *Field) GetText() string {
 	}
 	return ""
 }
+
+func (f *Field) GetBlob() []byte {
+	return f.value.([]byte)
+}
diff --git a/client/rpcdataset.go b/client/rpcdataset.go
index 0dd77cd..4b1eb1d 100644
--- a/client/rpcdataset.go
+++ b/client/rpcdataset.go
@@ -39,12 +39,16 @@ const (
 var (
 	errClosed error                 = errors.New("DataSet is Closed")
 	tsTypeMap map[string]TSDataType = map[string]TSDataType{
-		"BOOLEAN": BOOLEAN,
-		"INT32":   INT32,
-		"INT64":   INT64,
-		"FLOAT":   FLOAT,
-		"DOUBLE":  DOUBLE,
-		"TEXT":    TEXT,
+		"BOOLEAN":   BOOLEAN,
+		"INT32":     INT32,
+		"INT64":     INT64,
+		"FLOAT":     FLOAT,
+		"DOUBLE":    DOUBLE,
+		"TEXT":      TEXT,
+		"TIMESTAMP": TIMESTAMP,
+		"DATE":      DATE,
+		"BLOB":      BLOB,
+		"STRING":    STRING,
 	}
 )
 
@@ -119,7 +123,7 @@ func (s *IoTDBRpcDataSet) constructOneRow() error {
 			case INT32:
 				s.values[i] = valueBuffer[:4]
 				s.queryDataSet.ValueList[i] = valueBuffer[4:]
-			case INT64:
+			case INT64, TIMESTAMP:
 				s.values[i] = valueBuffer[:8]
 				s.queryDataSet.ValueList[i] = valueBuffer[8:]
 			case FLOAT:
@@ -128,7 +132,7 @@ func (s *IoTDBRpcDataSet) constructOneRow() error {
 			case DOUBLE:
 				s.values[i] = valueBuffer[:8]
 				s.queryDataSet.ValueList[i] = valueBuffer[8:]
-			case TEXT:
+			case TEXT, BLOB, STRING:
 				length := bytesToInt32(valueBuffer[:4])
 				s.values[i] = valueBuffer[4 : 4+length]
 				s.queryDataSet.ValueList[i] = valueBuffer[4+length:]
@@ -178,7 +182,7 @@ func (s *IoTDBRpcDataSet) getString(columnIndex int, dataType TSDataType) string
 		return "false"
 	case INT32:
 		return int32ToString(bytesToInt32(valueBytes))
-	case INT64:
+	case INT64, TIMESTAMP:
 		return int64ToString(bytesToInt64(valueBytes))
 	case FLOAT:
 		bits := binary.BigEndian.Uint32(valueBytes)
@@ -186,8 +190,10 @@ func (s *IoTDBRpcDataSet) getString(columnIndex int, dataType TSDataType) string
 	case DOUBLE:
 		bits := binary.BigEndian.Uint64(valueBytes)
 		return float64ToString(math.Float64frombits(bits))
-	case TEXT:
+	case TEXT, STRING:
 		return string(valueBytes)
+	case BLOB:
+		return parseBytesToString(valueBytes)
 	default:
 		return ""
 	}
@@ -206,10 +212,10 @@ func (s *IoTDBRpcDataSet) getValue(columnName string) interface{} {
 	valueBytes := s.values[columnIndex]
 	switch dataType {
 	case BOOLEAN:
-		return bool(valueBytes[0] != 0)
+		return valueBytes[0] != 0
 	case INT32:
 		return bytesToInt32(valueBytes)
-	case INT64:
+	case INT64, TIMESTAMP:
 		return bytesToInt64(valueBytes)
 	case FLOAT:
 		bits := binary.BigEndian.Uint32(valueBytes)
@@ -217,8 +223,10 @@ func (s *IoTDBRpcDataSet) getValue(columnName string) interface{} {
 	case DOUBLE:
 		bits := binary.BigEndian.Uint64(valueBytes)
 		return math.Float64frombits(bits)
-	case TEXT:
+	case TEXT, STRING:
 		return string(valueBytes)
+	case BLOB:
+		return valueBytes
 	default:
 		return nil
 	}
@@ -301,7 +309,7 @@ func (s *IoTDBRpcDataSet) scan(dest ...interface{}) error {
 			default:
 				return fmt.Errorf("dest[%d] types must be *int32 or *string", i)
 			}
-		case INT64:
+		case INT64, TIMESTAMP:
 			switch t := d.(type) {
 			case *int64:
 				*t = bytesToInt64(valueBytes)
@@ -332,7 +340,7 @@ func (s *IoTDBRpcDataSet) scan(dest ...interface{}) error {
 			default:
 				return fmt.Errorf("dest[%d] types must be *float64 or *string", i)
 			}
-		case TEXT:
+		case TEXT, STRING, BLOB:
 			switch t := d.(type) {
 			case *string:
 				*t = string(valueBytes)
diff --git a/client/session.go b/client/session.go
index 6fc014b..9c209ad 100644
--- a/client/session.go
+++ b/client/session.go
@@ -90,9 +90,6 @@ func (s *Session) Open(enableRPCCompression bool, connectionTimeoutInMs int) err
 	s.trans = thrift.NewTSocketConf(net.JoinHostPort(s.config.Host, s.config.Port), &thrift.TConfiguration{
 		ConnectTimeout: time.Duration(connectionTimeoutInMs) * time.Millisecond, // Use 0 for no timeout
 	})
-	if err != nil {
-		return err
-	}
 	// s.trans = thrift.NewTFramedTransport(s.trans)	// deprecated
 	var tmp_conf = thrift.TConfiguration{MaxFrameSize: thrift.DEFAULT_MAX_FRAME_SIZE}
 	s.trans = thrift.NewTFramedTransportConf(s.trans, &tmp_conf)
@@ -951,8 +948,7 @@ func valuesToBytes(dataTypes []TSDataType, values []interface{}) ([]byte, error)
 			default:
 				return nil, fmt.Errorf("values[%d] %v(%v) must be int32", i, v, reflect.TypeOf(v))
 			}
-		case INT64:
-		case TIMESTAMP:
+		case INT64, TIMESTAMP:
 			switch v.(type) {
 			case int64:
 				binary.Write(buff, binary.BigEndian, v)
@@ -973,82 +969,25 @@ func valuesToBytes(dataTypes []TSDataType, values []interface{}) ([]byte, error)
 			default:
 				return nil, fmt.Errorf("values[%d] %v(%v) must be float64", i, v, reflect.TypeOf(v))
 			}
-		case TEXT:
-		case STRING:
+		case TEXT, STRING:
 			switch s := v.(type) {
 			case string:
 				size := len(s)
 				binary.Write(buff, binary.BigEndian, int32(size))
 				binary.Write(buff, binary.BigEndian, []byte(s))
-			default:
-				return nil, fmt.Errorf("values[%d] %v(%v) must be string", i, v, reflect.TypeOf(v))
-			}
-		case BLOB:
-			switch s := v.(type) {
-			case string:
+			case []byte:
 				size := len(s)
 				binary.Write(buff, binary.BigEndian, int32(size))
-				binary.Write(buff, binary.BigEndian, []byte(s))
+				binary.Write(buff, binary.BigEndian, s)
 			default:
 				return nil, fmt.Errorf("values[%d] %v(%v) must be string", i, v, reflect.TypeOf(v))
 			}
-		default:
-			return nil, fmt.Errorf("types[%d] is incorrect, it must in (BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT)", i)
-		}
-	}
-	return buff.Bytes(), nil
-}
-
-func valuesToBytesForFast(dataTypes []TSDataType, values []interface{}) ([]byte, error) {
-	buff := &bytes.Buffer{}
-	for i, t := range dataTypes {
-		v := values[i]
-		if v == nil {
-			return nil, fmt.Errorf("values[%d] can't be nil", i)
-		}
-
-		switch t {
-		case BOOLEAN:
-			switch v.(type) {
-			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))
-			}
-		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))
-			}
-		case INT64:
-			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))
-			}
-		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))
-			}
-		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))
-			}
-		case TEXT:
+		case BLOB:
 			switch s := v.(type) {
-			case string:
+			case []byte:
 				size := len(s)
 				binary.Write(buff, binary.BigEndian, int32(size))
-				binary.Write(buff, binary.BigEndian, []byte(s))
+				binary.Write(buff, binary.BigEndian, s)
 			default:
 				return nil, fmt.Errorf("values[%d] %v(%v) must be string", i, v, reflect.TypeOf(v))
 			}
diff --git a/client/tablet.go b/client/tablet.go
index ff4ef57..4d5cf42 100644
--- a/client/tablet.go
+++ b/client/tablet.go
@@ -55,7 +55,7 @@ func (t *Tablet) Swap(i, j int) {
 		case INT32:
 			sortedSlice := t.values[index].([]int32)
 			sortedSlice[i], sortedSlice[j] = sortedSlice[j], sortedSlice[i]
-		case INT64:
+		case INT64, TIMESTAMP:
 			sortedSlice := t.values[index].([]int64)
 			sortedSlice[i], sortedSlice[j] = sortedSlice[j], sortedSlice[i]
 		case FLOAT:
@@ -64,8 +64,8 @@ func (t *Tablet) Swap(i, j int) {
 		case DOUBLE:
 			sortedSlice := t.values[index].([]float64)
 			sortedSlice[i], sortedSlice[j] = sortedSlice[j], sortedSlice[i]
-		case TEXT:
-			sortedSlice := t.values[index].([]string)
+		case TEXT, BLOB, STRING:
+			sortedSlice := t.values[index].([][]byte)
 			sortedSlice[i], sortedSlice[j] = sortedSlice[j], sortedSlice[i]
 		}
 	}
@@ -141,7 +141,7 @@ func (t *Tablet) SetValueAt(value interface{}, columnIndex, rowIndex int) error
 		default:
 			return fmt.Errorf("illegal argument value %v %v", value, reflect.TypeOf(value))
 		}
-	case INT64:
+	case INT64, TIMESTAMP:
 		values := t.values[columnIndex].([]int64)
 		switch v := value.(type) {
 		case int64:
@@ -171,13 +171,21 @@ func (t *Tablet) SetValueAt(value interface{}, columnIndex, rowIndex int) error
 		default:
 			return fmt.Errorf("illegal argument value %v %v", value, reflect.TypeOf(value))
 		}
-	case TEXT:
-		values := t.values[columnIndex].([]string)
+	case TEXT, STRING:
+		values := t.values[columnIndex].([][]byte)
 		switch v := value.(type) {
 		case string:
+			values[rowIndex] = []byte(v)
+		case []byte:
 			values[rowIndex] = v
+		default:
+			return fmt.Errorf("illegal argument value %v %v", value, reflect.TypeOf(value))
+		}
+	case BLOB:
+		values := t.values[columnIndex].([][]byte)
+		switch v := value.(type) {
 		case []byte:
-			values[rowIndex] = string(v)
+			values[rowIndex] = v
 		default:
 			return fmt.Errorf("illegal argument value %v %v", value, reflect.TypeOf(value))
 		}
@@ -194,7 +202,6 @@ func (t *Tablet) GetValueAt(columnIndex, rowIndex int) (interface{}, error) {
 		return nil, fmt.Errorf("illegal argument columnIndex %d", columnIndex)
 	}
 
-
 	if rowIndex < 0 || rowIndex > t.maxRowNumber {
 		return nil, fmt.Errorf("illegal argument rowIndex %d", rowIndex)
 	}
@@ -209,14 +216,14 @@ func (t *Tablet) GetValueAt(columnIndex, rowIndex int) (interface{}, error) {
 		return t.values[columnIndex].([]bool)[rowIndex], nil
 	case INT32:
 		return t.values[columnIndex].([]int32)[rowIndex], nil
-	case INT64:
+	case INT64, TIMESTAMP:
 		return t.values[columnIndex].([]int64)[rowIndex], nil
 	case FLOAT:
 		return t.values[columnIndex].([]float32)[rowIndex], nil
 	case DOUBLE:
 		return t.values[columnIndex].([]float64)[rowIndex], nil
-	case TEXT:
-		return t.values[columnIndex].([]string)[rowIndex], nil
+	case TEXT, STRING, BLOB:
+		return t.values[columnIndex].([][]byte)[rowIndex], nil
 	default:
 		return nil, fmt.Errorf("illegal datatype %v", schema.DataType)
 	}
@@ -252,16 +259,16 @@ func (t *Tablet) getValuesBytes() ([]byte, error) {
 			binary.Write(buff, binary.BigEndian, t.values[i].([]bool)[0:t.RowSize])
 		case INT32:
 			binary.Write(buff, binary.BigEndian, t.values[i].([]int32)[0:t.RowSize])
-		case INT64:
+		case INT64, TIMESTAMP:
 			binary.Write(buff, binary.BigEndian, t.values[i].([]int64)[0:t.RowSize])
 		case FLOAT:
 			binary.Write(buff, binary.BigEndian, t.values[i].([]float32)[0:t.RowSize])
 		case DOUBLE:
 			binary.Write(buff, binary.BigEndian, t.values[i].([]float64)[0:t.RowSize])
-		case TEXT:
-			for _, s := range t.values[i].([]string)[0:t.RowSize] {
+		case TEXT, STRING, BLOB:
+			for _, s := range t.values[i].([][]byte)[0:t.RowSize] {
 				binary.Write(buff, binary.BigEndian, int32(len(s)))
-				binary.Write(buff, binary.BigEndian, []byte(s))
+				binary.Write(buff, binary.BigEndian, s)
 			}
 		default:
 			return nil, fmt.Errorf("illegal datatype %v", schema.DataType)
@@ -303,14 +310,14 @@ func NewTablet(deviceId string, measurementSchemas []*MeasurementSchema, maxRowN
 			tablet.values[i] = make([]bool, maxRowNumber)
 		case INT32:
 			tablet.values[i] = make([]int32, maxRowNumber)
-		case INT64:
+		case INT64, TIMESTAMP:
 			tablet.values[i] = make([]int64, maxRowNumber)
 		case FLOAT:
 			tablet.values[i] = make([]float32, maxRowNumber)
 		case DOUBLE:
 			tablet.values[i] = make([]float64, maxRowNumber)
-		case TEXT:
-			tablet.values[i] = make([]string, maxRowNumber)
+		case TEXT, STRING, BLOB:
+			tablet.values[i] = make([][]byte, maxRowNumber)
 		default:
 			return nil, fmt.Errorf("illegal datatype %v", schema.DataType)
 		}
diff --git a/client/utils.go b/client/utils.go
index f3c465b..fc835dc 100644
--- a/client/utils.go
+++ b/client/utils.go
@@ -69,6 +69,16 @@ func bytesToInt64(bys []byte) int64 {
 	return int64(data)
 }
 
+func parseBytesToString(input []byte) string {
+	hexString := "0x"
+	if input != nil {
+		for _, b := range input {
+			hexString += fmt.Sprintf("%02x", b)
+		}
+	}
+	return hexString
+}
+
 func verifySuccesses(statuses []*common.TSStatus) error {
 	buff := bytes.Buffer{}
 	for _, status := range statuses {


(iotdb-client-go) 01/02: init

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c92755dc272e0846219f2bce9aff0b31427d95cd
Author: HTHou <hh...@outlook.com>
AuthorDate: Thu Sep 19 09:54:40 2024 +0800

    init
---
 client/protocol.go | 54 +++++++++++++++++++++++++++---------------------------
 client/session.go  | 11 +++++++++++
 2 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/client/protocol.go b/client/protocol.go
index 883f9ae..edc211e 100644
--- a/client/protocol.go
+++ b/client/protocol.go
@@ -26,42 +26,42 @@ type TSEncoding uint8
 type TSCompressionType uint8
 
 const (
-	UNKNOWN TSDataType = -1
-	BOOLEAN TSDataType = 0
-	INT32   TSDataType = 1
-	INT64   TSDataType = 2
-	FLOAT   TSDataType = 3
-	DOUBLE  TSDataType = 4
-	TEXT    TSDataType = 5
+	UNKNOWN   TSDataType = -1
+	BOOLEAN   TSDataType = 0
+	INT32     TSDataType = 1
+	INT64     TSDataType = 2
+	FLOAT     TSDataType = 3
+	DOUBLE    TSDataType = 4
+	TEXT      TSDataType = 5
+	TIMESTAMP TSDataType = 8
+	DATE      TSDataType = 9
+	BLOB      TSDataType = 10
+	STRING    TSDataType = 11
 )
 
 const (
-	PLAIN            TSEncoding = 0
-	PLAIN_DICTIONARY TSEncoding = 1
-	RLE              TSEncoding = 2
-	DIFF             TSEncoding = 3
-	TS_2DIFF         TSEncoding = 4
-	BITMAP           TSEncoding = 5
-	GORILLA_V1       TSEncoding = 6
-	REGULAR          TSEncoding = 7
-	GORILLA          TSEncoding = 8
-    ZIGZAG           TSEncoding = 9
-    FREQ             TSEncoding = 10
-    CHIMP            TSEncoding = 11
-    SPRINTZ          TSEncoding = 12
-    RLBE             TSEncoding = 13
+	PLAIN      TSEncoding = 0
+	DICTIONARY TSEncoding = 1
+	RLE        TSEncoding = 2
+	DIFF       TSEncoding = 3
+	TS_2DIFF   TSEncoding = 4
+	BITMAP     TSEncoding = 5
+	GORILLA_V1 TSEncoding = 6
+	REGULAR    TSEncoding = 7
+	GORILLA    TSEncoding = 8
+	ZIGZAG     TSEncoding = 9
+	FREQ       TSEncoding = 10
+	CHIMP      TSEncoding = 11
+	SPRINTZ    TSEncoding = 12
+	RLBE       TSEncoding = 13
 )
 
 const (
 	UNCOMPRESSED TSCompressionType = 0
 	SNAPPY       TSCompressionType = 1
 	GZIP         TSCompressionType = 2
-	LZO          TSCompressionType = 3
-	SDT          TSCompressionType = 4
-	PAA          TSCompressionType = 5
-	PLA          TSCompressionType = 6
 	LZ4          TSCompressionType = 7
-	ZSTD		 TSCompressionType = 8
+	ZSTD         TSCompressionType = 8
 	LZMA2        TSCompressionType = 9
 )
 
@@ -201,4 +201,4 @@ const (
 	CqAlreadyActive           int32 = 1401
 	CqAlreadyExist            int32 = 1402
 	CqUpdateLastExecTimeError int32 = 1403
-)
\ No newline at end of file
+)
diff --git a/client/session.go b/client/session.go
index 47985f8..6fc014b 100644
--- a/client/session.go
+++ b/client/session.go
@@ -952,6 +952,7 @@ func valuesToBytes(dataTypes []TSDataType, values []interface{}) ([]byte, error)
 				return nil, fmt.Errorf("values[%d] %v(%v) must be int32", i, v, reflect.TypeOf(v))
 			}
 		case INT64:
+		case TIMESTAMP:
 			switch v.(type) {
 			case int64:
 				binary.Write(buff, binary.BigEndian, v)
@@ -973,6 +974,16 @@ func valuesToBytes(dataTypes []TSDataType, values []interface{}) ([]byte, error)
 				return nil, fmt.Errorf("values[%d] %v(%v) must be float64", i, v, reflect.TypeOf(v))
 			}
 		case TEXT:
+		case STRING:
+			switch s := v.(type) {
+			case string:
+				size := len(s)
+				binary.Write(buff, binary.BigEndian, int32(size))
+				binary.Write(buff, binary.BigEndian, []byte(s))
+			default:
+				return nil, fmt.Errorf("values[%d] %v(%v) must be string", i, v, reflect.TypeOf(v))
+			}
+		case BLOB:
 			switch s := v.(type) {
 			case string:
 				size := len(s)