Skip to content

Commit

Permalink
Bump version v1.7.8 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaozzz authored Jul 26, 2023
1 parent a4afe70 commit ef88543
Show file tree
Hide file tree
Showing 25 changed files with 3,095 additions and 550 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ require (
github.com/stretchr/testify v1.7.0
go.uber.org/atomic v1.9.0
go.uber.org/zap v1.19.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand Down Expand Up @@ -66,8 +68,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
67 changes: 67 additions & 0 deletions sample/SQLOperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ func SQLQuerySample(client *tablestore.TableStoreClient) {
SQLCreateTableSample(client)
SQLDescribeTableSample(client)
SQLSelectSample(client)
SQLSelectTimeTypeSample(client)
}

func SQLShowTablesSample(client *tablestore.TableStoreClient) {
Expand Down Expand Up @@ -131,3 +132,69 @@ func SQLSelectSample(client *tablestore.TableStoreClient) {
}
println("END SQLSelectSample")
}

func SQLSelectTimeTypeSample(client *tablestore.TableStoreClient) {
println("BEGIN SQLSelectSample")
request := new(tablestore.SQLQueryRequest)
request.Query = "select from_unixtime(1668585138.995),timediff(from_unixtime(1668585138.995),from_unixtime(1668585013.712)),date(from_unixtime(1668585138.995))"
response, err := client.SQLQuery(request)
if err != nil {
println("[Info]: select failed with error: ", err.Error())
return
}

resultSet := response.ResultSet
columns := resultSet.Columns()
for resultSet.HasNext() {
row := resultSet.Next()
for i := 0; i < len(columns); i++ {
name := columns[i].Name
println("columnName: ", name)
isnull, err := row.IsNull(i)
if err != nil {
println("[INFO:] get column error, name: ", name, ", error: ", err.Error())
continue
}
if isnull {
println("[INFO]: column is SQL NULL, name: ", name)
continue
}
switch columns[i].Type {
case tablestore.ColumnType_DATETIME:
time, err := row.GetDateTime(i)
if err != nil {
println("[INFO:] get column error, name: ", name, ", error: ", err.Error())
}
println(time.String())
time, err = row.GetDateTimeByName("from_unixtime(1668585138.995)")
if err != nil {
println("[INFO:] get column error, name: ", name, ", error: ", err.Error())
}
println(time.String())
case tablestore.ColumnType_TIME:
duration, err := row.GetTime(i)
if err != nil {
println("[INFO:] get column error, name: ", name, ", error: ", err.Error())
}
println(duration.String())
duration, err = row.GetTimeByName("timediff(from_unixtime(1668585138.995),from_unixtime(1668585013.712))")
if err != nil {
println("[INFO:] get column error, name: ", name, ", error: ", err.Error())
}
println(duration.String())
case tablestore.ColumnType_DATE:
date, err := row.GetDate(i)
if err != nil {
println("[INFO:] get column error, name: ", name, ", error: ", err.Error())
}
println(date.String())
date, err = row.GetDateByName("date(from_unixtime(1668585138.995))")
if err != nil {
println("[INFO:] get column error, name: ", name, ", error: ", err.Error())
}
println(date.String())
}
}
}
println("END SQLSelectSample")
}
64 changes: 62 additions & 2 deletions sample/TimeseriesOperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"time"

"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
"github.com/golang/protobuf/proto"
)

