model.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. package tablestore
  2. import (
  3. "fmt"
  4. "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore/otsprotocol"
  5. "github.com/golang/protobuf/proto"
  6. "math/rand"
  7. "net/http"
  8. "strconv"
  9. "strings"
  10. "time"
  11. //"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
  12. )
  13. // @class TableStoreClient
  14. // The TableStoreClient, which will connect OTS service for authorization, create/list/
  15. // delete tables/table groups, to get/put/delete a row.
  16. // Note: TableStoreClient is thread-safe.
  17. // TableStoreClient的功能包括连接OTS服务进行验证、创建/列出/删除表或表组、插入/获取/
  18. // 删除/更新行数据
  19. type TableStoreClient struct {
  20. endPoint string
  21. instanceName string
  22. accessKeyId string
  23. accessKeySecret string
  24. securityToken string
  25. httpClient IHttpClient
  26. config *TableStoreConfig
  27. random *rand.Rand
  28. externalHeader map[string]string
  29. CustomizedRetryFunc CustomizedRetryNotMatterActions
  30. }
  31. type ClientOption func(*TableStoreClient)
  32. type TableStoreHttpClient struct {
  33. httpClient *http.Client
  34. }
  35. // use this to mock http.client for testing
  36. type IHttpClient interface {
  37. Do(*http.Request) (*http.Response, error)
  38. New(*http.Client)
  39. }
  40. func (httpClient *TableStoreHttpClient) Do(req *http.Request) (*http.Response, error) {
  41. return httpClient.httpClient.Do(req)
  42. }
  43. func (httpClient *TableStoreHttpClient) New(client *http.Client) {
  44. httpClient.httpClient = client
  45. }
  46. type HTTPTimeout struct {
  47. ConnectionTimeout time.Duration
  48. RequestTimeout time.Duration
  49. }
  50. type TableStoreConfig struct {
  51. RetryTimes uint
  52. MaxRetryTime time.Duration
  53. HTTPTimeout HTTPTimeout
  54. MaxIdleConnections int
  55. Transport http.RoundTripper
  56. }
  57. func NewDefaultTableStoreConfig() *TableStoreConfig {
  58. httpTimeout := &HTTPTimeout{
  59. ConnectionTimeout: time.Second * 15,
  60. RequestTimeout: time.Second * 30}
  61. config := &TableStoreConfig{
  62. RetryTimes: 10,
  63. HTTPTimeout: *httpTimeout,
  64. MaxRetryTime: time.Second * 5,
  65. MaxIdleConnections: 2000}
  66. return config
  67. }
  68. type CreateTableRequest struct {
  69. TableMeta *TableMeta
  70. TableOption *TableOption
  71. ReservedThroughput *ReservedThroughput
  72. StreamSpec *StreamSpecification
  73. IndexMetas []*IndexMeta
  74. }
  75. type CreateIndexRequest struct {
  76. MainTableName string
  77. IndexMeta *IndexMeta
  78. IncludeBaseData bool
  79. }
  80. type DeleteIndexRequest struct {
  81. MainTableName string
  82. IndexName string
  83. }
  84. type ResponseInfo struct {
  85. RequestId string
  86. }
  87. type CreateTableResponse struct {
  88. ResponseInfo
  89. }
  90. type CreateIndexResponse struct {
  91. ResponseInfo
  92. }
  93. type DeleteIndexResponse struct {
  94. ResponseInfo
  95. }
  96. type DeleteTableResponse struct {
  97. ResponseInfo
  98. }
  99. type TableMeta struct {
  100. TableName string
  101. SchemaEntry []*PrimaryKeySchema
  102. DefinedColumns []*DefinedColumnSchema
  103. }
  104. type PrimaryKeySchema struct {
  105. Name *string
  106. Type *PrimaryKeyType
  107. Option *PrimaryKeyOption
  108. }
  109. type PrimaryKey struct {
  110. PrimaryKeys []*PrimaryKeyColumn
  111. }
  112. type TableOption struct {
  113. TimeToAlive, MaxVersion int
  114. DeviationCellVersionInSec int64
  115. }
  116. type ReservedThroughput struct {
  117. Readcap, Writecap int
  118. }
  119. type ListTableResponse struct {
  120. TableNames []string
  121. ResponseInfo
  122. }
  123. type DeleteTableRequest struct {
  124. TableName string
  125. }
  126. type DescribeTableRequest struct {
  127. TableName string
  128. }
  129. type DescribeTableResponse struct {
  130. TableMeta *TableMeta
  131. TableOption *TableOption
  132. ReservedThroughput *ReservedThroughput
  133. StreamDetails *StreamDetails
  134. IndexMetas []*IndexMeta
  135. ResponseInfo
  136. }
  137. type UpdateTableRequest struct {
  138. TableName string
  139. TableOption *TableOption
  140. ReservedThroughput *ReservedThroughput
  141. StreamSpec *StreamSpecification
  142. }
  143. type UpdateTableResponse struct {
  144. TableOption *TableOption
  145. ReservedThroughput *ReservedThroughput
  146. StreamDetails *StreamDetails
  147. ResponseInfo
  148. }
  149. type ConsumedCapacityUnit struct {
  150. Read int32
  151. Write int32
  152. }
  153. type PutRowResponse struct {
  154. ConsumedCapacityUnit *ConsumedCapacityUnit
  155. PrimaryKey PrimaryKey
  156. ResponseInfo
  157. }
  158. type DeleteRowResponse struct {
  159. ConsumedCapacityUnit *ConsumedCapacityUnit
  160. ResponseInfo
  161. }
  162. type UpdateRowResponse struct {
  163. Columns []*AttributeColumn
  164. ConsumedCapacityUnit *ConsumedCapacityUnit
  165. ResponseInfo
  166. }
  167. type PrimaryKeyType int32
  168. const (
  169. PrimaryKeyType_INTEGER PrimaryKeyType = 1
  170. PrimaryKeyType_STRING PrimaryKeyType = 2
  171. PrimaryKeyType_BINARY PrimaryKeyType = 3
  172. )
  173. const (
  174. DefaultRetryInterval = 10
  175. MaxRetryInterval = 320
  176. )
  177. type PrimaryKeyOption int32
  178. const (
  179. NONE PrimaryKeyOption = 0
  180. AUTO_INCREMENT PrimaryKeyOption = 1
  181. MIN PrimaryKeyOption = 2
  182. MAX PrimaryKeyOption = 3
  183. )
  184. type PrimaryKeyColumn struct {
  185. ColumnName string
  186. Value interface{}
  187. PrimaryKeyOption PrimaryKeyOption
  188. }
  189. func (this *PrimaryKeyColumn) String() string {
  190. xs := make([]string, 0)
  191. xs = append(xs, fmt.Sprintf("\"Name\": \"%s\"", this.ColumnName))
  192. switch this.PrimaryKeyOption {
  193. case NONE:
  194. xs = append(xs, fmt.Sprintf("\"Value\": \"%s\"", this.Value))
  195. case MIN:
  196. xs = append(xs, "\"Value\": -inf")
  197. case MAX:
  198. xs = append(xs, "\"Value\": +inf")
  199. case AUTO_INCREMENT:
  200. xs = append(xs, "\"Value\": auto-incr")
  201. }
  202. return fmt.Sprintf("{%s}", strings.Join(xs, ", "))
  203. }
  204. type AttributeColumn struct {
  205. ColumnName string
  206. Value interface{}
  207. Timestamp int64
  208. }
  209. type TimeRange struct {
  210. Start int64
  211. End int64
  212. Specific int64
  213. }
  214. type ColumnToUpdate struct {
  215. ColumnName string
  216. Type byte
  217. Timestamp int64
  218. HasType bool
  219. HasTimestamp bool
  220. IgnoreValue bool
  221. Value interface{}
  222. }
  223. type RowExistenceExpectation int
  224. const (
  225. RowExistenceExpectation_IGNORE RowExistenceExpectation = 0
  226. RowExistenceExpectation_EXPECT_EXIST RowExistenceExpectation = 1
  227. RowExistenceExpectation_EXPECT_NOT_EXIST RowExistenceExpectation = 2
  228. )
  229. type ComparatorType int32
  230. const (
  231. CT_EQUAL ComparatorType = 1
  232. CT_NOT_EQUAL ComparatorType = 2
  233. CT_GREATER_THAN ComparatorType = 3
  234. CT_GREATER_EQUAL ComparatorType = 4
  235. CT_LESS_THAN ComparatorType = 5
  236. CT_LESS_EQUAL ComparatorType = 6
  237. )
  238. type LogicalOperator int32
  239. const (
  240. LO_NOT LogicalOperator = 1
  241. LO_AND LogicalOperator = 2
  242. LO_OR LogicalOperator = 3
  243. )
  244. type FilterType int32
  245. const (
  246. FT_SINGLE_COLUMN_VALUE FilterType = 1
  247. FT_COMPOSITE_COLUMN_VALUE FilterType = 2
  248. FT_COLUMN_PAGINATION FilterType = 3
  249. )
  250. type ColumnFilter interface {
  251. Serialize() []byte
  252. ToFilter() *otsprotocol.Filter
  253. }
  254. type VariantType int32
  255. const (
  256. Variant_INTEGER VariantType = 0;
  257. Variant_DOUBLE VariantType = 1;
  258. //VT_BOOLEAN = 2;
  259. Variant_STRING VariantType = 3;
  260. )
  261. type ValueTransferRule struct {
  262. Regex string
  263. Cast_type VariantType
  264. }
  265. type SingleColumnCondition struct {
  266. Comparator *ComparatorType
  267. ColumnName *string
  268. ColumnValue interface{} //[]byte
  269. FilterIfMissing bool
  270. LatestVersionOnly bool
  271. TransferRule *ValueTransferRule
  272. }
  273. type ReturnType int32
  274. const (
  275. ReturnType_RT_NONE ReturnType = 0
  276. ReturnType_RT_PK ReturnType = 1
  277. ReturnType_RT_AFTER_MODIFY ReturnType = 2
  278. )
  279. type PaginationFilter struct {
  280. Offset int32
  281. Limit int32
  282. }
  283. type CompositeColumnValueFilter struct {
  284. Operator LogicalOperator
  285. Filters []ColumnFilter
  286. }
  287. func (ccvfilter *CompositeColumnValueFilter) Serialize() []byte {
  288. result, _ := proto.Marshal(ccvfilter.ToFilter())
  289. return result
  290. }
  291. func (ccvfilter *CompositeColumnValueFilter) ToFilter() *otsprotocol.Filter {
  292. compositefilter := NewCompositeFilter(ccvfilter.Filters, ccvfilter.Operator)
  293. compositeFilterToBytes, _ := proto.Marshal(compositefilter)
  294. filter := new(otsprotocol.Filter)
  295. filter.Type = otsprotocol.FilterType_FT_COMPOSITE_COLUMN_VALUE.Enum()
  296. filter.Filter = compositeFilterToBytes
  297. return filter
  298. }
  299. func (ccvfilter *CompositeColumnValueFilter) AddFilter(filter ColumnFilter) {
  300. ccvfilter.Filters = append(ccvfilter.Filters, filter)
  301. }
  302. func (condition *SingleColumnCondition) ToFilter() *otsprotocol.Filter {
  303. singlefilter := NewSingleColumnValueFilter(condition)
  304. singleFilterToBytes, _ := proto.Marshal(singlefilter)
  305. filter := new(otsprotocol.Filter)
  306. filter.Type = otsprotocol.FilterType_FT_SINGLE_COLUMN_VALUE.Enum()
  307. filter.Filter = singleFilterToBytes
  308. return filter
  309. }
  310. func (condition *SingleColumnCondition) Serialize() []byte {
  311. result, _ := proto.Marshal(condition.ToFilter())
  312. return result
  313. }
  314. func (pageFilter *PaginationFilter) ToFilter() *otsprotocol.Filter {
  315. compositefilter := NewPaginationFilter(pageFilter)
  316. compositeFilterToBytes, _ := proto.Marshal(compositefilter)
  317. filter := new(otsprotocol.Filter)
  318. filter.Type = otsprotocol.FilterType_FT_COLUMN_PAGINATION.Enum()
  319. filter.Filter = compositeFilterToBytes
  320. return filter
  321. }
  322. func (pageFilter *PaginationFilter) Serialize() []byte {
  323. result, _ := proto.Marshal(pageFilter.ToFilter())
  324. return result
  325. }
  326. func NewTableOptionWithMaxVersion(maxVersion int) *TableOption {
  327. tableOption := new(TableOption)
  328. tableOption.TimeToAlive = -1
  329. tableOption.MaxVersion = maxVersion
  330. return tableOption
  331. }
  332. func NewTableOption(timeToAlive int, maxVersion int) *TableOption {
  333. tableOption := new(TableOption)
  334. tableOption.TimeToAlive = timeToAlive
  335. tableOption.MaxVersion = maxVersion
  336. return tableOption
  337. }
  338. type RowCondition struct {
  339. RowExistenceExpectation RowExistenceExpectation
  340. ColumnCondition ColumnFilter
  341. }
  342. type PutRowChange struct {
  343. TableName string
  344. PrimaryKey *PrimaryKey
  345. Columns []AttributeColumn
  346. Condition *RowCondition
  347. ReturnType ReturnType
  348. TransactionId *string
  349. }
  350. type PutRowRequest struct {
  351. PutRowChange *PutRowChange
  352. }
  353. type DeleteRowChange struct {
  354. TableName string
  355. PrimaryKey *PrimaryKey
  356. Condition *RowCondition
  357. TransactionId *string
  358. }
  359. type DeleteRowRequest struct {
  360. DeleteRowChange *DeleteRowChange
  361. }
  362. type SingleRowQueryCriteria struct {
  363. ColumnsToGet []string
  364. TableName string
  365. PrimaryKey *PrimaryKey
  366. MaxVersion int32
  367. TimeRange *TimeRange
  368. Filter ColumnFilter
  369. StartColumn *string
  370. EndColumn *string
  371. TransactionId *string
  372. }
  373. type UpdateRowChange struct {
  374. TableName string
  375. PrimaryKey *PrimaryKey
  376. Columns []ColumnToUpdate
  377. Condition *RowCondition
  378. TransactionId *string
  379. ReturnType ReturnType
  380. ColumnNamesToReturn []string
  381. }
  382. type UpdateRowRequest struct {
  383. UpdateRowChange *UpdateRowChange
  384. }
  385. func (rowQueryCriteria *SingleRowQueryCriteria) AddColumnToGet(columnName string) {
  386. rowQueryCriteria.ColumnsToGet = append(rowQueryCriteria.ColumnsToGet, columnName)
  387. }
  388. func (rowQueryCriteria *SingleRowQueryCriteria) SetStartColumn(columnName string) {
  389. rowQueryCriteria.StartColumn = &columnName
  390. }
  391. func (rowQueryCriteria *SingleRowQueryCriteria) SetEndtColumn(columnName string) {
  392. rowQueryCriteria.EndColumn = &columnName
  393. }
  394. func (rowQueryCriteria *SingleRowQueryCriteria) getColumnsToGet() []string {
  395. return rowQueryCriteria.ColumnsToGet
  396. }
  397. func (rowQueryCriteria *MultiRowQueryCriteria) AddColumnToGet(columnName string) {
  398. rowQueryCriteria.ColumnsToGet = append(rowQueryCriteria.ColumnsToGet, columnName)
  399. }
  400. func (rowQueryCriteria *RangeRowQueryCriteria) AddColumnToGet(columnName string) {
  401. rowQueryCriteria.ColumnsToGet = append(rowQueryCriteria.ColumnsToGet, columnName)
  402. }
  403. func (rowQueryCriteria *MultiRowQueryCriteria) AddRow(pk *PrimaryKey) {
  404. rowQueryCriteria.PrimaryKey = append(rowQueryCriteria.PrimaryKey, pk)
  405. }
  406. type GetRowRequest struct {
  407. SingleRowQueryCriteria *SingleRowQueryCriteria
  408. }
  409. type MultiRowQueryCriteria struct {
  410. PrimaryKey []*PrimaryKey
  411. ColumnsToGet []string
  412. TableName string
  413. MaxVersion int
  414. TimeRange *TimeRange
  415. Filter ColumnFilter
  416. StartColumn *string
  417. EndColumn *string
  418. }
  419. type BatchGetRowRequest struct {
  420. MultiRowQueryCriteria []*MultiRowQueryCriteria
  421. }
  422. type ColumnMap struct {
  423. Columns map[string][]*AttributeColumn
  424. columnsKey []string
  425. }
  426. type GetRowResponse struct {
  427. PrimaryKey PrimaryKey
  428. Columns []*AttributeColumn
  429. ConsumedCapacityUnit *ConsumedCapacityUnit
  430. columnMap *ColumnMap
  431. ResponseInfo
  432. }
  433. type Error struct {
  434. Code string
  435. Message string
  436. }
  437. type RowResult struct {
  438. TableName string
  439. IsSucceed bool
  440. Error Error
  441. PrimaryKey PrimaryKey
  442. Columns []*AttributeColumn
  443. ConsumedCapacityUnit *ConsumedCapacityUnit
  444. Index int32
  445. }
  446. type RowChange interface {
  447. Serialize() []byte
  448. getOperationType() otsprotocol.OperationType
  449. getCondition() *otsprotocol.Condition
  450. GetTableName() string
  451. }
  452. type BatchGetRowResponse struct {
  453. TableToRowsResult map[string][]RowResult
  454. ResponseInfo
  455. }
  456. type BatchWriteRowRequest struct {
  457. RowChangesGroupByTable map[string][]RowChange
  458. }
  459. type BatchWriteRowResponse struct {
  460. TableToRowsResult map[string][]RowResult
  461. ResponseInfo
  462. }
  463. type Direction int32
  464. const (
  465. FORWARD Direction = 0
  466. BACKWARD Direction = 1
  467. )
  468. type RangeRowQueryCriteria struct {
  469. TableName string
  470. StartPrimaryKey *PrimaryKey
  471. EndPrimaryKey *PrimaryKey
  472. ColumnsToGet []string
  473. MaxVersion int32
  474. TimeRange *TimeRange
  475. Filter ColumnFilter
  476. Direction Direction
  477. Limit int32
  478. StartColumn *string
  479. EndColumn *string
  480. TransactionId *string
  481. }
  482. type GetRangeRequest struct {
  483. RangeRowQueryCriteria *RangeRowQueryCriteria
  484. }
  485. type Row struct {
  486. PrimaryKey *PrimaryKey
  487. Columns []*AttributeColumn
  488. }
  489. type GetRangeResponse struct {
  490. Rows []*Row
  491. ConsumedCapacityUnit *ConsumedCapacityUnit
  492. NextStartPrimaryKey *PrimaryKey
  493. ResponseInfo
  494. }
  495. type ListStreamRequest struct {
  496. TableName *string
  497. }
  498. type Stream struct {
  499. Id *StreamId
  500. TableName *string
  501. CreationTime int64
  502. }
  503. type ListStreamResponse struct {
  504. Streams []Stream
  505. ResponseInfo
  506. }
  507. type StreamSpecification struct {
  508. EnableStream bool
  509. ExpirationTime int32 // must be positive. in hours
  510. }
  511. type StreamDetails struct {
  512. EnableStream bool
  513. StreamId *StreamId // nil when stream is disabled.
  514. ExpirationTime int32 // in hours
  515. LastEnableTime int64 // the last time stream is enabled, in usec
  516. }
  517. type DescribeStreamRequest struct {
  518. StreamId *StreamId // required
  519. InclusiveStartShardId *ShardId // optional
  520. ShardLimit *int32 // optional
  521. }
  522. type DescribeStreamResponse struct {
  523. StreamId *StreamId // required
  524. ExpirationTime int32 // in hours
  525. TableName *string // required
  526. CreationTime int64 // in usec
  527. Status StreamStatus // required
  528. Shards []*StreamShard
  529. NextShardId *ShardId // optional. nil means "no more shards"
  530. ResponseInfo
  531. }
  532. type GetShardIteratorRequest struct {
  533. StreamId *StreamId // required
  534. ShardId *ShardId // required
  535. Timestamp *int64
  536. Token *string
  537. }
  538. type GetShardIteratorResponse struct {
  539. ShardIterator *ShardIterator // required
  540. Token *string
  541. ResponseInfo
  542. }
  543. type GetStreamRecordRequest struct {
  544. ShardIterator *ShardIterator // required
  545. Limit *int32 // optional. max records which will reside in response
  546. }
  547. type GetStreamRecordResponse struct {
  548. Records []*StreamRecord
  549. NextShardIterator *ShardIterator // optional. an indicator to be used to read more records in this shard
  550. ResponseInfo
  551. }
  552. type ComputeSplitPointsBySizeRequest struct {
  553. TableName string
  554. SplitSize int64
  555. }
  556. type ComputeSplitPointsBySizeResponse struct {
  557. SchemaEntry []*PrimaryKeySchema
  558. Splits []*Split
  559. ResponseInfo
  560. }
  561. type Split struct {
  562. LowerBound *PrimaryKey
  563. UpperBound *PrimaryKey
  564. Location string
  565. }
  566. type StreamId string
  567. type ShardId string
  568. type ShardIterator string
  569. type StreamStatus int
  570. const (
  571. SS_Enabling StreamStatus = iota
  572. SS_Active
  573. )
  574. /*
  575. * Shards are possibly splitted into two or merged from two.
  576. * After splitting, both newly generated shards have the same FatherShard.
  577. * After merging, the newly generated shard have both FatherShard and MotherShard.
  578. */
  579. type StreamShard struct {
  580. SelfShard *ShardId // required
  581. FatherShard *ShardId // optional
  582. MotherShard *ShardId // optional
  583. }
  584. type StreamRecord struct {
  585. Type ActionType
  586. Info *RecordSequenceInfo // required
  587. PrimaryKey *PrimaryKey // required
  588. Columns []*RecordColumn
  589. }
  590. func (this *StreamRecord) String() string {
  591. return fmt.Sprintf(
  592. "{\"Type\":%s, \"PrimaryKey\":%s, \"Info\":%s, \"Columns\":%s}",
  593. this.Type,
  594. *this.PrimaryKey,
  595. this.Info,
  596. this.Columns)
  597. }
  598. type ActionType int
  599. const (
  600. AT_Put ActionType = iota
  601. AT_Update
  602. AT_Delete
  603. )
  604. func (this ActionType) String() string {
  605. switch this {
  606. case AT_Put:
  607. return "\"PutRow\""
  608. case AT_Update:
  609. return "\"UpdateRow\""
  610. case AT_Delete:
  611. return "\"DeleteRow\""
  612. default:
  613. panic(fmt.Sprintf("unknown action type: %d", int(this)))
  614. }
  615. }
  616. type RecordSequenceInfo struct {
  617. Epoch int32
  618. Timestamp int64
  619. RowIndex int32
  620. }
  621. func (this *RecordSequenceInfo) String() string {
  622. return fmt.Sprintf(
  623. "{\"Epoch\":%d, \"Timestamp\": %d, \"RowIndex\": %d}",
  624. this.Epoch,
  625. this.Timestamp,
  626. this.RowIndex)
  627. }
  628. type RecordColumn struct {
  629. Type RecordColumnType
  630. Name *string // required
  631. Value interface{} // optional. present when Type is RCT_Put
  632. Timestamp *int64 // optional, in msec. present when Type is RCT_Put or RCT_DeleteOneVersion
  633. }
  634. func (this *RecordColumn) String() string {
  635. xs := make([]string, 0)
  636. xs = append(xs, fmt.Sprintf("\"Name\":%s", strconv.Quote(*this.Name)))
  637. switch this.Type {
  638. case RCT_DeleteAllVersions:
  639. xs = append(xs, "\"Type\":\"DeleteAllVersions\"")
  640. case RCT_DeleteOneVersion:
  641. xs = append(xs, "\"Type\":\"DeleteOneVersion\"")
  642. xs = append(xs, fmt.Sprintf("\"Timestamp\":%d", *this.Timestamp))
  643. case RCT_Put:
  644. xs = append(xs, "\"Type\":\"Put\"")
  645. xs = append(xs, fmt.Sprintf("\"Timestamp\":%d", *this.Timestamp))
  646. xs = append(xs, fmt.Sprintf("\"Value\":%s", this.Value))
  647. }
  648. return fmt.Sprintf("{%s}", strings.Join(xs, ", "))
  649. }
  650. type RecordColumnType int
  651. const (
  652. RCT_Put RecordColumnType = iota
  653. RCT_DeleteOneVersion
  654. RCT_DeleteAllVersions
  655. )
  656. type IndexMeta struct {
  657. IndexName string
  658. Primarykey []string
  659. DefinedColumns []string
  660. IndexType IndexType
  661. }
  662. type DefinedColumnSchema struct {
  663. Name string
  664. ColumnType DefinedColumnType
  665. }
  666. type IndexType int32
  667. const (
  668. IT_GLOBAL_INDEX IndexType = 1
  669. IT_LOCAL_INDEX IndexType = 2
  670. )
  671. type DefinedColumnType int32
  672. const (
  673. /**
  674. * 64位整数。
  675. */
  676. DefinedColumn_INTEGER DefinedColumnType = 1
  677. /**
  678. * 浮点数。
  679. */
  680. DefinedColumn_DOUBLE DefinedColumnType = 2
  681. /**
  682. * 布尔值。
  683. */
  684. DefinedColumn_BOOLEAN DefinedColumnType = 3
  685. /**
  686. * 字符串。
  687. */
  688. DefinedColumn_STRING DefinedColumnType = 4
  689. /**
  690. * BINARY。
  691. */
  692. DefinedColumn_BINARY DefinedColumnType = 5
  693. )
  694. type StartLocalTransactionRequest struct {
  695. PrimaryKey *PrimaryKey
  696. TableName string
  697. }
  698. type StartLocalTransactionResponse struct {
  699. TransactionId *string
  700. ResponseInfo
  701. }
  702. type CommitTransactionRequest struct {
  703. TransactionId *string
  704. }
  705. type CommitTransactionResponse struct {
  706. ResponseInfo
  707. }
  708. type AbortTransactionRequest struct {
  709. TransactionId *string
  710. }
  711. type AbortTransactionResponse struct {
  712. ResponseInfo
  713. }