Skip to content

Commit

Permalink
gofmt codes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielxiaoran committed Jan 24, 2018
1 parent 7d1fafe commit 4f31f7c
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 443 deletions.
11 changes: 6 additions & 5 deletions sample.go
@@ -1,8 +1,9 @@
package main

import (
"os"
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
"github.com/aliyun/aliyun-tablestore-go-sdk/sample"
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
"os"
)

func main() {
Expand All @@ -22,14 +23,14 @@ func main() {
sample.DescribeTableSample(client, "sampletable")

// Single row operation
sample.PutRowSample(client,"sampletable")
sample.PutRowSample(client, "sampletable")
sample.UpdateRowSample(client, "sampletable")
sample.GetRowSample(client, "sampletable")
sample.DeleteRowSample(client, "sampletable")
sample.PutRowWithKeyAutoIncrementSample(client)

// Multi row operation
sample.BatchWriteRowSample(client,"sampletable")
sample.BatchWriteRowSample(client, "sampletable")
sample.BatchGetRowSample(client, "sampletable")
sample.GetRangeSample(client, "sampletable")

Expand All @@ -39,4 +40,4 @@ func main() {
// computeSplitpoint
sample.ComputeSplitPointsBySize(client, "sampletable")

}
}
11 changes: 5 additions & 6 deletions sample/MultipleRowOperation.go
Expand Up @@ -54,7 +54,6 @@ func BatchGetRowSample(client *tablestore.TableStoreClient, tableName string) {
mqCriteria.TableName = tableName
batchGetReq.MultiRowQueryCriteria = append(batchGetReq.MultiRowQueryCriteria, mqCriteria)


/*condition := tablestore.NewSingleColumnCondition("col1", tablestore.CT_GREATER_THAN, int64(0))
mqCriteria.Filter = condition*/

Expand All @@ -63,7 +62,7 @@ func BatchGetRowSample(client *tablestore.TableStoreClient, tableName string) {
if err != nil {
fmt.Println("batachget failed with error:", err)
} else {
for _, row := range (batchGetResponse.TableToRowsResult[mqCriteria.TableName]) {
for _, row := range batchGetResponse.TableToRowsResult[mqCriteria.TableName] {
if row.PrimaryKey.PrimaryKeys != nil {
fmt.Println("get row with key", row.PrimaryKey.PrimaryKeys[0].Value, row.PrimaryKey.PrimaryKeys[1].Value, row.PrimaryKey.PrimaryKeys[2].Value)
} else {
Expand Down Expand Up @@ -98,13 +97,13 @@ func GetRangeSample(client *tablestore.TableStoreClient, tableName string) {

getRangeResp, err := client.GetRange(getRangeRequest)

fmt.Println("get range result is " ,getRangeResp)
fmt.Println("get range result is ", getRangeResp)

for ; ; {
for {
if err != nil {
fmt.Println("get range failed with error:", err)
}
if (len(getRangeResp.Rows) > 0) {
if len(getRangeResp.Rows) > 0 {
for _, row := range getRangeResp.Rows {
fmt.Println("range get row with key", row.PrimaryKey.PrimaryKeys[0].Value, row.PrimaryKey.PrimaryKeys[1].Value, row.PrimaryKey.PrimaryKeys[2].Value)
}
Expand All @@ -123,4 +122,4 @@ func GetRangeSample(client *tablestore.TableStoreClient, tableName string) {
}
fmt.Println("putrow finished")

}
}
9 changes: 4 additions & 5 deletions sample/SingleRowOperation.go
Expand Up @@ -33,7 +33,7 @@ func PutRowSample(client *tablestore.TableStoreClient, tableName string) {
func GetRowSample(client *tablestore.TableStoreClient, tableName string) {
fmt.Println("begin to get row")
getRowRequest := new(tablestore.GetRowRequest)
criteria := new(tablestore.SingleRowQueryCriteria);
criteria := new(tablestore.SingleRowQueryCriteria)
putPk := new(tablestore.PrimaryKey)
putPk.AddPrimaryKeyColumn("pk1", "pk1value1")
putPk.AddPrimaryKeyColumn("pk2", int64(2))
Expand All @@ -47,11 +47,11 @@ func GetRowSample(client *tablestore.TableStoreClient, tableName string) {

colmap := getResp.GetColumnMap()

fmt.Println("length is ",len(colmap.Columns))
fmt.Println("length is ", len(colmap.Columns))
if err != nil {
fmt.Println("getrow failed with error:", err)
} else {
fmt.Println("get row col0 result is ",getResp.Columns[0].ColumnName, getResp.Columns[0].Value,)
fmt.Println("get row col0 result is ", getResp.Columns[0].ColumnName, getResp.Columns[0].Value)
}
}

Expand All @@ -70,7 +70,6 @@ func DeleteRowSample(client *tablestore.TableStoreClient, tableName string) {
deleteRowReq.DeleteRowChange.SetColumnCondition(clCondition1)
_, err := client.DeleteRow(deleteRowReq)


if err != nil {
fmt.Println("getrow failed with error:", err)
} else {
Expand Down Expand Up @@ -123,4 +122,4 @@ func PutRowWithKeyAutoIncrementSample(client *tablestore.TableStoreClient) {
} else {
fmt.Println("put row finished")
}
}
}
25 changes: 12 additions & 13 deletions sample/StreamOperation.go
Expand Up @@ -3,8 +3,8 @@ package sample
import (
"fmt"
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
"time"
"strconv"
"time"
)

func GetStreamRecordSample(client *tablestore.TableStoreClient, tableName string) {
Expand All @@ -30,32 +30,31 @@ func GetStreamRecordSample(client *tablestore.TableStoreClient, tableName string
createtableRequest.StreamSpec = &tablestore.StreamSpecification{EnableStream: true, ExpirationTime: 24}

_, err := client.CreateTable(createtableRequest)
if (err != nil) {
if err != nil {
fmt.Println("Failed to create table with error:", err)
} else {
fmt.Println("Create table finished")
}


time.Sleep(time.Millisecond * 20)

for j := 0; j < 300 ; j++ {
for j := 0; j < 300; j++ {

go func () {
for i := 0; i < 1000 ; i++ {
go func() {
for i := 0; i < 1000; i++ {
req := tablestore.PutRowRequest{}
rowChange := tablestore.PutRowChange{}
rowChange.TableName = tableName
pk := tablestore.PrimaryKey{}
pk.AddPrimaryKeyColumn("pk1", "01f3")
pk.AddPrimaryKeyColumn("pk2", "000001")
pk.AddPrimaryKeyColumn("pk3", "001")
val := 1495246210 + i * 100
val := 1495246210 + i*100
pk.AddPrimaryKeyColumn("pk4", int64(val))

rowChange.PrimaryKey = &pk

val1 := float64(120.1516525097) + float64(0.0000000001) * float64(i)
val1 := float64(120.1516525097) + float64(0.0000000001)*float64(i)

rowChange.AddColumn("longitude", strconv.FormatFloat(val1, 'g', 1, 64))
rowChange.AddColumn("latitude", "30.2583277934")
Expand All @@ -64,8 +63,8 @@ func GetStreamRecordSample(client *tablestore.TableStoreClient, tableName string
rowChange.AddColumn("speed", "25")
rowChange.AddColumn("wind_speed", "2")
rowChange.AddColumn("temperature", "20")
distance := 8000 + i;
rowChange.AddColumn("distance", strconv.Itoa(distance))
distance := 8000 + i
rowChange.AddColumn("distance", strconv.Itoa(distance))

rowChange.SetCondition(tablestore.RowExistenceExpectation_IGNORE)
req.PutRowChange = &rowChange
Expand All @@ -75,7 +74,7 @@ func GetStreamRecordSample(client *tablestore.TableStoreClient, tableName string
fmt.Print(err)
}
}
} ()
}()

}

Expand All @@ -92,7 +91,7 @@ func GetStreamRecordSample(client *tablestore.TableStoreClient, tableName string

resp3, err := client.GetShardIterator(&tablestore.GetShardIteratorRequest{
StreamId: streamId,
ShardId: shardId})
ShardId: shardId})

iter := resp3.ShardIterator

Expand Down Expand Up @@ -124,4 +123,4 @@ func GetStreamRecordSample(client *tablestore.TableStoreClient, tableName string
iter = nextIter
}

}
}
12 changes: 6 additions & 6 deletions sample/TableOperation.go
Expand Up @@ -25,7 +25,7 @@ func CreateTableSample(client *tablestore.TableStoreClient, tableName string) {
createtableRequest.ReservedThroughput = reservedThroughput

_, err := client.CreateTable(createtableRequest)
if (err != nil) {
if err != nil {
fmt.Println("Failed to create table with error:", err)
} else {
fmt.Println("Create table finished")
Expand Down Expand Up @@ -62,7 +62,7 @@ func DeleteTableSample(client *tablestore.TableStoreClient) {
deleteReq := new(tablestore.DeleteTableRequest)
deleteReq.TableName = tableName
_, err := client.DeleteTable(deleteReq)
if (err != nil) {
if err != nil {
fmt.Println("Failed to delete table with error:", err)
} else {
fmt.Println("Delete table finished")
Expand All @@ -76,7 +76,7 @@ func ListTableSample(client *tablestore.TableStoreClient) {
fmt.Println("Failed to list table")
} else {
fmt.Println("List table result is")
for _, table := range (listtables.TableNames) {
for _, table := range listtables.TableNames {
fmt.Println("TableName: ", table)
}
}
Expand All @@ -92,7 +92,7 @@ func UpdateTableSample(client *tablestore.TableStoreClient, tableName string) {

_, err := client.UpdateTable(updateTableReq)

if (err != nil) {
if err != nil {
fmt.Println("failed to update table with error:", err)
} else {
fmt.Println("update finished")
Expand All @@ -112,14 +112,14 @@ func DescribeTableSample(client *tablestore.TableStoreClient, tableName string)
}
}

func ComputeSplitPointsBySize(client *tablestore.TableStoreClient, tableName string){
func ComputeSplitPointsBySize(client *tablestore.TableStoreClient, tableName string) {
req := &tablestore.ComputeSplitPointsBySizeRequest{TableName: tableName, SplitSize: int64(1)}
va, err := client.ComputeSplitPointsBySize(req)
if err != nil {
fmt.Println(err)
}

for _, val := range (va.Splits) {
for _, val := range va.Splits {
fmt.Println(val.Location)
fmt.Println(*val.LowerBound)
fmt.Println(*val.UpperBound)
Expand Down

0 comments on commit 4f31f7c

Please sign in to comment.