/**
/*
CreateTimeseriesTableSample 创建一个时序表,其中表名为:timeseriesTableName,TTL为:timetolive。
*/
func CreateTimeseriesTableSample(client *tablestore.TimeseriesClient, timeseriesTableName string, timetoLive int64) {
Expand Down Expand Up @@ -65,7 +66,7 @@ func ListTimeseriesTableSample(client *tablestore.TimeseriesClient) {
fmt.Println("[Info]: ListTimeseriesTableSample finished !")
}

/**
/*
DeleteTimeseriesTableSample 删除实例中表名为timeseriesTableName的时序表
*/
func DeleteTimeseriesTableSample(client *tablestore.TimeseriesClient, timeseriesTableName string) {
Expand Down Expand Up @@ -274,3 +275,62 @@ func UpdateTimeseriesMetaSample(tsClient *tablestore.TimeseriesClient, timeserie

fmt.Println("[Info]: UpdateTimeseriesMetaSample finished !")
}

// CreateTimeseriesTableWithAnalyticalStoreSample 创建时序表,并且创建分析存储
func CreateTimeseriesTableWithAnalyticalStoreSample(tsClient *tablestore.TimeseriesClient, timeseriesTableName string) {
fmt.Println("[Info]: Begin to create timeseries table with analytical store !")

// 创建时序表
meta := tablestore.NewTimeseriesTableMeta(timeseriesTableName)
meta.SetTimeseriesTableOptions(tablestore.NewTimeseriesTableOptions(-1))
createTimeseriesTableRequest := tablestore.NewCreateTimeseriesTableRequest()
createTimeseriesTableRequest.SetTimeseriesTableMeta(meta)
createTimeseriesTableRequest.SetAnalyticalStores([]*tablestore.TimeseriesAnalyticalStore{{
StoreName: "custom_analytical_store", // 分析存储名称
TimeToLive: proto.Int32(-1), // 分析存储数据的过期时间,单位为秒,-1表示永不过期
}})
_, err := tsClient.CreateTimeseriesTable(createTimeseriesTableRequest)
if err != nil {
fmt.Println("[Error]: Create timeseries table failed with error: ", err)
return
}

fmt.Println("[Info]: Create timeseries table with analytical store succeed !")
}

// DescribeTimeseriesAnalyticalStoresSample 列出时序表下面所有的分析存储,并且打印出分析存储的同步状态和存储大小
func DescribeTimeseriesAnalyticalStoresSample(tsClient *tablestore.TimeseriesClient, timeseriesTableName string) {
fmt.Println("[Info]: Begin to describe timeseries analytical stores !")

describeTimeseriesTableRequest := tablestore.NewDescribeTimeseriesTableRequset(timeseriesTableName)
describeTimeseriesTableResponse, err := tsClient.DescribeTimeseriesTable(describeTimeseriesTableRequest)
if err != nil {
fmt.Println("[Error]: Describe timeseries table failed with error: ", err)
return
}

analyticalStores := describeTimeseriesTableResponse.GetAnalyticalStores()
for _, analyticalStore := range analyticalStores {
describeAnalyticalStoreRequest := tablestore.NewDescribeTimeseriesAnalyticalStoreRequest(timeseriesTableName, analyticalStore.StoreName)
describeAnalyticalStoreResponse, err := tsClient.DescribeTimeseriesAnalyticalStore(describeAnalyticalStoreRequest)
if err != nil {
fmt.Println("[Error]: Describe analytical store failed with error: ", err)
return
}
fmt.Println(" [Info]: StoreName: ", describeAnalyticalStoreResponse.AnalyticalStore.StoreName)
fmt.Println(" [Info]: TimeToLive: ", describeAnalyticalStoreResponse.AnalyticalStore.TimeToLive)
fmt.Println(" [Info]: SyncOption: ", describeAnalyticalStoreResponse.AnalyticalStore.SyncOption)
syncStat := describeAnalyticalStoreResponse.SyncStat
if syncStat != nil {
fmt.Println(" [Info]: CurrentSyncTimestamp: ", syncStat.CurrentSyncTimestamp)
fmt.Println(" [Info]: SyncPhase: ", syncStat.SyncPhase)
}
storageSize := describeAnalyticalStoreResponse.StorageSize
if storageSize != nil {
fmt.Println(" [Info]: Size: ", storageSize.Size)
fmt.Println(" [Info]: Timestamp: ", storageSize.Timestamp)
}
}

fmt.Println("[Info]: DescribeTimeseriesAnalyticalStoresSample finished !")
}
Loading

0 comments on commit ef88543

Please sign in to comment.