From a3c25a47a79d1a6a6a4bbade35eb0ab8f3ae4c40 Mon Sep 17 00:00:00 2001 From: YilunZhang39 Date: Tue, 5 Nov 2024 17:31:24 +0800 Subject: [PATCH] release 3.00.0.2 --- README.md | 18 +- api/client.go | 4 +- api/database.go | 2 +- api/patitioned_table_appender.go | 4 +- api/patitioned_table_appender_test.go | 2 +- api/pool.go | 7 +- api/pool_test.go | 2 +- api/table.go | 2 +- api/table_appender.go | 4 +- api/table_appender_test.go | 4 +- api/task.go | 2 +- api/task_test.go | 2 +- api/utils.go | 6 + dialer/behavior.go | 4 +- dialer/dialer.go | 17 +- dialer/dialer_test.go | 2 +- dialer/node.go | 2 +- dialer/request.go | 4 +- dialer/response.go | 6 +- dialer/util.go | 4 +- domain/domain.go | 2 +- domain/domain_test.go | 2 +- domain/hash_domain.go | 2 +- domain/hash_domain_test.go | 2 +- domain/list_domain.go | 2 +- domain/list_domain_test.go | 2 +- domain/range_domain.go | 2 +- domain/range_domain_test.go | 2 +- domain/value_domain.go | 2 +- domain/value_domain_test.go | 2 +- example/apis/account.go | 2 +- example/apis/database.go | 2 +- example/apis/pool.go | 8 +- example/apis/table.go | 2 +- example/example.go | 8 +- example/mtw/mtw.go | 10 +- example/script/function.go | 6 +- example/script/script.go | 6 +- example/streaming_test/streaming.go | 12 +- go.mod | 3 +- go.sum | 6 - model/chart.go | 2 +- model/chart_test.go | 2 +- model/dataform.go | 8 +- model/dataform_test.go | 2 +- model/datatype.go | 2 +- model/datatype_list.go | 2 +- model/datatype_list_test.go | 2 +- model/dictionary.go | 2 +- model/dictionary_test.go | 2 +- model/io.go | 2 +- model/io_test.go | 2 +- model/matrix.go | 2 +- model/matrix_test.go | 2 +- model/pair.go | 2 +- model/pair_test.go | 2 +- model/parse_dataform.go | 4 +- model/parse_dataform_test.go | 2 +- model/parse_datatype.go | 2 +- model/parse_datatype_test.go | 2 +- model/render_datatype.go | 2 +- model/scalar.go | 2 +- model/scalar_test.go | 2 +- model/set.go | 2 +- model/set_test.go | 2 +- model/symbol_base_collecttion.go | 2 +- model/table.go | 2 +- model/table_test.go | 2 +- model/util.go | 2 +- model/util_test.go | 2 +- model/vector.go | 17 +- model/vector_test.go | 2 +- multigoroutinetable/multi_goroutine_table.go | 8 +- multigoroutinetable/queue.go | 2 +- multigoroutinetable/writer_goroutine.go | 4 +- streaming/basic_message.go | 9 +- streaming/basic_message_test.go | 2 +- streaming/deserializer.go | 12 +- streaming/goroutine_client_test.go | 136 +- streaming/goroutine_pooled_client_test.go | 110 +- streaming/handler_looper.go | 35 +- streaming/message_parser.go | 19 +- streaming/polling_client_test.go | 108 +- streaming/stream_deserializer.go | 14 +- streaming/stream_deserializer_test.go | 174 +- streaming/subscriber.go | 20 +- streaming/util.go | 12 +- test/basicTypeTest/basicChart_test.go | 8 +- test/basicTypeTest/basicDictionary_test.go | 10 +- test/basicTypeTest/basicMatrix_test.go | 8 +- test/basicTypeTest/basicPair_test.go | 12 +- test/basicTypeTest/basicScalar_test.go | 19 +- test/basicTypeTest/basicSet_test.go | 6 +- test/basicTypeTest/basicTable_test.go | 14 +- test/basicTypeTest/basicVector_test.go | 6 +- test/connectionPool_test.go | 83 +- test/createDatabase_test.go | 541 ++---- test/dbConnection_test.go | 152 +- test/dfsTable_test.go | 325 ++-- test/dropPartition_tabletMultiple_test.go | 472 +++-- test/dropPartition_tabletSingle_test.go | 536 +++--- test/existsDatabase_test.go | 161 +- test/existsTable_test.go | 199 +-- test/extras/basicChart_test.go | 6 +- test/extras/basicDataTypeList_test.go | 2 +- test/extras/basicDataType_test.go | 4 +- test/extras/basicDataform_test.go | 4 +- test/extras/basicDictionary_test.go | 4 +- test/extras/basicMatrix_test.go | 2 +- test/extras/basicTable_test.go | 4 +- test/extras/basicVector_test.go | 2 +- test/loadTableBySQL_test.go | 59 +- test/loadTable_test.go | 193 +- test/loadText_test.go | 11 +- test/multigoroutinetable_test.go | 1581 ++++++----------- test/newTableFromRawData_test.go | 6 +- test/newTableFromStruct_test.go | 6 +- test/ploadText_test.go | 6 +- test/run_function_test.go | 6 +- test/saveTable_test.go | 6 +- test/saveText_test.go | 6 +- test/sql_test.go | 6 +- .../streaming/goroutineClient_reverse_test.go | 10 +- test/streaming/goroutineClient_test.go | 8 +- .../goroutinePooledClient_reverse_test.go | 10 +- test/streaming/goroutinePooledClient_test.go | 8 +- test/streaming/pollingClient_reverse_test.go | 14 +- test/streaming/pollingClient_test.go | 8 +- test/streaming/util.go | 8 +- test/table_test.go | 6 +- test/undef_test.go | 6 +- test/util.go | 6 +- 132 files changed, 2312 insertions(+), 3171 deletions(-) diff --git a/README.md b/README.md index 8ddc06d..a7b6561 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

DolphinDB Go API

-[![GitHub release](https://img.shields.io/github/release/dolphindb/api-go.svg?style=flat-square)](https://github.com/dolphindb/api-go/releases/latest) -[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?style=flat-square&logo=go&logoColor=white)](https://pkg.go.dev/github.com/dolphindb/api-go) +[![GitHub release](https://img.shields.io/github/release/dolphindb/api-go.svg?style=flat-square)](https://github.com/dolphindb/api-go/v3/releases/latest) +[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?style=flat-square&logo=go&logoColor=white)](https://pkg.go.dev/github.com/dolphindb/api-go/v3) 欢迎使用 DolphinDB Go API。您可以使用 Go API 连接 DolphinDB 数据库,进行建库建表,以及读取、写入数据等操作。 @@ -172,7 +172,7 @@ Go API 需要运行在 Go 1.15 或以上版本的环境。注意,Go API 只支 使用 `go get` 下载安装 `Go API`。 ```sh -go get -u github.com/dolphindb/api-go +go get -u github.com/dolphindb/api-go/v3 ``` ## 3. DolphinDB 基本用法 @@ -196,7 +196,7 @@ package main import ( "context" - "github.com/dolphindb/api-go/api" + "github.com/dolphindb/api-go/v3/api" ) func main() { @@ -256,7 +256,7 @@ package main import ( "context" - "github.com/dolphindb/api-go/api" + "github.com/dolphindb/api-go/v3/api" ) func main() { @@ -287,7 +287,7 @@ package main import ( "context" - "github.com/dolphindb/api-go/api" + "github.com/dolphindb/api-go/v3/api" ) func main() { @@ -346,7 +346,7 @@ package main import ( "fmt" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // new a bool datatype variable @@ -552,8 +552,8 @@ import ( "context" "fmt" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" ) func main() { diff --git a/api/client.go b/api/client.go index 2a2f499..b6ef6f4 100644 --- a/api/client.go +++ b/api/client.go @@ -5,8 +5,8 @@ import ( "fmt" "strings" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/model" ) // DolphinDB interface declares functions to communicate with the dolphindb server. diff --git a/api/database.go b/api/database.go index 1b686f3..3a63d56 100644 --- a/api/database.go +++ b/api/database.go @@ -3,7 +3,7 @@ package api import ( "fmt" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // Database is used to call table api based on the name of db. diff --git a/api/patitioned_table_appender.go b/api/patitioned_table_appender.go index f9477e6..4e8a06f 100644 --- a/api/patitioned_table_appender.go +++ b/api/patitioned_table_appender.go @@ -5,8 +5,8 @@ import ( "fmt" "strings" - "github.com/dolphindb/api-go/domain" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/domain" + "github.com/dolphindb/api-go/v3/model" ) // PartitionedTableAppender is used to append tables into a partitioned table. diff --git a/api/patitioned_table_appender_test.go b/api/patitioned_table_appender_test.go index 1a0e9de..dd607da 100644 --- a/api/patitioned_table_appender_test.go +++ b/api/patitioned_table_appender_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/api/pool.go b/api/pool.go index f2e15ff..474feee 100644 --- a/api/pool.go +++ b/api/pool.go @@ -8,8 +8,8 @@ import ( "sync" "time" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/model" ) // DBConnectionPool is the client which helps you to handle tasks with connections. @@ -20,7 +20,7 @@ type DBConnectionPool struct { loadBalanceAddresses []string connections chan dialer.Conn - timeout time.Duration + timeout time.Duration } // PoolOption helps you to configure DBConnectionPool by calling NewDBConnectionPool. @@ -123,6 +123,7 @@ func newConn(addr string, opt *PoolOption) (dialer.Conn, error) { func (d *DBConnectionPool) RefreshTimeout(t time.Duration) { d.timeout = t } + // Execute executes all task by connections with DBConnectionPool. func (d *DBConnectionPool) Execute(tasks []*Task) error { wg := sync.WaitGroup{} diff --git a/api/pool_test.go b/api/pool_test.go index 621cade..293ad01 100644 --- a/api/pool_test.go +++ b/api/pool_test.go @@ -3,7 +3,7 @@ package api import ( "testing" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/api/table.go b/api/table.go index a879d99..a44ef52 100644 --- a/api/table.go +++ b/api/table.go @@ -1,7 +1,7 @@ package api import ( - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // Table is the client of table script. diff --git a/api/table_appender.go b/api/table_appender.go index b0f6e12..7b10f16 100644 --- a/api/table_appender.go +++ b/api/table_appender.go @@ -3,8 +3,8 @@ package api import ( "fmt" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/model" ) // TableAppender is used to append tables into another. diff --git a/api/table_appender_test.go b/api/table_appender_test.go index db7e5f8..f0b1bc1 100644 --- a/api/table_appender_test.go +++ b/api/table_appender_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/api/task.go b/api/task.go index f89439c..afd547a 100644 --- a/api/task.go +++ b/api/task.go @@ -1,6 +1,6 @@ package api -import "github.com/dolphindb/api-go/model" +import "github.com/dolphindb/api-go/v3/model" // Task is the unit of work that is executed in the DBConnectionPool. type Task struct { diff --git a/api/task_test.go b/api/task_test.go index 8073796..a3c191d 100644 --- a/api/task_test.go +++ b/api/task_test.go @@ -3,7 +3,7 @@ package api import ( "testing" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/api/utils.go b/api/utils.go index c4895d8..1bf0330 100644 --- a/api/utils.go +++ b/api/utils.go @@ -7,6 +7,12 @@ import ( uuid "github.com/satori/go.uuid" ) +var API_VERSION = "3.00.0.1" + +func GetAPIVersion() string { + return API_VERSION +} + func generateDBName() string { u1 := uuid.NewV4() return fmt.Sprintf("db_%s", u1.String()[:8]) diff --git a/dialer/behavior.go b/dialer/behavior.go index 0ea41c2..4272bda 100644 --- a/dialer/behavior.go +++ b/dialer/behavior.go @@ -15,13 +15,13 @@ type BehaviorOptions struct { LoadBalance bool // Whether to enable high availability. - // If true, when the address is unrearched, another address in HighAvailabilitySites will be connected. + // If true, when the address is unreached, another address in HighAvailabilitySites will be connected. EnableHighAvailability bool // Available only when EnableHighAvailability is true. HighAvailabilitySites []string - // If true, the address will be reconncted util the server is ready. + // If true, the address will be reconnected util the server is ready. Reconnect bool // IsReverseStreaming specifies whether the job is a reverse stream subscription diff --git a/dialer/dialer.go b/dialer/dialer.go index f57de97..7951c5a 100644 --- a/dialer/dialer.go +++ b/dialer/dialer.go @@ -9,8 +9,8 @@ import ( "sync" "time" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" ) const ( @@ -109,6 +109,9 @@ func NewConn(ctx context.Context, addr string, behaviorOpt *BehaviorOptions) (Co if !behaviorOpt.EnableHighAvailability && len(behaviorOpt.HighAvailabilitySites) != 0 { fmt.Println("Warn: HighAvailabilitySites is not empty but EnableHighAvailability is false") } + if behaviorOpt.Priority != nil && (*behaviorOpt.Priority < 0 || *behaviorOpt.Priority > 8) { + return nil, errors.New("the job priority must be between 0 and 8") + } return &conn{ behaviorOpt: behaviorOpt, addr: addr, @@ -144,9 +147,10 @@ func NewSimpleConn(ctx context.Context, address, userID, pwd string) (Conn, erro return conn, err } -func (c *conn) GetReader() protocol.Reader { +func (c *conn) GetReader() protocol.Reader { return c.reader } + // Add an init script which will be run after you call connect // func (c *conn) AddInitScript(script string) { // if c.initScripts == nil { @@ -236,9 +240,8 @@ func (c *conn) Connect() error { return err } else { if c.reconnect { - c.nodePool = &nodePool{ - nodes: []*node{{address: c.addr}}, - } + c.nodePool = &nodePool{} + c.nodePool.add(&node{address: c.addr}) return c.switchDatanode(&node{address: ""}) } else { ok, err := c.connectNode(&node{address: c.addr}) @@ -421,7 +424,7 @@ func (c *conn) runInternal(params *requestParams) (*responseHeader, model.DataFo } if c.behaviorOpt.GetFetchSize() > 0 && c.behaviorOpt.GetFetchSize() < 8192 { - return nil, nil, fmt.Errorf("fetchSize %d must be greater than 8192", c.behaviorOpt.GetFetchSize()) + return nil, nil, fmt.Errorf("fetchSize %d must be equal or greater than 8192", c.behaviorOpt.GetFetchSize()) } } diff --git a/dialer/dialer_test.go b/dialer/dialer_test.go index bc471af..cc7cc2c 100644 --- a/dialer/dialer_test.go +++ b/dialer/dialer_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/dialer/node.go b/dialer/node.go index 96ca41e..86ff32e 100644 --- a/dialer/node.go +++ b/dialer/node.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) type node struct { diff --git a/dialer/request.go b/dialer/request.go index e3205bf..e54adfc 100644 --- a/dialer/request.go +++ b/dialer/request.go @@ -5,8 +5,8 @@ import ( "fmt" "strconv" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" ) type requestParams struct { diff --git a/dialer/response.go b/dialer/response.go index e2f704a..f28b336 100644 --- a/dialer/response.go +++ b/dialer/response.go @@ -5,9 +5,9 @@ import ( "fmt" "strconv" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/errors" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/errors" + "github.com/dolphindb/api-go/v3/model" ) type responseHeader struct { diff --git a/dialer/util.go b/dialer/util.go index 6e6e787..96cf618 100644 --- a/dialer/util.go +++ b/dialer/util.go @@ -8,8 +8,8 @@ import ( "strconv" "strings" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" ) const ( diff --git a/domain/domain.go b/domain/domain.go index 42f8418..9ee508d 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -3,7 +3,7 @@ package domain import ( "fmt" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // PartitionType decides how to append partitioned table. diff --git a/domain/domain_test.go b/domain/domain_test.go index 3e37db6..afa9d0a 100644 --- a/domain/domain_test.go +++ b/domain/domain_test.go @@ -3,7 +3,7 @@ package domain import ( "testing" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/domain/hash_domain.go b/domain/hash_domain.go index 42ad1bf..02896e7 100644 --- a/domain/hash_domain.go +++ b/domain/hash_domain.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // HashDomain implements the Domain interface. diff --git a/domain/hash_domain_test.go b/domain/hash_domain_test.go index eda6492..1749aa1 100644 --- a/domain/hash_domain_test.go +++ b/domain/hash_domain_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/domain/list_domain.go b/domain/list_domain.go index a46bcc1..01eb025 100644 --- a/domain/list_domain.go +++ b/domain/list_domain.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // ListDomain implements the Domain interface. diff --git a/domain/list_domain_test.go b/domain/list_domain_test.go index 8e993a5..582c806 100644 --- a/domain/list_domain_test.go +++ b/domain/list_domain_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/domain/range_domain.go b/domain/range_domain.go index ed0d225..8f9e0ab 100644 --- a/domain/range_domain.go +++ b/domain/range_domain.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // RangeDomain implements the Domain interface. diff --git a/domain/range_domain_test.go b/domain/range_domain_test.go index 0bdd65f..a598fe2 100644 --- a/domain/range_domain_test.go +++ b/domain/range_domain_test.go @@ -3,7 +3,7 @@ package domain import ( "testing" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/domain/value_domain.go b/domain/value_domain.go index f696b15..1d1942c 100644 --- a/domain/value_domain.go +++ b/domain/value_domain.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // ValueDomain implements the Domain interface. diff --git a/domain/value_domain_test.go b/domain/value_domain_test.go index c950912..4c2c26c 100644 --- a/domain/value_domain_test.go +++ b/domain/value_domain_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/example/apis/account.go b/example/apis/account.go index d6a57f1..9854745 100644 --- a/example/apis/account.go +++ b/example/apis/account.go @@ -3,7 +3,7 @@ package apis import ( "fmt" - "github.com/dolphindb/api-go/api" + "github.com/dolphindb/api-go/v3/api" ) // Login checks whether the Login api is valid. diff --git a/example/apis/database.go b/example/apis/database.go index fdd238c..07f777b 100644 --- a/example/apis/database.go +++ b/example/apis/database.go @@ -3,7 +3,7 @@ package apis import ( "fmt" - "github.com/dolphindb/api-go/api" + "github.com/dolphindb/api-go/v3/api" ) // Database checks whether the Database api is valid. diff --git a/example/apis/pool.go b/example/apis/pool.go index 07308bd..e83e494 100644 --- a/example/apis/pool.go +++ b/example/apis/pool.go @@ -7,10 +7,10 @@ import ( "math/rand" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" ) func dropDatabase(db api.DolphinDB, dbPath string) { diff --git a/example/apis/table.go b/example/apis/table.go index 9b6140a..06c12bb 100644 --- a/example/apis/table.go +++ b/example/apis/table.go @@ -3,7 +3,7 @@ package apis import ( "fmt" - "github.com/dolphindb/api-go/api" + "github.com/dolphindb/api-go/v3/api" ) // ExistsTable checks whether the ExistsTable api is valid. diff --git a/example/example.go b/example/example.go index cc9d8c2..0a8ebdf 100644 --- a/example/example.go +++ b/example/example.go @@ -3,10 +3,10 @@ package main import ( "context" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/example/apis" - "github.com/dolphindb/api-go/example/streaming_test" - "github.com/dolphindb/api-go/example/util" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/example/apis" + "github.com/dolphindb/api-go/v3/example/streaming_test" + "github.com/dolphindb/api-go/v3/example/util" ) func main() { diff --git a/example/mtw/mtw.go b/example/mtw/mtw.go index 13d7202..d656a53 100644 --- a/example/mtw/mtw.go +++ b/example/mtw/mtw.go @@ -6,11 +6,11 @@ import ( "fmt" "time" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/example/apis" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" - mtw "github.com/dolphindb/api-go/multigoroutinetable" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/example/apis" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" + mtw "github.com/dolphindb/api-go/v3/multigoroutinetable" ) // MultiGoroutineTable checks whether the MultiGoroutineTable is valid when inserts to memory table. diff --git a/example/script/function.go b/example/script/function.go index 9294044..4768d30 100644 --- a/example/script/function.go +++ b/example/script/function.go @@ -3,9 +3,9 @@ package script import ( "fmt" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" ) // CheckFunction checks whether the RunFunc is valid. diff --git a/example/script/script.go b/example/script/script.go index 9d9fb60..456f46f 100644 --- a/example/script/script.go +++ b/example/script/script.go @@ -5,9 +5,9 @@ import ( "fmt" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" ) // CheckDataForm checks whether the DataForm serialization and deserialization are valid. diff --git a/example/streaming_test/streaming.go b/example/streaming_test/streaming.go index dc68f92..82afd20 100644 --- a/example/streaming_test/streaming.go +++ b/example/streaming_test/streaming.go @@ -6,12 +6,12 @@ import ( "fmt" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/example/apis" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/streaming" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/example/apis" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/streaming" ) var streamConn dialer.Conn diff --git a/go.mod b/go.mod index 6de472c..e207847 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,9 @@ -module github.com/dolphindb/api-go +module github.com/dolphindb/api-go/v3 go 1.15 require ( github.com/satori/go.uuid v1.1.0 - github.com/smallnest/chanx v1.0.0 github.com/stretchr/testify v1.7.2 ) diff --git a/go.sum b/go.sum index d44d760..2c0085c 100644 --- a/go.sum +++ b/go.sum @@ -20,18 +20,13 @@ github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBO github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/satori/go.uuid v1.1.0 h1:B9KXyj+GzIpJbV7gmr873NsY6zpbxNy24CBtGrk7jHo= github.com/satori/go.uuid v1.1.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/satori/go.uuid v1.2.1-0.20181016170032-d91630c85102 h1:WAQaHPfnpevd8SKXCcy5nk3JzEv2h5Q0kSwvoMqXiZs= -github.com/satori/go.uuid v1.2.1-0.20181016170032-d91630c85102/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/smallnest/chanx v1.0.0 h1:xd03MIQ0+doMOPQz/RQfHOTEeBTETputo9YZASCE/Os= -github.com/smallnest/chanx v1.0.0/go.mod h1:LH2uJLgza9WaWa4MgunOQERqM3t2ryDEq9LkPBlEfWM= github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -44,6 +39,5 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 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/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/model/chart.go b/model/chart.go index 76327d3..14123d1 100644 --- a/model/chart.go +++ b/model/chart.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) // ChartType is a map storing the mapping relationship. diff --git a/model/chart_test.go b/model/chart_test.go index 85cedf7..59007b1 100644 --- a/model/chart_test.go +++ b/model/chart_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/dataform.go b/model/dataform.go index 18eda82..68cee5d 100644 --- a/model/dataform.go +++ b/model/dataform.go @@ -1,8 +1,8 @@ package model import ( - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/errors" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/errors" ) // DataForm interface declares functions to handle DataForm data. @@ -39,7 +39,7 @@ func newCategory(dataForm, datatype byte) *Category { } func (cg *Category) render(w *protocol.Writer) error { - return w.Write(protocol.ByteSliceFromInt16Slice([]int16{int16(cg.DataForm) << 8 + int16(cg.DataType)})) + return w.Write(protocol.ByteSliceFromInt16Slice([]int16{int16(cg.DataForm)<<8 + int16(cg.DataType)})) } func parseCategory(r protocol.Reader, bo protocol.ByteOrder) (*Category, error) { @@ -47,7 +47,7 @@ func parseCategory(r protocol.Reader, bo protocol.ByteOrder) (*Category, error) if err != nil { return nil, errors.ReadDataTypeAndDataFormError(err.Error()) } - return newCategory(byte(c >> 8), byte(c << 8 >> 8)), nil + return newCategory(byte(c>>8), byte(c<<8>>8)), nil } // ParseDataForm parses the raw bytes in r with bo and return a DataForm object. diff --git a/model/dataform_test.go b/model/dataform_test.go index a91853e..7c9b094 100644 --- a/model/dataform_test.go +++ b/model/dataform_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/datatype.go b/model/datatype.go index 77d11af..b133d14 100644 --- a/model/datatype.go +++ b/model/datatype.go @@ -6,7 +6,7 @@ import ( "math/big" "time" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/shopspring/decimal" ) diff --git a/model/datatype_list.go b/model/datatype_list.go index dfb4eeb..45ec873 100644 --- a/model/datatype_list.go +++ b/model/datatype_list.go @@ -11,7 +11,7 @@ import ( "github.com/shopspring/decimal" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) // DataTypeList interface declares functions to handle DataType list. diff --git a/model/datatype_list_test.go b/model/datatype_list_test.go index 4016176..ed22ef6 100644 --- a/model/datatype_list_test.go +++ b/model/datatype_list_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/dictionary.go b/model/dictionary.go index 69559f4..ca40ccf 100644 --- a/model/dictionary.go +++ b/model/dictionary.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) // Dictionary is a DataForm. diff --git a/model/dictionary_test.go b/model/dictionary_test.go index c4c9dae..6d34f71 100644 --- a/model/dictionary_test.go +++ b/model/dictionary_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/io.go b/model/io.go index 473473c..100152b 100644 --- a/model/io.go +++ b/model/io.go @@ -5,7 +5,7 @@ import ( "math" "math/big" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) func (d *dataType) Render(w *protocol.Writer, bo protocol.ByteOrder) error { diff --git a/model/io_test.go b/model/io_test.go index eb53405..150ffd6 100644 --- a/model/io_test.go +++ b/model/io_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/matrix.go b/model/matrix.go index 58349a7..838e1a9 100644 --- a/model/matrix.go +++ b/model/matrix.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) // Matrix is a DataForm. diff --git a/model/matrix_test.go b/model/matrix_test.go index 2730827..616b3d2 100644 --- a/model/matrix_test.go +++ b/model/matrix_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/pair.go b/model/pair.go index c117528..75d9dff 100644 --- a/model/pair.go +++ b/model/pair.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) // Pair is a DataForm. diff --git a/model/pair_test.go b/model/pair_test.go index 9e5f44d..8b4aef4 100644 --- a/model/pair_test.go +++ b/model/pair_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/parse_dataform.go b/model/parse_dataform.go index 5b75c99..2a47b33 100644 --- a/model/parse_dataform.go +++ b/model/parse_dataform.go @@ -4,7 +4,7 @@ import ( "fmt" "math/big" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) func parseDictionary(r protocol.Reader, bo protocol.ByteOrder, c *Category) (*Dictionary, error) { @@ -232,7 +232,7 @@ func readVectorData(r protocol.Reader, bo protocol.ByteOrder, dv *Vector) error func ParseArrayVector(r protocol.Reader, t DataTypeByte, bo protocol.ByteOrder) (*Vector, error) { vct := &Vector{ - category: &Category{DataForm: DfVector,DataType: t}, + category: &Category{DataForm: DfVector, DataType: t}, RowCount: 1, } err := parseArrayVector(r, bo, vct) diff --git a/model/parse_dataform_test.go b/model/parse_dataform_test.go index 4aa6a27..62b8e34 100644 --- a/model/parse_dataform_test.go +++ b/model/parse_dataform_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/parse_datatype.go b/model/parse_datatype.go index 4cff7b8..999287b 100644 --- a/model/parse_datatype.go +++ b/model/parse_datatype.go @@ -5,7 +5,7 @@ import ( "math" "time" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) func parseDate(raw interface{}) time.Time { diff --git a/model/parse_datatype_test.go b/model/parse_datatype_test.go index 54ad889..936ecb7 100644 --- a/model/parse_datatype_test.go +++ b/model/parse_datatype_test.go @@ -4,7 +4,7 @@ import ( "math" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/render_datatype.go b/model/render_datatype.go index f0242cf..a3fc246 100644 --- a/model/render_datatype.go +++ b/model/render_datatype.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) var originalTime = time.Date(1970, time.Month(1), 1, 0, 0, 0, 0, time.UTC) diff --git a/model/scalar.go b/model/scalar.go index 84ab3f4..a907b39 100644 --- a/model/scalar.go +++ b/model/scalar.go @@ -3,7 +3,7 @@ package model import ( "fmt" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) // Scalar is a DataForm. diff --git a/model/scalar_test.go b/model/scalar_test.go index 9cd771e..ab5f9a5 100644 --- a/model/scalar_test.go +++ b/model/scalar_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/set.go b/model/set.go index d0a9e93..33a79f2 100644 --- a/model/set.go +++ b/model/set.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) // Set is a DataForm. diff --git a/model/set_test.go b/model/set_test.go index 1e1f966..1b440bd 100644 --- a/model/set_test.go +++ b/model/set_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/symbol_base_collecttion.go b/model/symbol_base_collecttion.go index b8ec700..97280fe 100644 --- a/model/symbol_base_collecttion.go +++ b/model/symbol_base_collecttion.go @@ -3,7 +3,7 @@ package model import ( "errors" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) type symbolBaseCollection struct { diff --git a/model/table.go b/model/table.go index abb0ca9..cf97514 100644 --- a/model/table.go +++ b/model/table.go @@ -7,7 +7,7 @@ import ( "reflect" "strings" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" ) // Table is a DataForm. diff --git a/model/table_test.go b/model/table_test.go index fee6b60..24332ea 100644 --- a/model/table_test.go +++ b/model/table_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/util.go b/model/util.go index 83637ba..46d06ce 100644 --- a/model/util.go +++ b/model/util.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/shopspring/decimal" ) diff --git a/model/util_test.go b/model/util_test.go index c324952..a5d5f15 100644 --- a/model/util_test.go +++ b/model/util_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/model/vector.go b/model/vector.go index 3ed2733..1af4fb8 100644 --- a/model/vector.go +++ b/model/vector.go @@ -6,7 +6,7 @@ import ( "math" "strings" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/shopspring/decimal" ) @@ -188,20 +188,21 @@ func (vct *Vector) Get(ind int) DataType { func (arrayVector *ArrayVector) formNewLength() []int32 { ret := make([]int32, 0) if arrayVector.unit == 1 { - mid := protocol.Int8SliceFromByteSlice(arrayVector.lengths); - for _,v := range mid { + mid := protocol.Int8SliceFromByteSlice(arrayVector.lengths) + for _, v := range mid { ret = append(ret, int32(v)) } return ret } else if arrayVector.unit == 2 { - mid := protocol.Int16SliceFromByteSlice(arrayVector.lengths); - for _,v := range mid { + mid := protocol.Int16SliceFromByteSlice(arrayVector.lengths) + for _, v := range mid { ret = append(ret, int32(v)) } return ret } - return protocol.Int32SliceFromByteSlice(arrayVector.lengths); + return protocol.Int32SliceFromByteSlice(arrayVector.lengths) } + // GetVectorValue returns the element of the ArrayVector based on the ind. func (vct *Vector) GetVectorValue(ind int) *Vector { if ind >= vct.Rows() { @@ -232,7 +233,7 @@ func (vct *Vector) GetVectorValue(ind int) *Vector { // AppendVectorValue appends the vector to arrayVector. func (vct *Vector) AppendVectorValue(data *Vector) (err error) { - if(vct.category.DataType != data.GetDataType() + 64) { + if vct.category.DataType != data.GetDataType()+64 { return fmt.Errorf("mismatched type, expect %s actual %s", GetDataTypeString(vct.category.DataType-64), data.GetDataTypeString()) } arrayVec := NewArrayVector([]*Vector{data}) @@ -489,7 +490,7 @@ func (vct *Vector) GetSubvector(indexes []int) *Vector { func (vct *Vector) getArrayVectorSubVector(indexes []int) *Vector { rawVec := make([]*Vector, 0, len(indexes)) - for _,v := range indexes { + for _, v := range indexes { rawVec = append(rawVec, vct.GetVectorValue(v)) } newData := NewArrayVector(rawVec) diff --git a/model/vector_test.go b/model/vector_test.go index f0a9aaa..fe1ae34 100644 --- a/model/vector_test.go +++ b/model/vector_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" + "github.com/dolphindb/api-go/v3/dialer/protocol" "github.com/stretchr/testify/assert" ) diff --git a/multigoroutinetable/multi_goroutine_table.go b/multigoroutinetable/multi_goroutine_table.go index 1a0f1cd..83faa1a 100644 --- a/multigoroutinetable/multi_goroutine_table.go +++ b/multigoroutinetable/multi_goroutine_table.go @@ -6,11 +6,11 @@ import ( "fmt" "strconv" "strings" - "time" + "time" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/domain" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/domain" + "github.com/dolphindb/api-go/v3/model" ) // MultiGoroutineTable is used to insert data into a table with multiple goroutines. diff --git a/multigoroutinetable/queue.go b/multigoroutinetable/queue.go index 6ba4b44..14f5dfd 100644 --- a/multigoroutinetable/queue.go +++ b/multigoroutinetable/queue.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) type queue struct { diff --git a/multigoroutinetable/writer_goroutine.go b/multigoroutinetable/writer_goroutine.go index 89b09b4..f58e991 100644 --- a/multigoroutinetable/writer_goroutine.go +++ b/multigoroutinetable/writer_goroutine.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/model" ) type writerGoroutine struct { diff --git a/streaming/basic_message.go b/streaming/basic_message.go index a8cbf13..6f90614 100644 --- a/streaming/basic_message.go +++ b/streaming/basic_message.go @@ -3,7 +3,7 @@ package streaming import ( "strings" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) // IMessage is the interface of subscription messages. @@ -70,10 +70,11 @@ func (m *Message) GetValueByName(name string) model.DataForm { func (m *Message) Size() int { return m.msg.Rows() } + type TableMessage struct { - offset int64 - topic string - sym string + offset int64 + topic string + sym string msg *model.Table } diff --git a/streaming/basic_message_test.go b/streaming/basic_message_test.go index b0d7eca..515128d 100644 --- a/streaming/basic_message_test.go +++ b/streaming/basic_message_test.go @@ -3,7 +3,7 @@ package streaming import ( "testing" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) diff --git a/streaming/deserializer.go b/streaming/deserializer.go index a4b6b9c..ca6867d 100644 --- a/streaming/deserializer.go +++ b/streaming/deserializer.go @@ -3,24 +3,24 @@ package streaming import ( "bytes" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" ) type msgDeserializer struct { - colTypes []model.DataTypeByte + colTypes []model.DataTypeByte nameToIndex map[string]int } func newMsgDeserializer(colNames []string, colTypes []model.DataTypeByte) *msgDeserializer { // init nameToIndex nameToIndex := make(map[string]int, len(colNames)) - for k,v := range colNames { + for k, v := range colNames { nameToIndex[v] = k } md := &msgDeserializer{ nameToIndex: nameToIndex, - colTypes: make([]model.DataTypeByte, len(colTypes)), + colTypes: make([]model.DataTypeByte, len(colTypes)), } copy(md.colTypes, colTypes) @@ -33,7 +33,7 @@ func (md *msgDeserializer) parse(data []byte) (*model.Vector, error) { scalarList := make([]model.DataForm, len(md.colTypes)) for k, v := range md.colTypes { - if(v >= 64) { + if v >= 64 { vct, err := model.ParseArrayVector(rd, v, protocol.LittleEndian) if err != nil { return nil, err diff --git a/streaming/goroutine_client_test.go b/streaming/goroutine_client_test.go index 1ea16fe..2421be0 100644 --- a/streaming/goroutine_client_test.go +++ b/streaming/goroutine_client_test.go @@ -7,29 +7,29 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) var failedAction = "failedAction" var scripts = "st1 = streamTable(100:0, `timestampv`sym`blob,[TIMESTAMP,SYMBOL,BLOB]);" + - "share st1 as outTables;" + - "n = 3;" + - "table1 = table(100:0, `datetimev`timestampv`sym`price1`price2, [DATETIME, TIMESTAMP, SYMBOL, DOUBLE, DOUBLE]);" + - "share table1 as pt1;" + - "table2 = table(100:0, `datetimev`timestampv`sym`price1, [DATETIME, TIMESTAMP, SYMBOL, DOUBLE]);" + - "share table2 as pt2;" + - "tableInsert(table1, 2012.01.01T01:21:23 + 1..n, 2018.12.01T01:21:23.000 + 1..n, take(`a`b`c,n), rand(100,n)+rand(1.0, n), rand(100,n)+rand(1.0, n));" + - "tableInsert(table2, 2012.01.01T01:21:23 + 1..n, 2018.12.01T01:21:23.000 + 1..n, take(`a`b`c,n), rand(100,n)+rand(1.0, n));" + - "d = dict(['msg1','msg2'], [table1, table2]);" + - "replay(inputTables=d, outputTables=`outTables, dateColumn=`timestampv, timeColumn=`timestampv);" + "share st1 as outTables;" + + "n = 3;" + + "table1 = table(100:0, `datetimev`timestampv`sym`price1`price2, [DATETIME, TIMESTAMP, SYMBOL, DOUBLE, DOUBLE]);" + + "share table1 as pt1;" + + "table2 = table(100:0, `datetimev`timestampv`sym`price1, [DATETIME, TIMESTAMP, SYMBOL, DOUBLE]);" + + "share table2 as pt2;" + + "tableInsert(table1, 2012.01.01T01:21:23 + 1..n, 2018.12.01T01:21:23.000 + 1..n, take(`a`b`c,n), rand(100,n)+rand(1.0, n), rand(100,n)+rand(1.0, n));" + + "tableInsert(table2, 2012.01.01T01:21:23 + 1..n, 2018.12.01T01:21:23.000 + 1..n, take(`a`b`c,n), rand(100,n)+rand(1.0, n));" + + "d = dict(['msg1','msg2'], [table1, table2]);" + + "replay(inputTables=d, outputTables=`outTables, dateColumn=`timestampv, timeColumn=`timestampv);" type basicHandler struct { times int - msgs []IMessage + msgs []IMessage } func (s *basicHandler) DoEvent(msg IMessage) { @@ -48,22 +48,22 @@ func (s *batchHandler) DoEvent(msg []IMessage) { } func TestBasicGoroutineClient(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) client := NewGoroutineClient("localhost", 8848) @@ -78,13 +78,13 @@ func TestBasicGoroutineClient(t *testing.T) { Handler: &sh, Offset: 0, Reconnect: true, - Throttle: &throttle, + Throttle: &throttle, } err = client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) assert.Equal(t, 6, sh.times) for _, v := range sh.msgs { assert.Equal(t, model.DtBlob, v.GetValueByName("blob").GetDataType()) @@ -94,22 +94,22 @@ func TestBasicGoroutineClient(t *testing.T) { } func TestMsgAsTableGoroutineClient(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) client := NewGoroutineClient("localhost", 8848) @@ -123,41 +123,41 @@ func TestMsgAsTableGoroutineClient(t *testing.T) { MsgAsTable: true, Handler: &sh, Offset: 0, - BatchSize: &batch, + BatchSize: &batch, Reconnect: true, } err = client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) assert.Equal(t, 1, sh.times) tbl := sh.msgs[0] assert.Equal(t, 6, tbl.Size()) symVec := tbl.GetValueByName("sym").(*model.Vector).GetRawValue() - for _,v := range symVec { - assert.True(t, v=="msg1" || v=="msg2") + for _, v := range symVec { + assert.True(t, v == "msg1" || v == "msg2") } assert.Equal(t, model.DfVector, tbl.GetValueByName("blob").GetDataForm()) } func TestBatchGoroutineClient(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) client := NewGoroutineClient("localhost", 8848) @@ -165,20 +165,20 @@ func TestBatchGoroutineClient(t *testing.T) { sh := batchHandler{} throttle := 1 req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: false, - BatchHandler: &sh, - Offset: 0, - Reconnect: true, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: false, + BatchHandler: &sh, + Offset: 0, + Reconnect: true, } req.SetBatchSize(10).SetThrottle(float32(throttle)) err = client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) assert.Equal(t, 1, sh.times) assert.Equal(t, 6, sh.lines) } @@ -189,14 +189,14 @@ func TestErrMsgAsTableWithNoBatch(t *testing.T) { sh := batchHandler{} throttle := float32(1) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: true, - BatchHandler: &sh, - Offset: 0, - Reconnect: true, - Throttle: &throttle, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: true, + BatchHandler: &sh, + Offset: 0, + Reconnect: true, + Throttle: &throttle, } req.SetBatchSize(10) @@ -210,14 +210,14 @@ func TestErrBasicWithBatch(t *testing.T) { sh := batchHandler{} throttle := float32(1) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: false, - BatchHandler: &sh, - Offset: 0, - Reconnect: true, - Throttle: &throttle, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: false, + BatchHandler: &sh, + Offset: 0, + Reconnect: true, + Throttle: &throttle, } err := client.Subscribe(req) @@ -237,7 +237,7 @@ func TestErrBasicWithNoBatch(t *testing.T) { Handler: &sh, Offset: 0, Reconnect: true, - Throttle: &throttle, + Throttle: &throttle, } req.SetBatchSize(10) @@ -349,8 +349,6 @@ func TestUnsubscribeInDoEvent(t *testing.T) { fmt.Println("TestUnsubscribeInDoEvent test finish ") } - - var arrayVectorStreamScript = "st1 = streamTable(100:0, `arrayInt`timestampv`sym,[INT[],TIMESTAMP,SYMBOL]);" + "share st1 as outTables;" + "outTables.append!(table(arrayVector([4], [1,2,3,4]) as arrayInt, [2018.12.01T01:21:23.000] as timestampv, [`a] as sym));" @@ -405,4 +403,4 @@ func TestArrayVectorStream(t *testing.T) { assert.Equal(t, 1, len(sh.msgs)) -} \ No newline at end of file +} diff --git a/streaming/goroutine_pooled_client_test.go b/streaming/goroutine_pooled_client_test.go index 4e49be2..0aa1356 100644 --- a/streaming/goroutine_pooled_client_test.go +++ b/streaming/goroutine_pooled_client_test.go @@ -6,15 +6,15 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) type poolHandler struct { times int - msgs []IMessage + msgs []IMessage } func (s *poolHandler) DoEvent(msg IMessage) { @@ -24,22 +24,22 @@ func (s *poolHandler) DoEvent(msg IMessage) { } func TestBasicGoroutinePooledClient(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) tpc := NewGoroutinePooledClient(localhost, 8848) @@ -53,13 +53,13 @@ func TestBasicGoroutinePooledClient(t *testing.T) { Handler: &sh, Offset: 0, Reconnect: true, - Throttle: &throttle, + Throttle: &throttle, } err = tpc.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) assert.Equal(t, 6, sh.times) for _, v := range sh.msgs { assert.Equal(t, model.DtBlob, v.GetValueByName("blob").GetDataType()) @@ -72,7 +72,7 @@ func TestBasicGoroutinePooledClient(t *testing.T) { type batchPoolHandler struct { lines int times int - msgs []IMessage + msgs []IMessage } func (s *batchPoolHandler) DoEvent(msg []IMessage) { @@ -83,34 +83,34 @@ func (s *batchPoolHandler) DoEvent(msg []IMessage) { } func TestBatchGoroutinePooledClient(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) tpc := NewGoroutinePooledClient(localhost, 8848) sh := batchPoolHandler{} req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: false, - BatchHandler: &sh, - Offset: 0, - Reconnect: true, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: false, + BatchHandler: &sh, + Offset: 0, + Reconnect: true, } // req.SetThrottle(100) req.SetBatchSize(6) @@ -118,29 +118,29 @@ func TestBatchGoroutinePooledClient(t *testing.T) { err = tpc.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(3)*time.Second) + time.Sleep(time.Duration(3) * time.Second) assert.Equal(t, 6, sh.lines) assert.Equal(t, 1, sh.times) tpc.Close() } func TestBatchMsgAsTableGoroutinePooledClient(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) tpc := NewGoroutinePooledClient(localhost, 8848) @@ -154,14 +154,14 @@ func TestBatchMsgAsTableGoroutinePooledClient(t *testing.T) { Handler: &sh, Offset: 0, Reconnect: true, - Throttle: &throttle, + Throttle: &throttle, } req.SetBatchSize(2) err = tpc.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(3)*time.Second) + time.Sleep(time.Duration(3) * time.Second) assert.Equal(t, 3, sh.times) tbl := sh.msgs[0] assert.Equal(t, 2, tbl.Size()) @@ -176,14 +176,14 @@ func TestBatchHandlerErrGoroutinePooledClient(t *testing.T) { sh := batchPoolHandler{} throttle := float32(1) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: false, - BatchHandler: &sh, - Offset: 0, - Reconnect: true, - Throttle: &throttle, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: false, + BatchHandler: &sh, + Offset: 0, + Reconnect: true, + Throttle: &throttle, } err := tpc.Subscribe(req) @@ -194,14 +194,14 @@ func TestBatchHandlerMsgAsTableErrGoroutinePooledClient(t *testing.T) { sh := batchPoolHandler{} throttle := float32(1) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: true, - BatchHandler: &sh, - Offset: 0, - Reconnect: true, - Throttle: &throttle, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: true, + BatchHandler: &sh, + Offset: 0, + Reconnect: true, + Throttle: &throttle, } req.SetBatchSize(10) req.SetThrottle(1000) @@ -222,7 +222,7 @@ func TestBatchHandlerNilErrGoroutinePooledClient(t *testing.T) { Handler: &sh, Offset: 0, Reconnect: true, - Throttle: &throttle, + Throttle: &throttle, } req.SetBatchSize(10) diff --git a/streaming/handler_looper.go b/streaming/handler_looper.go index 5c99078..a7262d6 100644 --- a/streaming/handler_looper.go +++ b/streaming/handler_looper.go @@ -5,19 +5,19 @@ import ( "fmt" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" ) type handlerLopper struct { - queue *UnboundedChan - handler MessageHandler - batchHandler MessageBatchHandler + queue *UnboundedChan + handler MessageHandler + batchHandler MessageBatchHandler MsgDeserializer *StreamDeserializer msgAsTable bool - batchSize *int - throttle *int - exit chan bool + batchSize *int + throttle *int + exit chan bool affirmExit chan bool } @@ -73,7 +73,7 @@ func mergeIMessage(msg []IMessage) (IMessage, error) { colNum := len(firstMsg.nameToIndex) colNames := make([]string, colNum) colValues := make([](*model.Vector), colNum) - for k,v := range firstMsg.nameToIndex { + for k, v := range firstMsg.nameToIndex { colNames[v] = k val := firstMsg.GetValue(v) valType := val.(*model.Scalar).DataType @@ -84,7 +84,7 @@ func mergeIMessage(msg []IMessage) (IMessage, error) { for i := 1; i < len(msg); i++ { inMsg := msg[i].(*Message) - for k,v := range inMsg.nameToIndex { + for k, v := range inMsg.nameToIndex { colNames[v] = k val := inMsg.GetValue(v) valType := val.(*model.Scalar).DataType @@ -95,10 +95,10 @@ func mergeIMessage(msg []IMessage) (IMessage, error) { } } table := model.NewTable(colNames, colValues) - ret := &TableMessage { + ret := &TableMessage{ offset: firstMsg.offset, - topic: firstMsg.topic, - sym: firstMsg.sym, + topic: firstMsg.topic, + sym: firstMsg.sym, msg: table, } @@ -110,7 +110,7 @@ func (h *handlerLopper) handleMessage() { if len(msg) == 0 { return } - if(h.msgAsTable) { + if h.msgAsTable { ret, err := mergeIMessage(msg) if err != nil { fmt.Printf("merge msg to table failed: %s\n", err.Error()) @@ -118,8 +118,8 @@ func (h *handlerLopper) handleMessage() { if !h.isStopped() { h.handler.DoEvent(ret) } - } else if (h.batchSize != nil && *h.batchSize >= 1) { - if(h.MsgDeserializer != nil) { + } else if h.batchSize != nil && *h.batchSize >= 1 { + if h.MsgDeserializer != nil { outMsg := make([]IMessage, 0) for _, v := range msg { ret, err := h.MsgDeserializer.Parse(v) @@ -139,7 +139,7 @@ func (h *handlerLopper) handleMessage() { } } else { for _, v := range msg { - if(h.MsgDeserializer != nil) { + if h.MsgDeserializer != nil { ret, err := h.MsgDeserializer.Parse(v) if err != nil { fmt.Printf("StreamDeserializer parse failed: %s\n", err.Error()) @@ -202,8 +202,7 @@ func batchPoll(queue *UnboundedChan, batchSize int, throttle int) []IMessage { } } - - return msg; + return msg } // func poll(queue *UnboundedChan, batchSize int, throttle int) []IMessage { diff --git a/streaming/message_parser.go b/streaming/message_parser.go index e64097d..ec77e04 100644 --- a/streaming/message_parser.go +++ b/streaming/message_parser.go @@ -9,9 +9,9 @@ import ( "strings" "time" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" ) type messageParser struct { @@ -21,9 +21,10 @@ type messageParser struct { topic string topicNameToIndex map[string]map[string]int - firstColType model.DataTypeByte + firstColType model.DataTypeByte isReversed bool } + func closeUnboundedChan(q *UnboundedChan) { close(q.In) // y := 0 @@ -39,7 +40,7 @@ func closeUnboundedChan(q *UnboundedChan) { } func (m *messageParser) run() { - err := m.parse(); + err := m.parse() // TODO concern more than one topic if IsClosed(m.topic) { @@ -81,7 +82,7 @@ func (m *messageParser) parseHeader(r protocol.Reader, bo protocol.ByteOrder) (u func (m *messageParser) parse() error { var r protocol.Reader - if(m.isReversed) { + if m.isReversed { r = m.Conn.(dialer.Conn).GetReader() } else { r = protocol.NewReader(m.Conn) @@ -154,10 +155,10 @@ func (m *messageParser) parseTable(tb *model.Table) { } func (m *messageParser) isTupleMsg(firstElement model.DataForm) bool { - if (firstElement.GetDataForm() == model.DfScalar) || (firstElement.GetDataType() == m.firstColType - 64) { - return true; + if (firstElement.GetDataForm() == model.DfScalar) || (firstElement.GetDataType() == m.firstColType-64) { + return true } - return false; + return false } func (m *messageParser) parseVector(msgID uint64, vct *model.Vector) { diff --git a/streaming/polling_client_test.go b/streaming/polling_client_test.go index 40621c8..2191c39 100644 --- a/streaming/polling_client_test.go +++ b/streaming/polling_client_test.go @@ -9,9 +9,9 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) @@ -243,26 +243,23 @@ func isExit(exit <-chan bool) bool { } } - - - func TestPollingClientNormal(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) client := NewPollingClient("localhost", 8848) @@ -279,7 +276,7 @@ func TestPollingClientNormal(t *testing.T) { poller, err := client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) msgVec := poller.Poll(1, 6) assert.Equal(t, 6, len(msgVec)) for _, v := range msgVec { @@ -290,22 +287,22 @@ func TestPollingClientNormal(t *testing.T) { } func TestPollingClientMsgAsTable(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) client := NewPollingClient("localhost", 8848) @@ -322,33 +319,33 @@ func TestPollingClientMsgAsTable(t *testing.T) { poller, err := client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) msgVec := poller.Poll(1, 6) tbl := msgVec[0] assert.Equal(t, 6, tbl.Size()) symVec := tbl.GetValueByName("sym").(*model.Vector).GetRawValue() - for _,v := range symVec { - assert.True(t, v=="msg1" || v=="msg2") + for _, v := range symVec { + assert.True(t, v == "msg1" || v == "msg2") } assert.Equal(t, model.DfVector, tbl.GetValueByName("blob").GetDataForm()) } func TestPollingClientStreamDeserializer(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) client := NewPollingClient("localhost", 8848) @@ -357,7 +354,7 @@ func TestPollingClientStreamDeserializer(t *testing.T) { sdMap["msg1"] = [2]string{"", "pt1"} sdMap["msg2"] = [2]string{"", "pt2"} - opt := StreamDeserializerOption { + opt := StreamDeserializerOption{ TableNames: sdMap, Conn: db, } @@ -365,18 +362,18 @@ func TestPollingClientStreamDeserializer(t *testing.T) { util.AssertNil(err) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - Offset: 0, - Reconnect: true, - MsgDeserializer: sd, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + Offset: 0, + Reconnect: true, + MsgDeserializer: sd, } poller, err := client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) msgs := poller.Poll(1, 6) assert.Equal(t, len(msgs), 6) msg1StrVec := make([]interface{}, 0) @@ -411,30 +408,29 @@ func TestPollingClientStreamDeserializer(t *testing.T) { assert.Equal(t, msg2Value, msg2StrVec) } - func TestPollingClientStreamDeserializerErr(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) err = db.Connect() util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } - err = db.Login(loginReq) + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) sdMap := make(map[string][2]string) sdMap["msg1"] = [2]string{"", "pt1"} sdMap["msg2"] = [2]string{"", "pt2"} - opt := StreamDeserializerOption { + opt := StreamDeserializerOption{ TableNames: sdMap, Conn: db, } @@ -442,16 +438,16 @@ func TestPollingClientStreamDeserializerErr(t *testing.T) { util.AssertNil(err) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: true, - Offset: 0, - Reconnect: true, - MsgDeserializer: sd, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: true, + Offset: 0, + Reconnect: true, + MsgDeserializer: sd, } client := NewPollingClient("localhost", 8848) _, err = client.Subscribe(req) assert.EqualError(t, err, "if MsgAsTable is true, MsgDeserializer must be nil") -} \ No newline at end of file +} diff --git a/streaming/stream_deserializer.go b/streaming/stream_deserializer.go index bfc089c..889ec1f 100644 --- a/streaming/stream_deserializer.go +++ b/streaming/stream_deserializer.go @@ -4,8 +4,8 @@ import ( "errors" "fmt" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" ) type StreamDeserializer struct { @@ -144,7 +144,7 @@ func (sd *StreamDeserializer) Parse(msg IMessage) (*Message, error) { return nil, fmt.Errorf("the filter %s does not exist", sym) } - md:= sd.msgDeserializerMap[sym] + md := sd.msgDeserializerMap[sym] vct, err := md.parse(blob) if err != nil { @@ -152,10 +152,10 @@ func (sd *StreamDeserializer) Parse(msg IMessage) (*Message, error) { } return &Message{ - offset: msg.GetOffset(), - topic: msg.GetTopic(), - msg: vct, - sym: sym, + offset: msg.GetOffset(), + topic: msg.GetTopic(), + msg: vct, + sym: sym, nameToIndex: md.nameToIndex, }, nil } diff --git a/streaming/stream_deserializer_test.go b/streaming/stream_deserializer_test.go index 47c4edb..609bc0b 100644 --- a/streaming/stream_deserializer_test.go +++ b/streaming/stream_deserializer_test.go @@ -6,14 +6,14 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/example/util" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/example/util" + "github.com/dolphindb/api-go/v3/model" "github.com/stretchr/testify/assert" ) type sampleHandler struct { - sd StreamDeserializer + sd StreamDeserializer msgs []IMessage } @@ -24,29 +24,29 @@ func (s *sampleHandler) DoEvent(msg IMessage) { } func TestStreamDeserializerInHandler(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) //script defined in goroutine_client_test.go + _, err = db.RunScript(scripts) //script defined in goroutine_client_test.go util.AssertNil(err) sdMap := make(map[string][2]string) sdMap["msg1"] = [2]string{"", "pt1"} sdMap["msg2"] = [2]string{"", "pt2"} - opt := StreamDeserializerOption { + opt := StreamDeserializerOption{ TableNames: sdMap, Conn: db, } @@ -65,13 +65,13 @@ func TestStreamDeserializerInHandler(t *testing.T) { Handler: &sh, Offset: 0, Reconnect: true, - Throttle: &throttle, + Throttle: &throttle, } err = client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(2)*time.Second) + time.Sleep(time.Duration(2) * time.Second) assert.Equal(t, 6, len(sh.msgs)) msg1StrVec := make([]interface{}, 0) @@ -115,29 +115,29 @@ func (s *basicHandlerWithoutStreamDeserializer) DoEvent(msg IMessage) { } func TestPassInStreamDeserializer(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) //script defined in goroutine_client_test.go + _, err = db.RunScript(scripts) //script defined in goroutine_client_test.go util.AssertNil(err) sdMap := make(map[string][2]string) sdMap["msg1"] = [2]string{"", "pt1"} sdMap["msg2"] = [2]string{"", "pt2"} - opt := StreamDeserializerOption { + opt := StreamDeserializerOption{ TableNames: sdMap, Conn: db, } @@ -149,21 +149,21 @@ func TestPassInStreamDeserializer(t *testing.T) { sh := basicHandlerWithoutStreamDeserializer{make([]IMessage, 0)} throttle := float32(1) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: false, - Handler: &sh, - Offset: 0, - Reconnect: true, - Throttle: &throttle, - MsgDeserializer: sd, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: false, + Handler: &sh, + Offset: 0, + Reconnect: true, + Throttle: &throttle, + MsgDeserializer: sd, } err = client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) assert.Equal(t, len(sh.msgs), 6) msg1StrVec := make([]interface{}, 0) msg1Value := []interface{}{"a", "b", "c"} @@ -197,7 +197,6 @@ func TestPassInStreamDeserializer(t *testing.T) { assert.Equal(t, msg2Value, msg2StrVec) } - type batchHandlerWithoutStreamDeserializer struct { msgs []IMessage } @@ -207,29 +206,29 @@ func (s *batchHandlerWithoutStreamDeserializer) DoEvent(msg []IMessage) { } func TestPassInStreamDeserializerInBatch(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) //script defined in goroutine_client_test.go + _, err = db.RunScript(scripts) //script defined in goroutine_client_test.go util.AssertNil(err) sdMap := make(map[string][2]string) sdMap["msg1"] = [2]string{"", "pt1"} sdMap["msg2"] = [2]string{"", "pt2"} - opt := StreamDeserializerOption { + opt := StreamDeserializerOption{ TableNames: sdMap, Conn: db, } @@ -242,22 +241,22 @@ func TestPassInStreamDeserializerInBatch(t *testing.T) { throttle := float32(1) batch := 2 req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: false, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: false, BatchHandler: &sh, - Offset: 0, - Reconnect: true, - Throttle: &throttle, - BatchSize: &batch, - MsgDeserializer: sd, + Offset: 0, + Reconnect: true, + Throttle: &throttle, + BatchSize: &batch, + MsgDeserializer: sd, } err = client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(2)*time.Second) + time.Sleep(time.Duration(2) * time.Second) assert.Equal(t, len(sh.msgs), 6) msg1StrVec := make([]interface{}, 0) msg1Value := []interface{}{"a", "b", "c"} @@ -291,10 +290,9 @@ func TestPassInStreamDeserializerInBatch(t *testing.T) { assert.Equal(t, msg2Value, msg2StrVec) } - type poolDeserializerHandler struct { times int - msgs []IMessage + msgs []IMessage } func (s *poolDeserializerHandler) DoEvent(msg IMessage) { @@ -303,31 +301,30 @@ func (s *poolDeserializerHandler) DoEvent(msg IMessage) { s.msgs = append(s.msgs, msg) } - func TestPoolStreamDeserializer(t *testing.T) { - host := "localhost:8848"; + host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) util.AssertNil(err) - loginReq := &api.LoginRequest{ - UserID: "admin", - Password: "123456", - } + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } err = db.Connect() util.AssertNil(err) - err = db.Login(loginReq) + err = db.Login(loginReq) util.AssertNil(err) - _,err = db.RunScript(scripts) + _, err = db.RunScript(scripts) util.AssertNil(err) sdMap := make(map[string][2]string) sdMap["msg1"] = [2]string{"", "pt1"} sdMap["msg2"] = [2]string{"", "pt2"} - opt := StreamDeserializerOption { + opt := StreamDeserializerOption{ TableNames: sdMap, Conn: db, } @@ -338,22 +335,22 @@ func TestPoolStreamDeserializer(t *testing.T) { sh := poolDeserializerHandler{} throttle := float32(0.000) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: false, - Handler: &sh, - Offset: 0, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: false, + Handler: &sh, + Offset: 0, MsgDeserializer: sd, - Reconnect: true, - Throttle: &throttle, + Reconnect: true, + Throttle: &throttle, } req.SetBatchSize(0) err = tpc.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(3)*time.Second) + time.Sleep(time.Duration(3) * time.Second) assert.Equal(t, len(sh.msgs), 6) msg1StrVec := make([]interface{}, 0) @@ -388,7 +385,6 @@ func TestPoolStreamDeserializer(t *testing.T) { assert.Equal(t, msg2Value, msg2StrVec) } - var arrayVectorReplayScript = "st1 = streamTable(100:0, `timestampv`sym`blob,[TIMESTAMP,SYMBOL,BLOB]);" + "share st1 as outTables;" + "n = 300;" + @@ -406,10 +402,10 @@ var arrayVectorReplayScript = "st1 = streamTable(100:0, `timestampv`sym`blob,[TI var endScript = "tableInsert(outTables, table([2012.01.01T01:21:23] as timestampv, [`end] as sym, [`blob] as blob));" type replayHandle struct { - sd StreamDeserializer + sd StreamDeserializer msgs1 []IMessage msgs2 []IMessage - ch chan bool + ch chan bool } func (s *replayHandle) DoEvent(msgs []IMessage) { @@ -418,12 +414,12 @@ func (s *replayHandle) DoEvent(msgs []IMessage) { fmt.Println(msg.GetValue(1)) if msg.GetValue(1).(*model.Scalar).DataType.String() == "end" { fmt.Println("DoEvent: got to end") - s.ch <- true; + s.ch <- true return } ret, err := s.sd.Parse(msg) util.AssertNil(err) - if(msg.GetValue(1).(*model.Scalar).DataType.String() == "msg1") { + if msg.GetValue(1).(*model.Scalar).DataType.String() == "msg1" { fmt.Println(ret.GetValue(3), ret.GetValue(3), ret.GetValue(4), " ") arrV := ret.GetValue(3) fmt.Println(arrV.GetDataType(), arrV.GetDataTypeString()) @@ -452,7 +448,6 @@ func TestStreamDeserializerReplayParam(t *testing.T) { _, err = db.RunScript(arrayVectorReplayScript) //script defined in goroutine_client_test.go util.AssertNil(err) - sdMap := make(map[string][2]string) sdMap["msg1"] = [2]string{"", "pt1"} sdMap["msg2"] = [2]string{"", "pt2"} @@ -470,31 +465,30 @@ func TestStreamDeserializerReplayParam(t *testing.T) { batchSize := 10 throttle := float32(1) req := &SubscribeRequest{ - Address: "localhost:8848", - TableName: "outTables", - ActionName: "action1", - MsgAsTable: false, - BatchHandler: &sh, - Offset: 0, - Reconnect: true, - Throttle: &throttle, - BatchSize: &batchSize, + Address: "localhost:8848", + TableName: "outTables", + ActionName: "action1", + MsgAsTable: false, + BatchHandler: &sh, + Offset: 0, + Reconnect: true, + Throttle: &throttle, + BatchSize: &batchSize, } err = client.Subscribe(req) util.AssertNil(err) - time.Sleep(time.Duration(3)*time.Second) + time.Sleep(time.Duration(3) * time.Second) _, err = db.RunScript(endScript) //script defined in goroutine_client_test.go util.AssertNil(err) - <- sh.ch + <-sh.ch assert.Equal(t, 300, len(sh.msgs1)) assert.Equal(t, 300, len(sh.msgs2)) } - func TestStreamBug(t *testing.T) { host := "localhost:8848" db, err := api.NewDolphinDBClient(context.TODO(), host, nil) @@ -517,4 +511,4 @@ func TestStreamBug(t *testing.T) { // time.Sleep(time.Duration(3)*time.Second) _, err = db.RunScript(endScript) //script defined in goroutine_client_test.go util.AssertNil(err) -} \ No newline at end of file +} diff --git a/streaming/subscriber.go b/streaming/subscriber.go index 3bae20a..75aa0ae 100644 --- a/streaming/subscriber.go +++ b/streaming/subscriber.go @@ -9,8 +9,8 @@ import ( "sync" "time" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/model" ) type subscriber struct { @@ -141,8 +141,6 @@ func (s *subscriber) subscribeInternal(req *SubscribeRequest) (*UnboundedChan, e return q, retErr } - - func (s *subscriber) reSubscribeInternal(req *SubscribeRequest) error { var conn dialer.Conn var err error @@ -242,14 +240,14 @@ func isLater(ori, raw string) bool { func (s *subscriber) getConn() (net.Conn, bool) { select { - case tc, ok := <-s.connList.Out: - if ok { - return tc.(dialer.Conn), true - } else { - return nil, false - } - default: + case tc, ok := <-s.connList.Out: + if ok { + return tc.(dialer.Conn), true + } else { return nil, false + } + default: + return nil, false } } diff --git a/streaming/util.go b/streaming/util.go index 93de56d..0552691 100644 --- a/streaming/util.go +++ b/streaming/util.go @@ -8,8 +8,8 @@ import ( "sync" "time" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/model" ) func getReconnectTimestamp(site string) int64 { @@ -68,9 +68,9 @@ func dispatch(msg IMessage) { } sitesRaw, ok := trueTopicToSites.Load(topic) - if(ok && sitesRaw != nil) { + if ok && sitesRaw != nil { sites := sitesRaw.([]*site) - for _,s := range sites { + for _, s := range sites { s.msgID += 1 } } @@ -118,7 +118,7 @@ func flushToQueue() { sites := make([]*site, 0) sitesRaw, ok := trueTopicToSites.Load(topic) - if(ok && sitesRaw != nil) { + if ok && sitesRaw != nil { sites = sitesRaw.([]*site) } @@ -126,7 +126,7 @@ func flushToQueue() { if ok && raw != nil { q := raw.(*UnboundedChan) for _, m := range val { - for _,s := range sites { + for _, s := range sites { s.msgID += 1 } q.In <- m diff --git a/test/basicTypeTest/basicChart_test.go b/test/basicTypeTest/basicChart_test.go index 81a6f6f..9d82f68 100644 --- a/test/basicTypeTest/basicChart_test.go +++ b/test/basicTypeTest/basicChart_test.go @@ -6,10 +6,10 @@ import ( "fmt" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/basicTypeTest/basicDictionary_test.go b/test/basicTypeTest/basicDictionary_test.go index 75404d6..0c78c3f 100644 --- a/test/basicTypeTest/basicDictionary_test.go +++ b/test/basicTypeTest/basicDictionary_test.go @@ -7,9 +7,9 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) @@ -859,7 +859,7 @@ func Test_Dictionary_DownLoad_decimal32(t *testing.T) { db, err := api.NewSimpleDolphinDBClient(context.TODO(), setup.Address, setup.UserName, setup.Password) So(err, ShouldBeNil) Convey("Test_dictionary_decimal32_not_null:", func() { - s, err := db.RunScript("x=`a`b`c`d`e;y=take(0.99999,5)$DECIMAL32(2);z=dict(x,y);z") + s, err := db.RunScript("x=`a`b`c`d`e;y=take(0.98999,5)$DECIMAL32(2);z=dict(x,y);z") So(err, ShouldBeNil) result := s.(*model.Dictionary) key := []string{"a", "b", "c", "d"} @@ -900,7 +900,7 @@ func Test_Dictionary_DownLoad_decimal64(t *testing.T) { So(err, ShouldBeNil) result := s.(*model.Dictionary) key := []string{"a", "b", "c", "d"} - val := &model.Decimal64s{11, []float64{0.99999456485, 0.99999456485, 0.99999456485}} + val := &model.Decimal64s{11, []float64{0.99999456486, 0.99999456486, 0.99999456486}} for i := 0; i < 3; i++ { get, _ := result.Get(key[i]) zx := get.Value().(*model.Decimal64) diff --git a/test/basicTypeTest/basicMatrix_test.go b/test/basicTypeTest/basicMatrix_test.go index 9573a97..baf5ba5 100644 --- a/test/basicTypeTest/basicMatrix_test.go +++ b/test/basicTypeTest/basicMatrix_test.go @@ -7,10 +7,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/basicTypeTest/basicPair_test.go b/test/basicTypeTest/basicPair_test.go index 8fa0130..373888a 100644 --- a/test/basicTypeTest/basicPair_test.go +++ b/test/basicTypeTest/basicPair_test.go @@ -8,10 +8,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) @@ -808,7 +808,7 @@ func Test_Pair_DownLoad_decimal32(t *testing.T) { decimal32Val := val[i].(*model.Decimal32) So(decimal32Val.Scale, ShouldEqual, 2) } - So(result.Vector.Data.StringList()[0], ShouldEqual, "-3.15") + So(result.Vector.Data.StringList()[0], ShouldEqual, "-3.16") So(result.Vector.Data.StringList()[1], ShouldEqual, "1.40") reType := result.GetDataType() So(reType, ShouldEqual, 37) @@ -840,7 +840,7 @@ func Test_Pair_DownLoad_decimal32(t *testing.T) { decimal32Val := val[i].(*model.Decimal32) So(decimal32Val.Scale, ShouldEqual, 2) } - So(result.Vector.Data.StringList()[0], ShouldEqual, "-3.15") + So(result.Vector.Data.StringList()[0], ShouldEqual, "-3.16") So(result.Vector.Data.StringList()[1], ShouldEqual, "") reType := result.GetDataType() So(reType, ShouldEqual, 37) diff --git a/test/basicTypeTest/basicScalar_test.go b/test/basicTypeTest/basicScalar_test.go index de1c96b..a597942 100644 --- a/test/basicTypeTest/basicScalar_test.go +++ b/test/basicTypeTest/basicScalar_test.go @@ -7,10 +7,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) @@ -1394,7 +1394,7 @@ func Test_Scalar_DownLoad_Datatype_decimal32(t *testing.T) { decimal32Val := &model.Decimal32s{Scale: 2, Value: []float64{2.36510}} So(re.(*model.Decimal32).Scale, ShouldEqual, decimal32Val.Scale) - So(result.String(), ShouldEqual, "decimal32(2.36)") + So(result.String(), ShouldEqual, "decimal32(2.37)") So(reType, ShouldEqual, 37) reTypeString := result.GetDataTypeString() So(reTypeString, ShouldEqual, "decimal32") @@ -1440,7 +1440,7 @@ func Test_Scalar_DownLoad_Datatype_decimal64(t *testing.T) { decimal64Val := &model.Decimal64s{Scale: 4, Value: []float64{2.36510}} So(re.(*model.Decimal64).Scale, ShouldEqual, decimal64Val.Scale) - So(result.String(), ShouldEqual, "decimal64(2.3651)") + So(result.String(), ShouldEqual, "decimal64(2.3652)") So(reType, ShouldEqual, 38) reTypeString := result.GetDataTypeString() So(reTypeString, ShouldEqual, "decimal64") @@ -1465,7 +1465,7 @@ func Test_Scalar_DownLoad_Datatype_decimal64(t *testing.T) { decimal64Val := &model.Decimal64s{Scale: 11, Value: []float64{2.3}} So(re.(*model.Decimal64).Scale, ShouldEqual, decimal64Val.Scale) - So(result.String(), ShouldEqual, "decimal64(2.29999999999)") + So(result.String(), ShouldEqual, "decimal64(2.30000000000)") So(reType, ShouldEqual, 38) reTypeString := result.GetDataTypeString() So(reTypeString, ShouldEqual, "decimal64") @@ -2345,6 +2345,7 @@ func Test_Scalar_UpLoad_Datatype_decimal32(t *testing.T) { So(err, ShouldBeNil) Convey("Test_scalar_decimal32_scale_lt_digits:", func() { dc32 := &model.Decimal32{Scale: 2, Value: -0.369545} + dt, err := model.NewDataType(model.DtDecimal32, dc32) So(err, ShouldBeNil) s := model.NewScalar(dt) @@ -2354,12 +2355,12 @@ func Test_Scalar_UpLoad_Datatype_decimal32(t *testing.T) { So(res.(*model.Scalar).Value(), ShouldBeTrue) }) Convey("Test_scalar_decimal32_scale_gt_digits:", func() { - dc32 := &model.Decimal32{Scale: 8, Value: -0.36} + dc32 := &model.Decimal32{Scale: 8, Value: -0.37} dt, err := model.NewDataType(model.DtDecimal32, dc32) So(err, ShouldBeNil) s := model.NewScalar(dt) db.Upload(map[string]model.DataForm{"s": s}) - res, err := db.RunScript("eqObj(s, decimal32(-0.36, 8))") + res, err := db.RunScript("eqObj(s, decimal32(-0.37, 8))") So(err, ShouldBeNil) So(res.(*model.Scalar).Value(), ShouldBeTrue) }) diff --git a/test/basicTypeTest/basicSet_test.go b/test/basicTypeTest/basicSet_test.go index 3ede2e2..6eaf66f 100644 --- a/test/basicTypeTest/basicSet_test.go +++ b/test/basicTypeTest/basicSet_test.go @@ -6,9 +6,9 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/basicTypeTest/basicTable_test.go b/test/basicTypeTest/basicTable_test.go index 40da550..498f20e 100644 --- a/test/basicTypeTest/basicTable_test.go +++ b/test/basicTypeTest/basicTable_test.go @@ -2,13 +2,14 @@ package test import ( "context" + "fmt" "math" "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) @@ -909,7 +910,7 @@ func Test_Table_DownLoad_DataType_decimal32(t *testing.T) { So(c1[i].(*model.Decimal32).Scale, ShouldEqual, 2) So(c2[i].(*model.Decimal32).Scale, ShouldEqual, 7) So(c1[i].(*model.Decimal32).Value, ShouldEqual, 1.23) - So(c2[i].(*model.Decimal32).Value, ShouldEqual, 1.2332399) + So(c2[i].(*model.Decimal32).Value, ShouldEqual, 1.2332400) } }) Convey("Test_Table_only_one_decimal32_columns:", func() { @@ -952,7 +953,7 @@ func Test_Table_DownLoad_DataType_decimal64(t *testing.T) { for i := 0; i < len(c1); i++ { So(c1[i].(*model.Decimal64).Scale, ShouldEqual, 2) So(c2[i].(*model.Decimal64).Scale, ShouldEqual, 11) - So(c1[i].(*model.Decimal64).Value, ShouldEqual, 1.23) + So(c1[i].(*model.Decimal64).Value, ShouldEqual, 1.24) So(c2[i].(*model.Decimal64).Value, ShouldEqual, 1.23644) } }) @@ -963,7 +964,7 @@ func Test_Table_DownLoad_DataType_decimal64(t *testing.T) { c1 := result.GetColumnByName("c1").Data.Value() for i := 0; i < len(c1); i++ { So(c1[i].(*model.Decimal64).Scale, ShouldEqual, 2) - So(c1[i].(*model.Decimal64).Value, ShouldEqual, 1.23) + So(c1[i].(*model.Decimal64).Value, ShouldEqual, 1.24) } }) Convey("Test_Table_only_one_decimal64_null_columns:", func() { @@ -2436,6 +2437,7 @@ func Test_Table_UpLoad_DataType_decimal32(t *testing.T) { col, err := model.NewDataTypeListFromRawData(model.DtDecimal32, &model.Decimal32s{2, []float64{2.215512, -1.3, model.NullDecimal32Value}}) So(err, ShouldBeNil) tb := model.NewTable([]string{"c1"}, []*model.Vector{model.NewVector(col)}) + fmt.Println("tb:", tb) _, err = db.Upload(map[string]model.DataForm{"s": tb}) So(err, ShouldBeNil) res, _ := db.RunScript("t=table(decimal32([2.215512, -1.3, NULL], 2) as c1);eqObj(t.values(),s.values())") diff --git a/test/basicTypeTest/basicVector_test.go b/test/basicTypeTest/basicVector_test.go index b588905..ccc2827 100644 --- a/test/basicTypeTest/basicVector_test.go +++ b/test/basicTypeTest/basicVector_test.go @@ -7,9 +7,9 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) diff --git a/test/connectionPool_test.go b/test/connectionPool_test.go index 9f7b6fb..c27803f 100644 --- a/test/connectionPool_test.go +++ b/test/connectionPool_test.go @@ -9,9 +9,9 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) @@ -108,8 +108,9 @@ func TestDBConnectionPool_exception(t *testing.T) { PoolSize: 2, LoadBalance: false, } - _, err := api.NewDBConnectionPool(opt) + pool, err := api.NewDBConnectionPool(opt) So(err, ShouldNotBeNil) + So(pool, ShouldBeNil) }) Convey("Test_function_DBConnectionPool_address_nil_exception \n", func() { opt := &api.PoolOption{ @@ -119,8 +120,9 @@ func TestDBConnectionPool_exception(t *testing.T) { PoolSize: 2, LoadBalance: false, } - _, err := api.NewDBConnectionPool(opt) + pool, err := api.NewDBConnectionPool(opt) So(err, ShouldNotBeNil) + So(pool, ShouldBeNil) }) Convey("Test_function_DBConnectionPool_wrong_userName_exception \n", func() { opt := &api.PoolOption{ @@ -130,8 +132,9 @@ func TestDBConnectionPool_exception(t *testing.T) { PoolSize: 2, LoadBalance: false, } - _, err := api.NewDBConnectionPool(opt) + pool, err := api.NewDBConnectionPool(opt) So(err, ShouldNotBeNil) + So(pool, ShouldBeNil) }) Convey("Test_function_DBConnectionPool_userName_null_exception \n", func() { opt := &api.PoolOption{ @@ -141,8 +144,9 @@ func TestDBConnectionPool_exception(t *testing.T) { PoolSize: 2, LoadBalance: false, } - _, err := api.NewDBConnectionPool(opt) + pool, err := api.NewDBConnectionPool(opt) So(err, ShouldNotBeNil) + So(pool, ShouldBeNil) }) Convey("Test_function_DBConnectionPool_wrong_Password_exception \n", func() { opt := &api.PoolOption{ @@ -152,8 +156,9 @@ func TestDBConnectionPool_exception(t *testing.T) { PoolSize: 2, LoadBalance: false, } - _, err := api.NewDBConnectionPool(opt) + pool, err := api.NewDBConnectionPool(opt) So(err, ShouldNotBeNil) + So(pool, ShouldBeNil) }) Convey("Test_function_DBConnectionPool_wrong_Password_special_symbol_exception \n", func() { opt := &api.PoolOption{ @@ -163,8 +168,9 @@ func TestDBConnectionPool_exception(t *testing.T) { PoolSize: 2, LoadBalance: false, } - _, err := api.NewDBConnectionPool(opt) + pool, err := api.NewDBConnectionPool(opt) So(err, ShouldNotBeNil) + So(pool, ShouldBeNil) }) Convey("Test_function_DBConnectionPool_PoolSize_less_than_0_exception", func() { opt := &api.PoolOption{ @@ -174,8 +180,9 @@ func TestDBConnectionPool_exception(t *testing.T) { PoolSize: -1, LoadBalance: false, } - _, err := api.NewDBConnectionPool(opt) + pool, err := api.NewDBConnectionPool(opt) So(err, ShouldNotBeNil) + So(pool, ShouldBeNil) }) Convey("Test_function_DBConnectionPool_SetLoadBalanceAddress_LoadBalance_false_exception", func() { OriginConnectionNum := GetOriginConnNum() @@ -291,7 +298,6 @@ func TestDBConnectionPool_SetLoadBalanceAddress(t *testing.T) { } func TestDBConnectionPool_hash_hash_string(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_hash_hash_string", t, func() { _, err := globalConn.RunScript("t = table(timestamp(1..10) as datev,string(1..10) as sym)\n" + @@ -349,7 +355,6 @@ func TestDBConnectionPool_hash_hash_string(t *testing.T) { } func TestDBConnectionPool_value_hash_symbol(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_value_hash_symbol", t, func() { _, err := globalConn.RunScript("t = table(timestamp(1..10) as datev,string(1..10) as sym)\n" + @@ -365,7 +370,7 @@ func TestDBConnectionPool_value_hash_symbol(t *testing.T) { UserID: setup.UserName, Password: setup.Password, PoolSize: 3, - LoadBalance: true, + LoadBalance: false, } pool, err := api.NewDBConnectionPool(opt) So(err, ShouldBeNil) @@ -407,7 +412,6 @@ func TestDBConnectionPool_value_hash_symbol(t *testing.T) { } func TestDBConnectionPool_hash_hash_int(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_hash_hash_int", t, func() { _, err := globalConn.RunScript("t = table(timestamp(1..10) as datev,1..10 as sym)\n" + @@ -423,7 +427,7 @@ func TestDBConnectionPool_hash_hash_int(t *testing.T) { UserID: setup.UserName, Password: setup.Password, PoolSize: 3, - LoadBalance: true, + LoadBalance: false, } pool, err := api.NewDBConnectionPool(opt) So(err, ShouldBeNil) @@ -465,7 +469,6 @@ func TestDBConnectionPool_hash_hash_int(t *testing.T) { } func TestDBConnectionPool_value_hash_datetime(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_value_hash_datetime", t, func() { _, err := globalConn.RunScript("\n" + @@ -527,7 +530,6 @@ func TestDBConnectionPool_value_hash_datetime(t *testing.T) { } func TestDBConnectionPool_range_hash_date(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_range_hash_date", t, func() { _, err := globalConn.RunScript("t = table(date(1..10) as datev,symbol(string(1..10)) as sym)\n" + @@ -588,7 +590,6 @@ func TestDBConnectionPool_range_hash_date(t *testing.T) { } func TestDBConnectionPool_range_range_int(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_range_range_int", t, func() { _, err := globalConn.RunScript("\n" + @@ -650,7 +651,6 @@ func TestDBConnectionPool_range_range_int(t *testing.T) { } func TestDBConnectionPool_value_range_int(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_value_range_int", t, func() { _, err := globalConn.RunScript("\n" + @@ -712,7 +712,6 @@ func TestDBConnectionPool_value_range_int(t *testing.T) { } func TestDBConnectionPool_range_range_month(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_range_range_month", t, func() { _, err := globalConn.RunScript("\n" + @@ -774,7 +773,6 @@ func TestDBConnectionPool_range_range_month(t *testing.T) { } func TestDBConnectionPool_hash_range_date(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_hash_range_date", t, func() { _, err := globalConn.RunScript("\n" + @@ -836,7 +834,6 @@ func TestDBConnectionPool_hash_range_date(t *testing.T) { } func TestDBConnectionPool_hash_range_datetime(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_hash_range_datetime", t, func() { _, err := globalConn.RunScript("\n" + @@ -898,7 +895,6 @@ func TestDBConnectionPool_hash_range_datetime(t *testing.T) { } func TestDBConnectionPool_hash_value_symbol(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_hash_value_symbol", t, func() { _, err := globalConn.RunScript("\n" + @@ -960,7 +956,6 @@ func TestDBConnectionPool_hash_value_symbol(t *testing.T) { } func TestDBConnectionPool_value_value_date(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_value_value_date", t, func() { _, err := globalConn.RunScript("\n" + @@ -1022,7 +1017,6 @@ func TestDBConnectionPool_value_value_date(t *testing.T) { } func TestDBConnectionPool_value_value_month(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_value_value_month", t, func() { _, err := globalConn.RunScript("\n" + @@ -1084,7 +1078,6 @@ func TestDBConnectionPool_value_value_month(t *testing.T) { } func TestDBConnectionPool_range_value_int(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_range_value_int", t, func() { _, err := globalConn.RunScript("\n" + @@ -1146,7 +1139,6 @@ func TestDBConnectionPool_range_value_int(t *testing.T) { } func TestDBConnectionPool_loadBalance_false(t *testing.T) { - t.Parallel() dbname := generateRandomString(8) Convey("TestDBConnectionPool_loadBalance_false", t, func() { _, err := globalConn.RunScript("\n" + @@ -1208,7 +1200,6 @@ func TestDBConnectionPool_loadBalance_false(t *testing.T) { } func TestPartitionedTableAppender(t *testing.T) { - t.Parallel() Convey("Test_function_PartitionedTableAppender_prepare", t, func() { Convey("Test_function_PartitionedTableAppender_range_int", func() { dbname := generateRandomString(8) @@ -1258,6 +1249,7 @@ func TestPartitionedTableAppender(t *testing.T) { So(resultPrice, ShouldResemble, model.NewVector(price)) err = pool.Close() So(err, ShouldBeNil) + globalConn.RunScript("dropDatabase('dfs://" + dbname + "')") }) Convey("Test_function_PartitionedTableAppender_value_symbol", func() { dbname := generateRandomString(8) @@ -1307,6 +1299,7 @@ func TestPartitionedTableAppender(t *testing.T) { So(resultPrice, ShouldResemble, model.NewVector(price)) err = pool.Close() So(err, ShouldBeNil) + globalConn.RunScript("dropDatabase('dfs://" + dbname + "')") }) Convey("Test_function_PartitionedTableAppender_hash_symbol", func() { dbname := generateRandomString(8) @@ -1356,6 +1349,7 @@ func TestPartitionedTableAppender(t *testing.T) { So(resultPrice, ShouldResemble, model.NewVector(price)) err = pool.Close() So(err, ShouldBeNil) + globalConn.RunScript("dropDatabase('dfs://" + dbname + "')") }) Convey("Test_function_PartitionedTableAppender_list_symbol", func() { dbname := generateRandomString(8) @@ -1405,6 +1399,7 @@ func TestPartitionedTableAppender(t *testing.T) { So(resultPrice, ShouldResemble, model.NewVector(price)) err = pool.Close() So(err, ShouldBeNil) + globalConn.RunScript("dropDatabase('dfs://" + dbname + "')") }) Convey("Test_function_PartitionedTableAppender_compo_value_list_symbol", func() { dbname := generateRandomString(8) @@ -1455,6 +1450,7 @@ func TestPartitionedTableAppender(t *testing.T) { So(resultPrice, ShouldResemble, model.NewVector(price)) err = pool.Close() So(err, ShouldBeNil) + globalConn.RunScript("dropDatabase('dfs://" + dbname + "')") }) Convey("Test_function_PartitionedTableAppender_arraVector", func() { @@ -1531,12 +1527,12 @@ func TestPartitionedTableAppender(t *testing.T) { So(err, ShouldBeNil) _, err = globalConn.RunScript(`undef('origin_tab', SHARED)`) So(err, ShouldBeNil) + globalConn.RunScript("dropDatabase('" + dbpath + "')") }) }) } func TestDBConnectionPool_task(t *testing.T) { - t.Parallel() Convey("TestDBConnectionPool_task_equal_PoolSize", t, func() { dbname := generateRandomString(8) _, err := globalConn.RunScript("db_path = \"dfs://" + dbname + "\";\n" + @@ -1584,6 +1580,7 @@ func TestDBConnectionPool_task(t *testing.T) { So(err, ShouldBeNil) closed = pool.IsClosed() So(closed, ShouldBeTrue) + globalConn.RunScript("dropDatabase('dfs://" + dbname + "')") }) Convey("TestDBConnectionPool_task_large_than_PoolSize", t, func() { dbname := generateRandomString(8) @@ -1632,19 +1629,18 @@ func TestDBConnectionPool_task(t *testing.T) { So(err, ShouldBeNil) closed = pool.IsClosed() So(closed, ShouldBeTrue) + globalConn.RunScript("dropDatabase('dfs://" + dbname + "')") }) } func TestTableAppender(t *testing.T) { - t.Parallel() Convey("Test_function_TableAppender_prepare", t, func() { Convey("Test_function_TableAppender_range_int", func() { - _, err := globalConn.RunScript(` - t = table(100:0, ["sym", "id", "datev", "price"],[SYMBOL, INT, DATE, DOUBLE]) - `) + tb := "test_akldwjgof" + _, err := globalConn.RunScript(tb + `= table(100:0, ["sym", "id", "datev", "price"],[SYMBOL, INT, DATE, DOUBLE])`) So(err, ShouldBeNil) appenderOpt := &api.TableAppenderOption{ - TableName: "t", + TableName: tb, Conn: globalConn, } appender := api.NewTableAppender(appenderOpt) @@ -1660,7 +1656,7 @@ func TestTableAppender(t *testing.T) { // fmt.Println(newtable) _, err = appender.Append(newtable) So(err, ShouldBeNil) - re, err := globalConn.RunScript("t") + re, err := globalConn.RunScript(tb) So(err, ShouldBeNil) resultTable := re.(*model.Table) resultSym := resultTable.GetColumnByName("sym").Data.Value() @@ -1731,7 +1727,7 @@ func TestTableAppender(t *testing.T) { So(err, ShouldBeNil) IsClose = appender.IsClosed() So(IsClose, ShouldBeTrue) - globalConnx.Close() + So(globalConnx.IsClosed(), ShouldBeTrue) }) Convey("Test_function_TableAppender_dfsTable", func() { globalConnx, err := api.NewSimpleDolphinDBClient(context.TODO(), host1, setup.UserName, setup.Password) @@ -1779,16 +1775,17 @@ func TestTableAppender(t *testing.T) { So(resultDatev, ShouldResemble, model.NewVector(datev)) resultPrice := resultTable.GetColumnByName("price") So(resultPrice, ShouldResemble, model.NewVector(price)) - err = pool.Close() + _, err = globalConnx.RunScript("dropDatabase('" + DfsDBPath + "')") So(err, ShouldBeNil) - err = globalConnx.Close() + err = pool.Close() So(err, ShouldBeNil) + globalConnx.Close() + So(globalConnx.IsClosed(), ShouldBeTrue) }) }) } func TestConnnectionPoolHighAvailability(t *testing.T) { - t.Parallel() SkipConvey("TestConnnectionPoolHighAvailability", t, func() { opt := &api.PoolOption{ Address: setup.Address4, @@ -1862,7 +1859,6 @@ func TestConnnectionPoolHighAvailability(t *testing.T) { } func TestConnnectionPooltimeOut(t *testing.T) { - t.Parallel() Convey("TestConnnectionPooltimeOut_timeoutOption", t, func() { opt := &api.PoolOption{ Address: setup.Address4, @@ -1908,10 +1904,10 @@ func TestConnnectionPooltimeOut(t *testing.T) { for i := 0; i < 10; i++ { succeed := false for { - if tasks[i].IsSuccess(){ + if tasks[i].IsSuccess() { succeed = true break - }else{ + } else { time.Sleep(3 * time.Second) break } @@ -1919,7 +1915,7 @@ func TestConnnectionPooltimeOut(t *testing.T) { if succeed { re := tasks[i].GetResult() So(re.(*model.Scalar).Value().(int32), ShouldEqual, int32(2)) - }else{ + } else { threadErr := tasks[i].GetError().Error() So(threadErr, ShouldContainSubstring, "timeout") } @@ -1938,5 +1934,4 @@ func TestConnnectionPooltimeOut(t *testing.T) { So(err.Error(), ShouldContainSubstring, "Timeout must be equal or greater than 0") }) - } diff --git a/test/createDatabase_test.go b/test/createDatabase_test.go index de69922..075b249 100644 --- a/test/createDatabase_test.go +++ b/test/createDatabase_test.go @@ -6,46 +6,96 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) var host2 = getRandomClusterAddress() -func TestExistsDatabase_ex(t *testing.T) { + +func TestExistsDatabase(t *testing.T) { t.Parallel() + ddb, _ := api.NewSimpleDolphinDBClient(context.TODO(), host2, setup.UserName, setup.Password) Convey("Test_ExistsDatabase_ex", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host2, setup.UserName, setup.Password) - So(err, ShouldBeNil) - _, err = ExistsDatabase(ddb, "''''''''") - So(err, ShouldNotBeNil) + q := api.ExistsDatabaseRequest{ + Path: "''''''''", + } + res, err := ddb.ExistsDatabase(&q) + So(res, ShouldBeFalse) So(err.Error(), ShouldEqual, `client error response. existsDatabase(["","","","",""]) => Usage: existsDatabase(dbUrl). dbUrl must be a local path or a dfs path.`) - ddb.Close() }) + Convey("Test_ExistsDatabase_false", t, func() { + q := api.ExistsDatabaseRequest{ + Path: "dfs://DLFJBNWQQQ_TEST", + } + res, err := ddb.ExistsDatabase(&q) + So(res, ShouldBeFalse) + So(err, ShouldBeNil) + + }) + Convey("Test_ExistsDatabase_true", t, func() { + ddb.RunScript("db = database('dfs://test_existsDB', VALUE, 1..10)") + defer ddb.RunScript("dropDatabase('dfs://test_existsDB')") + q := api.ExistsDatabaseRequest{ + Path: "dfs://test_existsDB", + } + res, err := ddb.ExistsDatabase(&q) + So(res, ShouldBeTrue) + So(err, ShouldBeNil) + ddb.RunScript("dropDatabase('dfs://test_existsDB')") + }) + ddb.Close() } -func TestExistsTable_ex(t *testing.T) { +func TestExistsTable(t *testing.T) { t.Parallel() - Convey("Test_TestExistsTable_ex", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host2, setup.UserName, setup.Password) + ddb, _ := api.NewSimpleDolphinDBClient(context.TODO(), host2, setup.UserName, setup.Password) + Convey("Test_ExistsTable_ex", t, func() { + q := api.ExistsTableRequest{ + DBPath: "''''''''", + TableName: "t", + } + res, err := ddb.ExistsTable(&q) + So(res, ShouldBeFalse) + So(err.Error(), ShouldEqual, `client error response. existsTable(["","","","",""], 't') => Usage: existsTable(dbUrl, tableName). dbUrl must be a local path or a dfs path.`) + }) + Convey("Test_ExistsTable_false", t, func() { + q := api.ExistsTableRequest{ + DBPath: "dfs://DLFJBNWQQQ_TEST", + TableName: "test_existsTable", + } + res, err := ddb.ExistsTable(&q) + So(res, ShouldBeFalse) So(err, ShouldBeNil) - _, err = ddb.RunScript(fmt.Sprintf("existsTable('%s','%s')", "''", "tables")) - So(err, ShouldNotBeNil) - So(err.Error(), ShouldEqual, `client error response. existsTable(["",""], "tables") => Usage: existsTable(dbUrl, tableName). dbUrl must be a local path or a dfs path.`) - ddb.Close() }) + Convey("Test_ExistsTable_true", t, func() { + ddb.RunScript("db = database('dfs://test_existsTable', VALUE, 1..10); db.createTable(table(1 2 3 as c1), `test_existsTable)") + defer ddb.RunScript("dropDatabase('dfs://test_existsTable')") + q := api.ExistsTableRequest{ + DBPath: "dfs://test_existsTable", + TableName: "test_existsTable", + } + res, err := ddb.ExistsTable(&q) + So(res, ShouldBeTrue) + So(err, ShouldBeNil) + ddb.RunScript("dropDatabase('dfs://test_existsTable')") + }) + ddb.Close() } func TestCreateDatabase_ex(t *testing.T) { t.Parallel() - Convey("Test_CreateDatabase_ex", t, func() { + Convey("Test_CreateDatabase_ex1", t, func() { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host2, setup.UserName, setup.Password) So(err, ShouldBeNil) - _, err = ddb.RunScript(fmt.Sprintf("%s=database(%s)", DBhandler, "db")) - So(err, ShouldNotBeNil) - So(err.Error(), ShouldEqual, `client error response. db = database(db) => Variable 'db' isn't initialized yet.`) + q := api.DatabaseRequest{ + DBHandle: "db", + } + db, err := ddb.Database(&q) + So(db, ShouldBeNil) + So(err.Error(), ShouldContainSubstring, `The function [database] expects 1~7 argument(s), but the actual number of arguments is: 0`) ddb.Close() }) } @@ -55,9 +105,11 @@ func TestDropDatabase_ex(t *testing.T) { Convey("Test_DropDataBase_ex", t, func() { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host2, setup.UserName, setup.Password) So(err, ShouldBeNil) - _, err = ddb.RunScript(fmt.Sprintf("dropDatabase('%s')", "nj")) - So(err, ShouldNotBeNil) - So(err.Error(), ShouldEqual, `client error response. dropDatabase("nj") => There is no database in the directory nj`) + q := api.DropDatabaseRequest{ + Directory: "abcd", + } + err = ddb.DropDatabase(&q) + So(err.Error(), ShouldEqual, `client error response. dropDatabase("abcd") => There is no database in the directory abcd`) ddb.Close() }) } @@ -85,12 +137,12 @@ func TestCreateDatabase(t *testing.T) { }) Convey("Test_CreateDatabase_olap_value_partition", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - database, err := CreateDatabase(ddb, DfsDBPath, DBhandler, "VALUE", "2010.01.01..2010.01.30", "", "", "") + database, err := ddb.Database(&api.DatabaseRequest{DBHandle: "db", Directory: DfsDBPath, PartitionType: "VALUE", PartitionScheme: "2010.01.01..2010.01.30"}) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) re3, err := ddb.RunScript("schema(db)") @@ -118,10 +170,15 @@ func TestCreateDatabase(t *testing.T) { So(reDatabaseDir.Value().(*model.Scalar).Value(), ShouldEqual, DfsDBPath) _, err = ddb.RunScript("n=10") So(err, ShouldBeNil) - _, err = CreateMemTable(ddb, "t", "datev", "id", "sym", "val", "sort(take(2010.01.01..2010.12.31, n))", "1..n", `take(["AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"], n)`, "take([39, 50, 5, 24, 79, 39, 8, 67, 29, 55], n)") + _, err = ddb.Table(&api.TableRequest{TableName: "t", TableParams: []api.TableParam{ + {Key: "datev", Value: "sort(take(2010.01.01..2010.12.31, n))"}, + {Key: "int", Value: "1..n"}, + {Key: "sym", Value: `take(["AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"], n)`}, + {Key: "val", Value: "take([39, 50, 5, 24, 79, 39, 8, 67, 29, 55], n)"}, + }}) So(err, ShouldBeNil) // create dfsTable - dfsTable, err := CreateDefPartitionedTable(database, "t", DfsTBName1, []string{"datev"}) + dfsTable, err := database.CreatePartitionedTable(&api.CreatePartitionedTableRequest{SrcTable: "t", PartitionedTableName: DfsTBName1, PartitionColumns: []string{"datev"}}) So(err, ShouldBeNil) resultDatev := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) So(resultDatev.Data.IsNull(0), ShouldBeTrue) @@ -133,7 +190,7 @@ func TestCreateDatabase(t *testing.T) { So(resultVal.Data.IsNull(0), ShouldBeTrue) _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + DfsTBName1 + `").append!(t)`) So(err, ShouldBeNil) - newdfstable, err := LoadPartitionedTable(ddb, DfsTBName1, DfsDBPath) + newdfstable, err := ddb.LoadTable(&api.LoadTableRequest{Database: DfsDBPath, TableName: DfsTBName1}) So(err, ShouldBeNil) for i := 1; i <= 10; i++ { resultDatev = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) @@ -161,11 +218,11 @@ func TestCreateDatabase(t *testing.T) { assert.Equal(t, re[i], tmpVal[i]) } // create dimensionTable - _, err = CreateTable(database, "t", TbName1) + _, err = database.CreateTable(&api.CreateTableRequest{SrcTable: "t", DimensionTableName: TbName1}) So(err, ShouldBeNil) _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `").append!(t)`) So(err, ShouldBeNil) - dimensionTable, err := LoadTable(ddb, TbName1, DfsDBPath) + dimensionTable, err := ddb.LoadTable(&api.LoadTableRequest{Database: DfsDBPath, TableName: TbName1}) So(err, ShouldBeNil) for i := 1; i <= 10; i++ { resultDatev = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) @@ -192,27 +249,31 @@ func TestCreateDatabase(t *testing.T) { for i := 0; i < resultVal.Rows(); i++ { assert.Equal(t, re[i], tmpVal[i]) } - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re6, err := ExistsDatabase(ddb, DfsDBPath) + re6, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re6, ShouldBeFalse) }) - Convey("Test_CreateDatabase_olap_range_partition", func() { + Convey("Test_CreateDatabase_tsdb_compo_partition", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - database, err := CreateDatabase(ddb, DfsDBPath, DBhandler, "RANGE", "0 3 5 10", "", "", "") + _, err = ddb.Database(&api.DatabaseRequest{DBHandle: "db1", PartitionType: "RANGE", PartitionScheme: "0 3 5 10"}) + So(err, ShouldBeNil) + _, err = ddb.Database(&api.DatabaseRequest{DBHandle: "db2", PartitionType: "VALUE", PartitionScheme: "`AMD`QWE`CES"}) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + database, err := ddb.Database(&api.DatabaseRequest{DBHandle: "db", Directory: DfsDBPath, PartitionType: "COMPO", PartitionScheme: "[db1,db2]", Engine: "TSDB"}) + So(err, ShouldBeNil) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) re3, err := ddb.RunScript("schema(db)") So(err, ShouldBeNil) re4 := re3.(*model.Dictionary) rePartitionType, _ := re4.Get("partitionType") - So(rePartitionType.Value().(*model.Scalar).Value(), ShouldEqual, 2) + So(rePartitionType.Value().(*model.Vector).String(), ShouldEqual, "vector([2, 1])") reChunkGranularity, _ := re4.Get("chunkGranularity") So(reChunkGranularity.Value().(*model.Scalar).Value(), ShouldEqual, "TABLE") reAtomic, _ := re4.Get("atomic") @@ -220,20 +281,23 @@ func TestCreateDatabase(t *testing.T) { rePartitionSites, _ := re4.Get("partitionSites") So(rePartitionSites.Value().(*model.Scalar).IsNull(), ShouldBeTrue) rePartitionTypeName, _ := re4.Get("partitionTypeName") - So(rePartitionTypeName.Value().(*model.Scalar).Value(), ShouldEqual, "RANGE") + So(rePartitionTypeName.Value().(*model.Vector).String(), ShouldEqual, "vector([RANGE, VALUE])") rePartitionSchema, _ := re4.Get("partitionSchema") - tmpPartitionSchema := []int{0, 3, 5, 10} - for i := 0; i < len(rePartitionSchema.Value().(*model.Vector).Data.Value()); i++ { - So(rePartitionSchema.Value().(*model.Vector).Data.Value()[i], ShouldEqual, tmpPartitionSchema[i]) - } + + So(rePartitionSchema.String(), ShouldEqual, "vector([vector([0, 3, 5, 10]), vector([AMD, CES, QWE])])") reDatabaseDir, _ := re4.Get("databaseDir") So(reDatabaseDir.Value().(*model.Scalar).Value(), ShouldEqual, DfsDBPath) _, err = ddb.RunScript("n=10") So(err, ShouldBeNil) - _, err = CreateMemTable(ddb, "t", "datev", "id", "sym", "val", "take(2010.01.01..2010.01.31, n)", "[1,4,5,5,6,6,6,6,8,8]", `take(["AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"], n)`, "take([39, 50, 5, 24, 79, 39, 8, 67, 29, 55], n)") + _, err = ddb.Table(&api.TableRequest{TableName: "t", TableParams: []api.TableParam{ + {Key: "datev", Value: "sort(take(2010.01.01..2010.01.31, n))"}, + {Key: "id", Value: "1..n"}, + {Key: "sym", Value: `take(["AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"], n)`}, + {Key: "val", Value: "take([39, 50, 5, 24, 79, 39, 8, 67, 29, 55], n)"}, + }}) So(err, ShouldBeNil) // create dfsTable - dfsTable, err := CreateDefPartitionedTable(database, "t", DfsTBName1, []string{"id"}) + dfsTable, err := database.CreatePartitionedTable(&api.CreatePartitionedTableRequest{SrcTable: "t", PartitionedTableName: DfsTBName1, PartitionColumns: []string{"id", "sym"}, SortColumns: []string{"datev"}}) So(err, ShouldBeNil) resultDatev := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) So(resultDatev.Data.IsNull(0), ShouldBeTrue) @@ -245,39 +309,39 @@ func TestCreateDatabase(t *testing.T) { So(resultVal.Data.IsNull(0), ShouldBeTrue) _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + DfsTBName1 + `").append!(t)`) So(err, ShouldBeNil) - newdfstable, err := LoadPartitionedTable(ddb, DfsTBName1, DfsDBPath) + newdfstable, err := ddb.LoadTable(&api.LoadTableRequest{Database: DfsDBPath, TableName: DfsTBName1}) So(err, ShouldBeNil) - for i := 1; i <= 10; i++ { - resultDatev = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - re := resultDatev.Data.Value() - datev := time.Date(2010, time.January, i, 0, 0, 0, 0, time.UTC) - tmp := []time.Time{datev} - assert.Equal(t, re[i-1], tmp[0]) + tmp, _ := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + DfsTBName1 + `")`) + for i := 0; i < newdfstable.Data.Columns(); i++ { + res := newdfstable.Data.GetColumnByIndex(i).Data.Value() + ex := tmp.(*model.Table).GetColumnByIndex(i).Data.Value() + So(res, ShouldResemble, ex) } resultInt = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) re := resultInt.Data.Value() - tmpInt := []int32{1, 4, 5, 5, 6, 6, 6, 6, 8, 8} + tmpInt := []int32{1, 2, 3, 4, 5, 8, 7, 9, 6} for i := 0; i < resultInt.Rows(); i++ { So(re[i], ShouldEqual, tmpInt[i]) } resultSym = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) re = resultSym.Data.Value() - tmpSym := []string{"AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS", "AMD"} + + tmpSym := []string{"AMD", "QWE", "CES", "DOP", "ASZ", "AWQ", "BBVC", "DS", "FSD"} for i := 0; i < resultSym.Rows(); i++ { So(re[i], ShouldEqual, tmpSym[i]) } resultVal = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) re = resultVal.Data.Value() - tmpVal := []int32{39, 50, 5, 24, 79, 39, 8, 67, 29, 55} + tmpVal := []int32{39, 50, 5, 24, 79, 67, 8, 29, 39} for i := 0; i < resultVal.Rows(); i++ { - assert.Equal(t, re[i], tmpVal[i]) + So(re[i], ShouldEqual, tmpVal[i]) } // create dimensionTable - _, err = CreateTable(database, "t", TbName1) + _, err = database.CreateTable(&api.CreateTableRequest{SrcTable: "t", DimensionTableName: TbName1, SortColumns: []string{"datev"}}) So(err, ShouldBeNil) _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `").append!(t)`) So(err, ShouldBeNil) - dimensionTable, err := LoadTable(ddb, TbName1, DfsDBPath) + dimensionTable, err := ddb.LoadTable(&api.LoadTableRequest{Database: DfsDBPath, TableName: TbName1}) So(err, ShouldBeNil) for i := 1; i <= 10; i++ { resultDatev = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) @@ -288,12 +352,14 @@ func TestCreateDatabase(t *testing.T) { } resultInt = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) re = resultInt.Data.Value() - tmpInt = []int32{1, 4, 5, 5, 6, 6, 6, 6, 8, 8} + + tmpInt = []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} for i := 0; i < resultInt.Rows(); i++ { So(re[i], ShouldEqual, tmpInt[i]) } resultSym = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) re = resultSym.Data.Value() + fmt.Println(re) tmpSym = []string{"AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS", "AMD"} for i := 0; i < resultSym.Rows(); i++ { So(re[i], ShouldEqual, tmpSym[i]) @@ -304,352 +370,16 @@ func TestCreateDatabase(t *testing.T) { for i := 0; i < resultVal.Rows(); i++ { assert.Equal(t, re[i], tmpVal[i]) } - err = DropDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - re6, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re6, ShouldBeFalse) - }) - Convey("Test_CreateDatabase_olap_hash_partition", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re1, ShouldBeFalse) - database, err := CreateDatabase(ddb, DfsDBPath, DBhandler, "HASH", "[INT, 3]", "", "", "") - So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re2, ShouldBeTrue) - re3, err := ddb.RunScript("schema(db)") - So(err, ShouldBeNil) - re4 := re3.(*model.Dictionary) - rePartitionType, _ := re4.Get("partitionType") - So(rePartitionType.Value().(*model.Scalar).Value(), ShouldEqual, 5) - reChunkGranularity, _ := re4.Get("chunkGranularity") - So(reChunkGranularity.Value().(*model.Scalar).Value(), ShouldEqual, "TABLE") - reAtomic, _ := re4.Get("atomic") - So(reAtomic.Value().(*model.Scalar).Value(), ShouldEqual, "TRANS") - rePartitionSites, _ := re4.Get("partitionSites") - So(rePartitionSites.Value().(*model.Scalar).IsNull(), ShouldBeTrue) - rePartitionTypeName, _ := re4.Get("partitionTypeName") - So(rePartitionTypeName.Value().(*model.Scalar).Value(), ShouldEqual, "HASH") - rePartitionSchema, _ := re4.Get("partitionSchema") - So(rePartitionSchema.Value().(*model.Scalar).Value(), ShouldEqual, 3) - reDatabaseDir, _ := re4.Get("databaseDir") - So(reDatabaseDir.Value().(*model.Scalar).Value(), ShouldEqual, DfsDBPath) - _, err = ddb.RunScript("n=10") - So(err, ShouldBeNil) - _, err = CreateMemTable(ddb, "t", "datev", "id", "sym", "val", "take(2010.01.01..2010.01.31, n)", "[1,4,5,5,6,6,6,6,8,8]", `take(["AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"], n)`, "take([39, 50, 5, 24, 79, 39, 8, 67, 29, 55], n)") - So(err, ShouldBeNil) - // create dfsTable - dfsTable, err := CreateDefPartitionedTable(database, "t", DfsTBName1, []string{"id"}) - So(err, ShouldBeNil) - resultDatev := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - So(resultDatev.Data.IsNull(0), ShouldBeTrue) - resultInt := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - So(resultInt.Data.IsNull(0), ShouldBeTrue) - resultSym := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - So(resultSym.Data.IsNull(0), ShouldBeTrue) - resultVal := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - So(resultVal.Data.IsNull(0), ShouldBeTrue) - _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + DfsTBName1 + `").append!(t)`) - So(err, ShouldBeNil) - newdfstable, err := LoadPartitionedTable(ddb, DfsTBName1, DfsDBPath) - So(err, ShouldBeNil) - - resultDatev = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - re := resultDatev.String() - So(re, ShouldEqual, "vector([2010.01.05, 2010.01.06, 2010.01.07, 2010.01.08, 2010.01.01, 2010.01.02, 2010.01.03, 2010.01.04, 2010.01.09, 2010.01.10])") - - resultInt = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - reInt := resultInt.Data.Value() - tmpInt := []int32{6, 6, 6, 6, 1, 4, 5, 5, 8, 8} - for i := 0; i < resultInt.Rows(); i++ { - So(reInt[i], ShouldEqual, tmpInt[i]) - } - resultSym = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - resym := resultSym.Data.Value() - tmpSym := []string{"ASZ", "FSD", "BBVC", "AWQ", "AMD", "QWE", "CES", "DOP", "DS", "AMD"} - for i := 0; i < resultSym.Rows(); i++ { - So(resym[i], ShouldEqual, tmpSym[i]) - } - resultVal = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - reVal := resultVal.Data.Value() - tmpVal := []int32{79, 39, 8, 67, 39, 50, 5, 24, 29, 55} - for i := 0; i < resultVal.Rows(); i++ { - So(reVal[i], ShouldEqual, tmpVal[i]) - } - // create dimensionTable - _, err = CreateTable(database, "t", TbName1) - So(err, ShouldBeNil) - _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `").append!(t)`) - So(err, ShouldBeNil) - dimensionTable, err := LoadTable(ddb, TbName1, DfsDBPath) - So(err, ShouldBeNil) - for i := 1; i <= 10; i++ { - resultDatev = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - re := resultDatev.Data.Value() - datev := time.Date(2010, time.January, i, 0, 0, 0, 0, time.UTC) - tmp := []time.Time{datev} - So(re[i-1], ShouldEqual, tmp[0]) - } - resultInt = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - reInt = resultInt.Data.Value() - tmpInt = []int32{1, 4, 5, 5, 6, 6, 6, 6, 8, 8} - for i := 0; i < resultInt.Rows(); i++ { - So(reInt[i], ShouldEqual, tmpInt[i]) - } - resultSym = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - reSym := resultSym.Data.Value() - tmpSym = []string{"AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS", "AMD"} - for i := 0; i < resultSym.Rows(); i++ { - So(reSym[i], ShouldEqual, tmpSym[i]) - } - resultVal = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - reVal = resultVal.Data.Value() - tmpVal = []int32{39, 50, 5, 24, 79, 39, 8, 67, 29, 55} - for i := 0; i < resultVal.Rows(); i++ { - So(reVal[i], ShouldEqual, tmpVal[i]) - } - err = DropDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - re6, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re6, ShouldBeFalse) - }) - Convey("Test_CreateDatabase_olap_list_partition", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re1, ShouldBeFalse) - database, err := CreateDatabase(ddb, DfsDBPath, DBhandler, "LIST", "[`AMD`QWE`CES,`DOP`ASZ,`FSD`BBVC,`AWQ`DS]", "", "", "") - So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re2, ShouldBeTrue) - re3, err := ddb.RunScript("schema(db)") - So(err, ShouldBeNil) - re4 := re3.(*model.Dictionary) - rePartitionType, _ := re4.Get("partitionType") - So(rePartitionType.Value().(*model.Scalar).Value(), ShouldEqual, 3) - reChunkGranularity, _ := re4.Get("chunkGranularity") - So(reChunkGranularity.Value().(*model.Scalar).Value(), ShouldEqual, "TABLE") - reAtomic, _ := re4.Get("atomic") - So(reAtomic.Value().(*model.Scalar).Value(), ShouldEqual, "TRANS") - rePartitionSites, _ := re4.Get("partitionSites") - So(rePartitionSites.Value().(*model.Scalar).IsNull(), ShouldBeTrue) - rePartitionTypeName, _ := re4.Get("partitionTypeName") - So(rePartitionTypeName.Value().(*model.Scalar).Value(), ShouldEqual, "LIST") - rePartitionSchema, _ := re4.Get("partitionSchema") - So(rePartitionSchema.Value().(*model.Vector).String(), ShouldEqual, "vector([vector([AMD, QWE, CES]), vector([DOP, ASZ]), vector([FSD, BBVC]), vector([AWQ, DS])])") - reDatabaseDir, _ := re4.Get("databaseDir") - So(reDatabaseDir.Value().(*model.Scalar).Value(), ShouldEqual, DfsDBPath) - _, err = ddb.RunScript("n=10") - So(err, ShouldBeNil) - _, err = CreateMemTable(ddb, "t", "datev", "id", "sym", "val", "take(2010.01.01..2010.01.31, n)", "[1,4,5,5,6,6,6,6,8,8]", `take(["AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"], n)`, "take([39, 50, 5, 24, 79, 39, 8, 67, 29, 55], n)") - So(err, ShouldBeNil) - // create dfsTable - dfsTable, err := CreateDefPartitionedTable(database, "t", DfsTBName1, []string{"sym"}) - So(err, ShouldBeNil) - resultDatev := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - So(resultDatev.Data.IsNull(0), ShouldBeTrue) - resultInt := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - So(resultInt.Data.IsNull(0), ShouldBeTrue) - resultSym := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - So(resultSym.Data.IsNull(0), ShouldBeTrue) - resultVal := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - So(resultVal.Data.IsNull(0), ShouldBeTrue) - _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + DfsTBName1 + `").append!(t)`) - So(err, ShouldBeNil) - newdfstable, err := LoadPartitionedTable(ddb, DfsTBName1, DfsDBPath) - So(err, ShouldBeNil) - - resultDatev = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - re := resultDatev.String() - So(re, ShouldEqual, "vector([2010.01.01, 2010.01.02, 2010.01.03, 2010.01.10, 2010.01.04, 2010.01.05, 2010.01.06, 2010.01.07, 2010.01.08, 2010.01.09])") - - resultInt = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - reInt := resultInt.Data.Value() - tmpInt := []int32{1, 4, 5, 8, 5, 6, 6, 6, 6, 8} - for i := 0; i < resultInt.Rows(); i++ { - So(reInt[i], ShouldEqual, tmpInt[i]) - } - resultSym = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - resym := resultSym.Data.Value() - tmpSym := []string{"AMD", "QWE", "CES", "AMD", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"} - for i := 0; i < resultSym.Rows(); i++ { - So(resym[i], ShouldEqual, tmpSym[i]) - } - resultVal = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - reVal := resultVal.Data.Value() - tmpVal := []int32{39, 50, 5, 55, 24, 79, 39, 8, 67, 29} - for i := 0; i < resultVal.Rows(); i++ { - So(reVal[i], ShouldEqual, tmpVal[i]) - } - // create dimensionTable - _, err = CreateTable(database, "t", TbName1) - So(err, ShouldBeNil) - _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `").append!(t)`) - So(err, ShouldBeNil) - dimensionTable, err := LoadTable(ddb, TbName1, DfsDBPath) - So(err, ShouldBeNil) - for i := 1; i <= 10; i++ { - resultDatev = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - re := resultDatev.Data.Value() - datev := time.Date(2010, time.January, i, 0, 0, 0, 0, time.UTC) - tmp := []time.Time{datev} - So(re[i-1], ShouldEqual, tmp[0]) - } - resultInt = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - reInt = resultInt.Data.Value() - tmpInt = []int32{1, 4, 5, 5, 6, 6, 6, 6, 8, 8} - for i := 0; i < resultInt.Rows(); i++ { - So(reInt[i], ShouldEqual, tmpInt[i]) - } - resultSym = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - reSym := resultSym.Data.Value() - tmpSym = []string{"AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS", "AMD"} - for i := 0; i < resultSym.Rows(); i++ { - So(reSym[i], ShouldEqual, tmpSym[i]) - } - resultVal = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - reVal = resultVal.Data.Value() - tmpVal = []int32{39, 50, 5, 24, 79, 39, 8, 67, 29, 55} - for i := 0; i < resultVal.Rows(); i++ { - So(reVal[i], ShouldEqual, tmpVal[i]) - } - err = DropDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - re6, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re6, ShouldBeFalse) - }) - Convey("Test_CreateDatabase_olap_compo_partition", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re1, ShouldBeFalse) - _, err = CreateDatabase(ddb, "", "db1", "VALUE", "2010.01.01..2010.01.30", "", "", "") - So(err, ShouldBeNil) - _, err = CreateDatabase(ddb, "", "db2", "RANGE", "1 3 5 7 9 10", "", "", "") - So(err, ShouldBeNil) - database, err := CreateDatabase(ddb, DfsDBPath, DBhandler, "COMPO", "[db1, db2]", "", "", "") - So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - So(re2, ShouldBeTrue) - re3, err := ddb.RunScript("schema(db)") - So(err, ShouldBeNil) - re4 := re3.(*model.Dictionary) - rePartitionType, _ := re4.Get("partitionType") - So(rePartitionType.Value().(*model.Vector).String(), ShouldEqual, "vector([1, 2])") - reChunkGranularity, _ := re4.Get("chunkGranularity") - So(reChunkGranularity.Value().(*model.Scalar).Value(), ShouldEqual, "TABLE") - reAtomic, _ := re4.Get("atomic") - So(reAtomic.Value().(*model.Scalar).Value(), ShouldEqual, "TRANS") - rePartitionSites, _ := re4.Get("partitionSites") - So(rePartitionSites.Value().(*model.Scalar).IsNull(), ShouldBeTrue) - rePartitionTypeName, _ := re4.Get("partitionTypeName") - So(rePartitionTypeName.Value().(*model.Vector).String(), ShouldEqual, "vector([VALUE, RANGE])") - rePartitionSchema, _ := re4.Get("partitionSchema") - re := rePartitionSchema.Value().(*model.Vector).Get(0).Value().(*model.Vector).Data.Value() - j := 0 - for i := 1; i < 30; i++ { - datev := time.Date(2010, time.January, i, 0, 0, 0, 0, time.UTC) - tmp := []time.Time{datev} - So(re[j], ShouldEqual, tmp[0]) - j++ - } - So(rePartitionSchema.Value().(*model.Vector).Get(1).Value().(*model.Vector).String(), ShouldEqual, "vector([1, 3, 5, 7, 9, 10])") - reDatabaseDir, _ := re4.Get("databaseDir") - So(reDatabaseDir.Value().(*model.Scalar).Value(), ShouldEqual, DfsDBPath) - _, err = ddb.RunScript("n=10") - So(err, ShouldBeNil) - _, err = CreateMemTable(ddb, "t", "datev", "id", "sym", "val", "take(2010.01.01..2010.01.31, n)", "[1,4,5,5,6,6,6,6,8,8]", `take(["AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"], n)`, "take([39, 50, 5, 24, 79, 39, 8, 67, 29, 55], n)") - So(err, ShouldBeNil) - // create dfsTable - dfsTable, err := CreateDefPartitionedTable(database, "t", DfsTBName1, []string{"datev", "id"}) - So(err, ShouldBeNil) - resultDatev := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - So(resultDatev.Data.IsNull(0), ShouldBeTrue) - resultInt := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - So(resultInt.Data.IsNull(0), ShouldBeTrue) - resultSym := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - So(resultSym.Data.IsNull(0), ShouldBeTrue) - resultVal := dfsTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - So(resultVal.Data.IsNull(0), ShouldBeTrue) - _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + DfsTBName1 + `").append!(t)`) - So(err, ShouldBeNil) - newdfstable, err := LoadPartitionedTable(ddb, DfsTBName1, DfsDBPath) - So(err, ShouldBeNil) - - resultDatev = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - reDate := resultDatev.Data.Value() - for i := 1; i < resultDatev.Rows(); i++ { - datev := time.Date(2010, time.January, i, 0, 0, 0, 0, time.UTC) - tmp := []time.Time{datev} - So(reDate[i-1], ShouldEqual, tmp[0]) - } - resultInt = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - reInt := resultInt.Data.Value() - tmpInt := []int32{1, 4, 5, 5, 6, 6, 6, 6, 8, 8} - for i := 0; i < resultInt.Rows(); i++ { - So(reInt[i], ShouldEqual, tmpInt[i]) - } - resultSym = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - resym := resultSym.Data.Value() - tmpSym := []string{"AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS", "AMD"} - for i := 0; i < resultSym.Rows(); i++ { - So(resym[i], ShouldEqual, tmpSym[i]) - } - resultVal = newdfstable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - reVal := resultVal.Data.Value() - tmpVal := []int32{39, 50, 5, 24, 79, 39, 8, 67, 29, 55} - for i := 0; i < resultVal.Rows(); i++ { - So(reVal[i], ShouldEqual, tmpVal[i]) - } - // create dimensionTable - _, err = CreateTable(database, "t", TbName1) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - _, err = ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `").append!(t)`) - So(err, ShouldBeNil) - dimensionTable, err := LoadTable(ddb, TbName1, DfsDBPath) - So(err, ShouldBeNil) - for i := 1; i <= 10; i++ { - resultDatev = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[0]) - re := resultDatev.Data.Value() - datev := time.Date(2010, time.January, i, 0, 0, 0, 0, time.UTC) - tmp := []time.Time{datev} - So(re[i-1], ShouldEqual, tmp[0]) - } - resultInt = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[1]) - reInt = resultInt.Data.Value() - tmpInt = []int32{1, 4, 5, 5, 6, 6, 6, 6, 8, 8} - for i := 0; i < resultInt.Rows(); i++ { - So(reInt[i], ShouldEqual, tmpInt[i]) - } - resultSym = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[2]) - reSym := resultSym.Data.Value() - tmpSym = []string{"AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS", "AMD"} - for i := 0; i < resultSym.Rows(); i++ { - So(reSym[i], ShouldEqual, tmpSym[i]) - } - resultVal = dimensionTable.Data.GetColumnByName(dfsTable.Data.GetColumnNames()[3]) - reVal = resultVal.Data.Value() - tmpVal = []int32{39, 50, 5, 24, 79, 39, 8, 67, 29, 55} - for i := 0; i < resultVal.Rows(); i++ { - So(reVal[i], ShouldEqual, tmpVal[i]) - } - err = DropDatabase(ddb, DfsDBPath) - So(err, ShouldBeNil) - re6, err := ExistsDatabase(ddb, DfsDBPath) + re6, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re6, ShouldBeFalse) }) }) } -func TestDataBaseGetSession(t *testing.T) { +func TestDataBaseFunctions(t *testing.T) { t.Parallel() Convey("Test_CreateDatabase_prepare", t, func() { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host2, setup.UserName, setup.Password) @@ -670,15 +400,18 @@ func TestDataBaseGetSession(t *testing.T) { So(err, ShouldBeNil) } }) - Convey("Test_CreateDatabase_olap_value_partition", func() { + Convey("Test_getSession", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + db, err := ddb.Database(&api.DatabaseRequest{DBHandle: "db", Directory: DfsDBPath, PartitionType: "RANGE", PartitionScheme: "0 3 5 10"}) So(err, ShouldBeNil) - So(re1, ShouldBeFalse) - database, err := CreateDatabase(ddb, DfsDBPath, DBhandler, "VALUE", "2010.01.01..2010.01.30", "", "", "") + sname := db.GetSession() + fmt.Println(sname) + ex_sname, _ := ddb.RunScript("getCurrentSessionAndUser()[0]") + fmt.Println(ex_sname) + So("long("+sname+")", ShouldEqual, ex_sname.(*model.Scalar).String()) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - res := database.GetSession() - So(res, ShouldNotBeNil) }) + ddb.Close() }) } diff --git a/test/dbConnection_test.go b/test/dbConnection_test.go index be8c20d..5a27a1b 100644 --- a/test/dbConnection_test.go +++ b/test/dbConnection_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/dialer" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/dialer" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) @@ -113,6 +113,7 @@ func TestNewSimpleDolphinDBClient(t *testing.T) { Convey("Test NewSimpleDolphinDB login", func() { db, err := api.NewSimpleDolphinDBClient(context.TODO(), host3, setup.UserName, setup.Password) So(err, ShouldBeNil) + defer db.Close() dbName := `dfs://` + generateRandomString(10) re, err := db.RunScript( `dbName='` + dbName + `' @@ -126,14 +127,17 @@ func TestNewSimpleDolphinDBClient(t *testing.T) { result := s.DataType.Value() ex := "DB[" + dbName + "]" So(result, ShouldEqual, ex) + db.DropDatabase(&api.DropDatabaseRequest{Directory: dbName}) }) Convey("Test NewSimpleDolphinDB logout", func() { db, _ := api.NewSimpleDolphinDBClient(context.TODO(), host3, setup.UserName, setup.Password) err := db.Logout() So(err, ShouldBeNil) + defer db.Close() + dbName := `dfs://` + generateRandomString(10) re, err := db.RunScript(` - dbName="dfs://` + generateRandomString(10) + `" + dbName="` + dbName + `" if(existsDatabase(dbName)){ dropDatabase(dbName) } @@ -141,6 +145,7 @@ func TestNewSimpleDolphinDBClient(t *testing.T) { result := fmt.Errorf("\n error is %w", err) So(re, ShouldBeNil) So(result, ShouldNotBeNil) + db.DropDatabase(&api.DropDatabaseRequest{Directory: dbName}) }) }) } @@ -444,13 +449,12 @@ func TestConnectionHighAvailability(t *testing.T) { } func TestConnectionParallel(t *testing.T) { - t.Parallel() db, err := api.NewSimpleDolphinDBClient(context.TODO(), host3, "admin", "123456") AssertNil(err) - db.RunScript("login(`admin,`123456);try{createUser(`test1, `123456)}catch(ex){};go;setMaxJobParallelism(`test1, 10);") + db.RunScript("login(`admin,`123456);try{createUser(`test1, `123456)}catch(ex){};go;setMaxJobParallelism(`test1, 10);setMaxJobPriority(`test1, 6);") Convey("TestConnectionParallel_lt_MaxJobParallelism", t, func() { - priority := 4 + priority := 0 parallel := 1 opt := &dialer.BehaviorOptions{ Priority: &priority, @@ -468,7 +472,7 @@ func TestConnectionParallel(t *testing.T) { res, _ := conn.RunScript("getConsoleJobs()") Println(res) So(res.(*model.Table).GetColumnByName("parallelism").Get(0).Value().(int32), ShouldEqual, 1) - So(res.(*model.Table).GetColumnByName("priority").Get(0).Value().(int32), ShouldEqual, 4) + So(res.(*model.Table).GetColumnByName("priority").Get(0).Value().(int32), ShouldEqual, 0) conn.Close() So(conn.IsClosed(), ShouldBeTrue) @@ -476,7 +480,7 @@ func TestConnectionParallel(t *testing.T) { Convey("TestConnectionParallel_gt_MaxJobParallelism", t, func() { - priority := 4 + priority := 8 parallel := 11 opt := &dialer.BehaviorOptions{ Priority: &priority, @@ -494,7 +498,7 @@ func TestConnectionParallel(t *testing.T) { res, _ := conn.RunScript("getConsoleJobs()") Println(res) So(res.(*model.Table).GetColumnByName("parallelism").Get(0).Value().(int32), ShouldEqual, 10) - So(res.(*model.Table).GetColumnByName("priority").Get(0).Value().(int32), ShouldEqual, 4) + So(res.(*model.Table).GetColumnByName("priority").Get(0).Value().(int32), ShouldEqual, 6) conn.Close() So(conn.IsClosed(), ShouldBeTrue) @@ -518,7 +522,133 @@ func TestConnectionParallel(t *testing.T) { conn.Close() So(conn.IsClosed(), ShouldBeTrue) }) + Convey("TestConnection_priority_10", t, func() { + priority := 10 + opt := &dialer.BehaviorOptions{ + Priority: &priority, + } + conn, err := api.NewDolphinDBClient(context.TODO(), host3, opt) + So(err, ShouldNotBeNil) + result := fmt.Errorf("\n exception error is %w", err) + fmt.Println(result.Error()) + expectedErrMsg := "the job priority must be between 0 and 8" + So(result.Error(), ShouldContainSubstring, expectedErrMsg) + if conn != nil { + defer conn.Close() // 确保关闭连接 + } + + }) + + db.Close() + AssertEqual(db.IsClosed(), true) +} + +func TestConnectionFetchSize(t *testing.T) { + db, err := api.NewSimpleDolphinDBClient(context.TODO(), host3, "admin", "123456") + AssertNil(err) + Convey("Test_BehaviorOptions_FetchSize_Invalid", t, func() { + + FetchSize := 8191 + opt := &dialer.BehaviorOptions{ + FetchSize: &FetchSize, + } + conn, err := api.NewDolphinDBClient(context.TODO(), host3, opt) + So(err, ShouldBeNil) + err = conn.Connect() + So(err, ShouldNotBeNil) // 确保连接返回了错误 + result := fmt.Errorf("\n exception error is %w", err) + fmt.Println(result.Error()) + So(result, ShouldNotBeNil) + conn.Close() + So(conn.IsClosed(), ShouldBeTrue) + }) + + Convey("Test_BehaviorOptions_FetchSize_8192", t, func() { + + FetchSize := 8192 + opt := &dialer.BehaviorOptions{ + FetchSize: &FetchSize, + } + conn, err := api.NewDolphinDBClient(context.TODO(), host3, opt) + So(err, ShouldBeNil) + err = conn.Connect() + So(err, ShouldBeNil) + }) + + db.Close() + AssertEqual(db.IsClosed(), true) +} + +func TestConnectionIsClearSessionMemory(t *testing.T) { + db, err := api.NewSimpleDolphinDBClient(context.TODO(), host3, "admin", "123456") + AssertNil(err) + Convey("Test_BehaviorOptions_IsClearSessionMemory_true", t, func() { + + opt := &dialer.BehaviorOptions{ + IsClearSessionMemory: true, + } + conn, err := api.NewDolphinDBClient(context.TODO(), host3, opt) + So(err, ShouldBeNil) + conn.Connect() + conn.RunScript("pt=table(1..3 as id);") + _, err1 := conn.RunScript("select * from pt;") + So(err1, ShouldNotBeNil) + conn.Close() + So(conn.IsClosed(), ShouldBeTrue) + }) + + Convey("Test_BehaviorOptions_IsClearSessionMemory_false", t, func() { + + opt := &dialer.BehaviorOptions{ + IsClearSessionMemory: false, + } + conn, err := api.NewDolphinDBClient(context.TODO(), host3, opt) + So(err, ShouldBeNil) + conn.Connect() + conn.RunScript("pt=table(1..3 as id);") + res, _ := conn.RunScript("select * from pt;") + So(res.Rows(), ShouldEqual, 3) + conn.Close() + So(conn.IsClosed(), ShouldBeTrue) + }) db.Close() AssertEqual(db.IsClosed(), true) } + +func TestBehaviorOptions(t *testing.T) { + Convey("Test_BehaviorOptions_Reconnect_true", t, func() { + opt := &dialer.BehaviorOptions{ + Reconnect: true, + } + connCtl, _ := api.NewSimpleDolphinDBClient(context.TODO(), setup.CtlAdress, setup.UserName, setup.Password) + So(connCtl.IsConnected(), ShouldBeTrue) + conn, err := api.NewDolphinDBClient(context.TODO(), host3, opt) + So(err, ShouldBeNil) + conn.Connect() + loginReq := &api.LoginRequest{ + UserID: "admin", + Password: "123456", + } + err = conn.Login(loginReq) + So(err, ShouldBeNil) + nodeName, _ := conn.RunScript("getNodeAlias()") + connCtl.RunScript("stopDataNode(`" + nodeName.(*model.Scalar).Value().(string) + ")") + time.Sleep(2 * time.Second) + connCtl.RunScript("startDataNode(`" + nodeName.(*model.Scalar).Value().(string) + ")") + time.Sleep(2 * time.Second) + res, _ := conn.RunScript("1+1") + So(res.(*model.Scalar).Value().(int32), ShouldEqual, 2) + conn.Close() + connCtl.Close() + }) + + Convey("Test_BehaviorOptions_Reconnect_false", t, func() { + opt := &dialer.BehaviorOptions{ + Reconnect: false, + } + conn, err := api.NewDolphinDBClient(context.TODO(), "192.168.0.69:3111", opt) + err = conn.Connect() + So(err, ShouldNotBeNil) + }) +} diff --git a/test/dfsTable_test.go b/test/dfsTable_test.go index e72dcc5..d4da665 100644 --- a/test/dfsTable_test.go +++ b/test/dfsTable_test.go @@ -6,18 +6,19 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) var host4 = getRandomClusterAddress() -func CreateScript(Num int) string { +func CreateScript(Num int) (string, string) { + dbPath := "dfs://" + generateRandomString(5) script := ` - dbName="dfs://` + generateRandomString(5) + `" + dbName="` + dbPath + `"; if(existsDatabase(dbName)){ dropDatabase(dbName) } @@ -50,7 +51,7 @@ func CreateScript(Num int) string { int128v = take([int128("7667974ea2fb155252559cc28b4a8efa"), int128("e7ef2788305d0f9c2c53cbfe3c373250"), int128("e602ccab7ff343e227b9596368ad5a44"), int128("709f888e885cfa716e0f36a0387477d5"), int128("978b68ce63f35ffbb79f23bd022269d8"), int128("022fd928ccbfc91efa6719ac22ccd239")], n) t = table(sym, boolv, intv, longv, shortv, doublev, floatv, str, charv, timestampv, datev, datetimev, monthv, timev, minutev, secondv, nanotimev, nanotimestampv, datehourv, uuidv, ipaddrv, int128v) pt.append!(t)` - return script + return dbPath, script } func TestDfsTable(t *testing.T) { @@ -58,10 +59,12 @@ func TestDfsTable(t *testing.T) { Convey("test dfsTable download data", t, func() { db, err := api.NewSimpleDolphinDBClient(context.TODO(), host4, setup.UserName, setup.Password) So(err, ShouldBeNil) + defer db.Close() var rowNum int Convey("test dfsTable only one rows", func() { rowNum = 1 - _, err = db.RunScript(CreateScript(rowNum)) + dbpath, s := CreateScript(rowNum) + _, err = db.RunScript(s) So(err, ShouldBeNil) Convey("Test select single col from dfsTable:", func() { Convey("Test select bool col from dfsTable:", func() { @@ -371,6 +374,8 @@ func TestDfsTable(t *testing.T) { } }) }) + err = db.DropDatabase(&api.DropDatabaseRequest{Directory: dbpath}) + So(err, ShouldBeNil) }) // Convey("test dfsTable less than 1024 rows", func() { // rowNum = 1023 @@ -406,141 +411,144 @@ func TestDfsTable(t *testing.T) { }) } -func CreateDecimalTypeScript(Num int) string { - script := ` - dbName="dfs://` + generateRandomString(5) + `" - if(existsDatabase(dbName)){ - dropDatabase(dbName) +func CreateAllTypesDFSTableScript(Num int) (string, string) { + dbName := "dfs://" + generateRandomString(5) + s := ` + row_num=` + strconv.Itoa(Num) + `-1; + cbool1 = bool(take(0 1 ,row_num));cchar1 = char(take(1..row_num ,row_num));cshort1 = short(take(1..row_num ,row_num));cint1 = int(take(1..row_num ,row_num));clong1 = long(take(1..row_num ,row_num)); + cdate1 = date(rand(10000 ,row_num));cmonth1 = month(rand(23640..25000 ,row_num));ctime1 = time(rand(10000 ,row_num));cminute1 = minute(rand(100 ,row_num)); + csecond1 = second(rand(100 ,row_num));cdatetime1 = datetime(rand(10000 ,row_num));ctimestamp1 = timestamp(rand(10000 ,row_num));cnanotime1 = nanotime(rand(10000 ,row_num)); + cnanotimestamp1 = nanotimestamp(rand(10000 ,row_num));cdatehour1 = datehour(rand(10000 ,row_num));cfloat1 = take(float(rand(1000.0000,2)) ,row_num);cdouble1 = take(rand(1000.0000,2) ,row_num); + csymbol1 = take(symbol("a""s""sym""d""zdg""f""y""ddvb"),row_num); + cstring1 = take("a""s""sym""d""zdg""f""y""ddvb",row_num); + cblob1 = blob(string(take("a""s""sym""d""zdg""f""y""ddvb",row_num))); + cipaddr1 = take(ipaddr("192.168.1.13"),row_num); + cuuid1 = take(uuid("5d212a78-cc48-e3b1-4235-b4d91473ee87"),row_num); + cint1281 = take(int128("e1671797c52e15f763380b45e841ec32"),row_num); + ccomplex1 = take(complex(1 2 ,3 4), row_num);cpoint1 = take(point(1 2 ,3 4),row_num); + cdecimal32_1 = decimal32(rand(1.0000, row_num),6); + cdecimal64_1 = decimal64(rand(1.0000000, row_num),16); + cdecimal128_1 = decimal128(rand(1.00000000, row_num),26); + + + ind = [2,4,6,8,10]; + cbool= arrayVector(ind, bool(rand(0 1 ,10)));cchar = arrayVector(ind, char(rand(256 ,10)));cshort = arrayVector(ind, short(rand(-10000..10000 ,10)));cint = arrayVector(ind, int(rand(-10000..10000 ,10))); + clong = arrayVector(ind, long(rand(-10000..10000 ,10)));cdate = arrayVector(ind, date(rand(10000 ,10)));cmonth = arrayVector(ind, month(rand(23640..25000 ,10)));ctime = arrayVector(ind, time(rand(10000 ,10))); + cminute = arrayVector(ind, minute(rand(100 ,10)));csecond = arrayVector(ind, second(rand(100 ,10)));cdatetime = arrayVector(ind, datetime(rand(10000 ,10)));ctimestamp = arrayVector(ind, timestamp(rand(10000 ,10))); + cnanotime = arrayVector(ind, nanotime(rand(10000 ,10)));cnanotimestamp = arrayVector(ind, nanotimestamp(rand(10000 ,10)));cdatehour = arrayVector(ind, datehour(rand(10000 ,10))); + cfloat = arrayVector(ind, float(rand(10000.0000,10)));cdouble = arrayVector(ind, rand(10000.0000,10)); + cdecimal32 = array(DECIMAL32(6)[], 0, 0).append!(decimal32([1..2, [], rand(100.000000, 2), rand(1..100, 2), take(00i, 2)], 6)) + cdecimal64 = array(DECIMAL64(16)[], 0, 0).append!(decimal64([1..2, [], rand(100.000000, 2), rand(1..100, 2), take(00i, 2)], 16)) + cdecimal128 = array(DECIMAL128(26)[], 0, 0).append!(decimal128([1..2, [], rand(100.000000, 2), rand(1..100, 2), take(00i, 2)], 26)) + cipaddr = arrayVector(ind, take(ipaddr(["192.168.1.13","192.168.1.14"]),10)) + cuuid = arrayVector(ind, take(uuid(["5d212a78-cc48-e3b1-4235-b4d91473ee87", "5d212a78-cc48-e3b1-4235-b4d91473ee88"]),10)) + cint128 = arrayVector(ind, take(int128(["e1671797c52e15f763380b45e841ec32","e1671797c52e15f763380b45e841ec33"]),10)) + + for(i in 1..(row_num-5)){ + cbool.append!([bool(take(0 1 ,2))]); + cchar.append!([char(rand(256 ,2))]);cshort.append!([short(rand(-10000..10000 ,2))]);cint.append!([int(rand(-10000..10000 ,2))]); + clong.append!([long(rand(-10000..10000 ,2))]);cdate.append!([date(rand(10000 ,2))]);cmonth.append!([month(rand(23640..25000 ,2))]); + ctime.append!([time(rand(10000 ,2))]);cminute.append!([minute(rand(100 ,2))]);csecond.append!([second(rand(100 ,2))]); + cdatetime.append!([datetime(rand(10000 ,2))]);ctimestamp.append!([timestamp(rand(10000 ,2))]); + cnanotime.append!([nanotime(rand(10000 ,2))]);cnanotimestamp.append!([nanotimestamp(rand(10000 ,2))]); + cdatehour.append!([datehour(rand(10000 ,2))]); + cfloat.append!([float(rand(10000.0000,2))]);cdouble.append!([rand(10000.0000, 2)]); + cdecimal32.append!([decimal32("1.123123123123123123123123123"'-5.789' ,6)]) + cdecimal64.append!([decimal64("1.123123123123123123123123123"'-5.789' ,16)]) + cdecimal128.append!([decimal128("1.123123123123123123123123123"'-5.789' ,26)]) + cipaddr.append!([take(ipaddr(["192.168.1.13","192.168.1.14"]),2)]) + cuuid.append!([take(uuid(["5d212a78-cc48-e3b1-4235-b4d91473ee87", "5d212a78-cc48-e3b1-4235-b4d91473ee88"]),2)]) + cint128.append!([take(int128(["e1671797c52e15f763380b45e841ec32","e1671797c52e15f763380b45e841ec33"]),2)]) } - n=` + strconv.Itoa(Num) + ` - t=table(100:0, ["sym", "boolv", "intv", "longv", "shortv", "doublev", "floatv", "str", "charv", "timestampv", "datev", "datetimev", "monthv", "timev", "minutev", "secondv", "nanotimev", "nanotimestamp", "datehourv", "uuidv", "ipaddrv", "int128v", "decimal32v", "decimal64v"], - [SYMBOL, BOOL, INT, LONG, SHORT, DOUBLE, FLOAT, STRING, CHAR, TIMESTAMP, DATE, DATETIME, MONTH, TIME, MINUTE, SECOND, NANOTIME, NANOTIMESTAMP, DATEHOUR, UUID, IPADDR, INT128, DECIMAL32(3), DECIMAL64(10)]) - db=database(dbName, VALUE, ["A", "B", "C", "D", "E", "F"]) - pt=db.createPartitionedTable(t, "pt", "sym") - sym = take(["A", "B", "C", "D", "E", "F"], n) - boolv = take([true, false, true, false, false, true, true], n) - intv = take([91,NULL,69,16,35,NULL,57,-28,-81,26], n) - longv = take([99,23,92,NULL,49,67,NULL,81,-38,14], n) - shortv = take([47,26,-39,NULL,97,NULL,4,39,-51,25], n) - doublev = take([4.7,2.6,-3.9,NULL,9.7,4.9,NULL,3.9,5.1,2.5], n) - floatv = take([5.2f, 11.3f, -3.9, 1.2f, 7.8f, -4.9f, NULL, 3.9f, 5.1f, 2.5f], n) - str = take("str" + string(1..10), n) - charv = take(char([70, 72, 15, 98, 94]), n) - timestampv = take([2012.01.01T12:23:56.166, NULL, 1970.01.01T12:23:56.148, 1969.12.31T23:59:59.138, 2012.01.01T12:23:56.132], n) - datev = take([NULL, 1969.01.11, 1970.01.24, 1969.12.31, 2012.03.30], n) - datetimev = take([NULL, 2012.01.01T12:24:04, 2012.01.01T12:25:04, 2012.01.01T12:24:55, 2012.01.01T12:24:27], n) - monthv = take([1970.06M, 2014.05M, 1970.06M, 2017.12M, 1969.11M], n) - timev = take([12:23:56.156, NULL, 12:23:56.206, 12:23:56.132, 12:23:56.201], n) - minutev = take([12:47m,13:13m, NULL, 13:49m, 13:17m], n) - secondv = take([NULL, 00:03:11, 00:01:52, 00:02:43, 00:02:08], n) - nanotimev = take(nanotime(1..10) join nanotime(), n) - nanotimestampv = take(nanotimestamp(-5..5) join nanotimestamp(), n) - datehourv = take(datehour([1969.12.01, 1969.01.11, NULL, 1969.12.31, 2012.03.30]), n) - uuidv = take([uuid("7d943e7f-5660-e015-a895-fa4da2b36c43"), uuid("3272fc73-5a91-34f5-db39-6ee71aa479a4"), uuid("62746671-9870-5b92-6deb-a6f5d59e715e"), uuid("dd05902d-5561-ee7f-6318-41a107371a8d"), uuid("14f82b2a-cf0f-7a0c-4cba-3df7be0ba0fc"), uuid("1f9093c3-9132-7200-4893-0f937a0d52c9")], n) - ipaddrv = take([ipaddr("a9b7:f65:9be1:20fd:741a:97ac:6ce5:1dd"), ipaddr("8494:3a0e:13db:a097:d3fd:8dc:56e4:faed"), ipaddr("4d93:5be:edbc:1830:344d:f71b:ce65:a4a3"), ipaddr("70ff:6bb4:a554:5af5:d90c:49f4:e8e6:eff0"), ipaddr("51b3:1bf0:1e65:740a:2b:51d9:162f:385a"), ipaddr("d6ea:3fcb:54bf:169f:9ab5:63bf:a960:19fb")], n) - int128v = take([int128("7667974ea2fb155252559cc28b4a8efa"), int128("e7ef2788305d0f9c2c53cbfe3c373250"), int128("e602ccab7ff343e227b9596368ad5a44"), int128("709f888e885cfa716e0f36a0387477d5"), int128("978b68ce63f35ffbb79f23bd022269d8"), int128("022fd928ccbfc91efa6719ac22ccd239")], n) - decimal32v = take(decimal32([0.235, -1.20345, -0.23564648, NULL, NULL, 2.36445], 5),n) - decimal64v = take(decimal64([0, -1.20345, -0.23564648, NULL, NULL, 2.36445], 10),n) - t = table(sym, boolv, intv, longv, shortv, doublev, floatv, str, charv, timestampv, datev, datetimev, monthv, timev, minutev, secondv, nanotimev, nanotimestampv, datehourv, uuidv, ipaddrv, int128v, decimal32v, decimal64v) - pt.append!(t)` - return script + + go + + table3=table(cbool1,cchar1,cshort1,cint1,clong1,cdate1,cmonth1,ctime1,cminute1,csecond1,cdatetime1,ctimestamp1,cnanotime1,cnanotimestamp1,cdatehour1,cfloat1,cdouble1,csymbol1,cstring1,cblob1,cuuid1,cint1281,cipaddr1,ccomplex1,cpoint1,cdecimal32_1,cdecimal64_1,cdecimal128_1, + cbool,cchar,cshort,cint,clong,cdate,cmonth,ctime,cminute,csecond,cdatetime,ctimestamp,cnanotime,cnanotimestamp,cdatehour,cfloat,cdouble,cuuid,cint128,cipaddr,cdecimal32,cdecimal64,cdecimal128); + + tableInsert(table3, NULL,NULL,NULL,row_num+1,NULL,date(row_num+1),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + [take(bool(NULL),2)],[take(char(NULL),2)],[take(short(NULL),2)],[take(int(NULL),2)],[take(long(NULL),2)],[take(date(NULL),2)],[take(month(NULL),2)],[take(time(NULL),2)],[take(minute(NULL),2)],[take(second(NULL),2)],[take(datetime(NULL),2)],[take(timestamp(NULL),2)],[take(nanotime(NULL),2)],[take(nanotimestamp(NULL),2)],[take(datehour(NULL),2)],[take(float(NULL),2)],[take(double(NULL),2)],[take(uuid(string(NULL)),2)],[take(int128(string(NULL)),2)],[take(ipaddr(string(NULL)),2)],[take(decimal32(NULL,6),2)],[take(decimal64(NULL,16),2)],[take(decimal128(NULL,26),2)]); + dbName = "` + dbName + `" + tbname = "pt" + if(existsDatabase(dbName)) + dropDatabase(dbName) + db = database(dbName, HASH, [DATE, 2], engine="TSDB") + db.createPartitionedTable(table3, tbname, "cdate1", , "cint1""cdate1").append!(table3)` + return dbName, s } func TestDfsTable_decimal(t *testing.T) { - t.Parallel() Convey("test dfsTable download data", t, func() { db, err := api.NewSimpleDolphinDBClient(context.TODO(), host4, setup.UserName, setup.Password) So(err, ShouldBeNil) + defer db.Close() var rowNum int - Convey("test dfsTable only one rows", func() { - rowNum = 1 - _, err = db.RunScript(CreateDecimalTypeScript(rowNum)) + Convey("test dfsTable 100 rows", func() { + rowNum = 100 + dbPath, s := CreateAllTypesDFSTableScript(rowNum) + defer db.DropDatabase(&api.DropDatabaseRequest{Directory: dbPath}) + _, err = db.RunScript(s) So(err, ShouldBeNil) Convey("Test select single col from dfsTable:", func() { Convey("Test select decimal32v col from dfsTable:", func() { - s, err := db.RunScript("select decimal32v from loadTable(dbName, `pt)") + s, err := db.RunScript("select cdecimal32_1 from loadTable('" + dbPath + "', `pt)") So(err, ShouldBeNil) memTable := s.(*model.Table) reDecimal32v := memTable.GetColumnByName(memTable.GetColumnNames()[0]) So(reDecimal32v.GetDataType(), ShouldEqual, model.DtDecimal32) So(reDecimal32v.GetDataForm(), ShouldResemble, model.DfVector) So(reDecimal32v.Rows(), ShouldEqual, rowNum) - So(reDecimal32v.Get(0).String(), ShouldEqual, "0.235") + db.Upload(map[string]model.DataForm{"res": reDecimal32v}) + ans, _ := db.RunScript(`ex = exec cdecimal32_1 from loadTable("` + dbPath + `", 'pt'); eqObj(ex, res)`) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) }) Convey("Test select decimal64v col from dfsTable:", func() { - s, err := db.RunScript("select decimal64v from loadTable(dbName, `pt)") + s, err := db.RunScript("select cdecimal64_1 from loadTable('" + dbPath + "', `pt)") So(err, ShouldBeNil) memTable := s.(*model.Table) reDecimal64v := memTable.GetColumnByName(memTable.GetColumnNames()[0]) So(reDecimal64v.GetDataType(), ShouldEqual, model.DtDecimal64) So(reDecimal64v.GetDataForm(), ShouldResemble, model.DfVector) So(reDecimal64v.Rows(), ShouldEqual, rowNum) - So(reDecimal64v.Get(0).String(), ShouldEqual, "0.0000000000") + db.Upload(map[string]model.DataForm{"res": reDecimal64v}) + ans, _ := db.RunScript(`ex = exec cdecimal64_1 from loadTable("` + dbPath + `", 'pt'); eqObj(ex, res)`) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) }) }) }) - Convey("test dfsTable 1024 rows", func() { - rowNum = 1030 - _, err = db.RunScript(CreateDecimalTypeScript(rowNum)) + Convey("test dfsTable 65536 rows", func() { + rowNum = 70000 + dbPath, s := CreateAllTypesDFSTableScript(rowNum) + defer db.DropDatabase(&api.DropDatabaseRequest{Directory: dbPath}) + _, err = db.RunScript(s) So(err, ShouldBeNil) Convey("Test select single col from dfsTable:", func() { Convey("Test select decimal32v col from dfsTable:", func() { - s, err := db.RunScript("select decimal32v from loadTable(dbName, `pt)") + s, err := db.RunScript("select cdecimal32_1 from loadTable(dbName, `pt)") So(err, ShouldBeNil) memTable := s.(*model.Table) reDecimal32v := memTable.GetColumnByName(memTable.GetColumnNames()[0]) So(reDecimal32v.GetDataType(), ShouldEqual, model.DtDecimal32) So(reDecimal32v.GetDataForm(), ShouldResemble, model.DfVector) So(reDecimal32v.Rows(), ShouldEqual, rowNum) - temp1 := []string{} - temp2 := []string{} - temp3 := []string{} - for i := 0; i < 171; i++ { - temp1 = append(temp1, "0.235") - temp2 = append(temp2, "-1.203") - temp3 = append(temp3, "-0.235") - } - for i := 0; i < 171; i++ { - if reDecimal32v.Get(i).String() != temp1[i] { - So(1, ShouldEqual, 0) - } - if reDecimal32v.Get(i+172).String() != temp2[i] { - So(1, ShouldEqual, 0) - } - if reDecimal32v.Get(i+172+172).String() != temp3[i] { - So(1, ShouldEqual, 0) - } - } + db.Upload(map[string]model.DataForm{"decimal32v": reDecimal32v}) + res, _ := db.RunScript(`ex = exec cdecimal32_1 from loadTable(dbName, 'pt'); + eqObj(ex, decimal32v)`) + So(res.(*model.Scalar).Value(), ShouldBeTrue) }) Convey("Test select decimal64v col from dfsTable:", func() { - s, err := db.RunScript("select decimal64v from loadTable(dbName, `pt)") + s, err := db.RunScript("select cdecimal64_1 from loadTable(dbName, `pt)") So(err, ShouldBeNil) memTable := s.(*model.Table) reDecimal64v := memTable.GetColumnByName(memTable.GetColumnNames()[0]) So(reDecimal64v.GetDataType(), ShouldEqual, model.DtDecimal64) So(reDecimal64v.GetDataForm(), ShouldResemble, model.DfVector) So(reDecimal64v.Rows(), ShouldEqual, rowNum) - So(reDecimal64v.Get(0).String(), ShouldEqual, "0.0000000000") - temp1 := []string{} - temp2 := []string{} - temp3 := []string{} - for i := 0; i < 171; i++ { - temp1 = append(temp1, "0.0000000000") - temp2 = append(temp2, "-1.2034500000") - temp3 = append(temp3, "-0.2356464800") - } - for i := 0; i < 171; i++ { - if reDecimal64v.Get(i).String() != temp1[i] { - So(1, ShouldEqual, 0) - } - if reDecimal64v.Get(i+172).String() != temp2[i] { - So(1, ShouldEqual, 0) - } - if reDecimal64v.Get(i+172+172).String() != temp3[i] { - So(1, ShouldEqual, 0) - } - } + db.Upload(map[string]model.DataForm{"decimal64v": reDecimal64v}) + res, _ := db.RunScript(`ex = exec cdecimal64_1 from loadTable(dbName, 'pt'); + eqObj(ex, decimal64v)`) + So(res.(*model.Scalar).Value(), ShouldBeTrue) }) }) }) @@ -548,58 +556,20 @@ func TestDfsTable_decimal(t *testing.T) { }) } -func CreateDecimalTypeScript_arrayVector(Num int) string { - script := ` - dbName="dfs://` + generateRandomString(5) + `" - if(existsDatabase(dbName)){ - dropDatabase(dbName) - } - n=` + strconv.Itoa(Num) + ` - t=table(100:0, ["sym", "boolv", "intv", "longv", "shortv", "doublev", "floatv", "str", "charv", "timestampv", "datev", "datetimev", "monthv", "timev", "minutev", "secondv", "nanotimev", "nanotimestamp", "datehourv", "uuidv", "ipaddrv", "int128v", "decimal32v", "decimal64v"], - [SYMBOL, BOOL, INT, LONG, SHORT, DOUBLE, FLOAT, STRING, CHAR, TIMESTAMP, DATE, DATETIME, MONTH, TIME, MINUTE, SECOND, NANOTIME, NANOTIMESTAMP, DATEHOUR, UUID, IPADDR, INT128, DECIMAL32(3)[], DECIMAL64(10)[]]) - db=database(dbName, VALUE, ["A", "B", "C", "D", "E", "F"], , "TSDB") - pt=db.createPartitionedTable(t, "pt", "sym", , ["sym", "timestampv"]) - sym = take(["A", "B", "C", "D", "E", "F"], n) - boolv = take([true, false, true, false, false, true, true], n) - intv = take([91,NULL,69,16,35,NULL,57,-28,-81,26], n) - longv = take([99,23,92,NULL,49,67,NULL,81,-38,14], n) - shortv = take([47,26,-39,NULL,97,NULL,4,39,-51,25], n) - doublev = take([4.7,2.6,-3.9,NULL,9.7,4.9,NULL,3.9,5.1,2.5], n) - floatv = take([5.2f, 11.3f, -3.9, 1.2f, 7.8f, -4.9f, NULL, 3.9f, 5.1f, 2.5f], n) - str = take("str" + string(1..10), n) - charv = take(char([70, 72, 15, 98, 94]), n) - timestampv = take([2012.01.01T12:23:56.166, NULL, 1970.01.01T12:23:56.148, 1969.12.31T23:59:59.138, 2012.01.01T12:23:56.132], n) - datev = take([NULL, 1969.01.11, 1970.01.24, 1969.12.31, 2012.03.30], n) - datetimev = take([NULL, 2012.01.01T12:24:04, 2012.01.01T12:25:04, 2012.01.01T12:24:55, 2012.01.01T12:24:27], n) - monthv = take([1970.06M, 2014.05M, 1970.06M, 2017.12M, 1969.11M], n) - timev = take([12:23:56.156, NULL, 12:23:56.206, 12:23:56.132, 12:23:56.201], n) - minutev = take([12:47m,13:13m, NULL, 13:49m, 13:17m], n) - secondv = take([NULL, 00:03:11, 00:01:52, 00:02:43, 00:02:08], n) - nanotimev = take(nanotime(1..10) join nanotime(), n) - nanotimestampv = take(nanotimestamp(-5..5) join nanotimestamp(), n) - datehourv = take(datehour([1969.12.01, 1969.01.11, NULL, 1969.12.31, 2012.03.30]), n) - uuidv = take([uuid("7d943e7f-5660-e015-a895-fa4da2b36c43"), uuid("3272fc73-5a91-34f5-db39-6ee71aa479a4"), uuid("62746671-9870-5b92-6deb-a6f5d59e715e"), uuid("dd05902d-5561-ee7f-6318-41a107371a8d"), uuid("14f82b2a-cf0f-7a0c-4cba-3df7be0ba0fc"), uuid("1f9093c3-9132-7200-4893-0f937a0d52c9")], n) - ipaddrv = take([ipaddr("a9b7:f65:9be1:20fd:741a:97ac:6ce5:1dd"), ipaddr("8494:3a0e:13db:a097:d3fd:8dc:56e4:faed"), ipaddr("4d93:5be:edbc:1830:344d:f71b:ce65:a4a3"), ipaddr("70ff:6bb4:a554:5af5:d90c:49f4:e8e6:eff0"), ipaddr("51b3:1bf0:1e65:740a:2b:51d9:162f:385a"), ipaddr("d6ea:3fcb:54bf:169f:9ab5:63bf:a960:19fb")], n) - int128v = take([int128("7667974ea2fb155252559cc28b4a8efa"), int128("e7ef2788305d0f9c2c53cbfe3c373250"), int128("e602ccab7ff343e227b9596368ad5a44"), int128("709f888e885cfa716e0f36a0387477d5"), int128("978b68ce63f35ffbb79f23bd022269d8"), int128("022fd928ccbfc91efa6719ac22ccd239")], n) - decimal32v = array(DECIMAL32(4)[], 0, 10).append!(take([[-2.3645, -2.346], [0.231], [], [2.2356, 1.2356, NULL]], n)) - decimal64v = array(DECIMAL64(4)[], 0, 10).append!(take([[-2.3645, -2.346], [0.231], [], [2.2356, 1.2356, NULL]], n)) - t = table(sym, boolv, intv, longv, shortv, doublev, floatv, str, charv, timestampv, datev, datetimev, monthv, timev, minutev, secondv, nanotimev, nanotimestampv, datehourv, uuidv, ipaddrv, int128v, decimal32v, decimal64v) - pt.append!(t)` - return script -} func TestDfsTable_decimal_arrayVector(t *testing.T) { - t.Parallel() Convey("test dfsTable download data", t, func() { db, err := api.NewSimpleDolphinDBClient(context.TODO(), host4, setup.UserName, setup.Password) So(err, ShouldBeNil) var rowNum int - Convey("test dfsTable only one rows", func() { - rowNum = 1 - _, err = db.RunScript(CreateDecimalTypeScript_arrayVector(rowNum)) + Convey("test dfsTable 100 rows", func() { + rowNum = 100 + dbPath, s := CreateAllTypesDFSTableScript(rowNum) + defer db.DropDatabase(&api.DropDatabaseRequest{Directory: dbPath}) + _, err = db.RunScript(s) So(err, ShouldBeNil) Convey("Test select single col from dfsTable:", func() { Convey("Test select decimal32v col from dfsTable:", func() { - s, err := db.RunScript("select decimal32v from loadTable(dbName, `pt)") + s, err := db.RunScript("select cdecimal32 from loadTable(dbName, `pt)") So(err, ShouldBeNil) memTable := s.(*model.Table) reDecimal32v := memTable.GetColumnByName(memTable.GetColumnNames()[0]) @@ -607,82 +577,59 @@ func TestDfsTable_decimal_arrayVector(t *testing.T) { So(reDecimal32v.GetDataTypeString(), ShouldEqual, "decimal32Array") So(reDecimal32v.GetDataForm(), ShouldResemble, model.DfVector) So(reDecimal32v.Rows(), ShouldEqual, rowNum) - So(reDecimal32v.String(), ShouldEqual, "vector([[-2.364, -2.346]])") + db.Upload(map[string]model.DataForm{"decimal32v": reDecimal32v}) + res, _ := db.RunScript(`ex = exec cdecimal32 from loadTable(dbName, 'pt'); + eqObj(ex, decimal32v)`) + So(res.(*model.Scalar).Value(), ShouldBeTrue) }) Convey("Test select decimal64v col from dfsTable:", func() { - s, err := db.RunScript("select decimal64v from loadTable(dbName, `pt)") + s, err := db.RunScript("select cdecimal64 from loadTable(dbName, `pt)") So(err, ShouldBeNil) memTable := s.(*model.Table) reDecimal64v := memTable.GetColumnByName(memTable.GetColumnNames()[0]) So(reDecimal64v.GetDataType(), ShouldEqual, model.DtDecimal64+64) So(reDecimal64v.GetDataForm(), ShouldResemble, model.DfVector) So(reDecimal64v.Rows(), ShouldEqual, rowNum) - So(reDecimal64v.String(), ShouldEqual, "vector([[-2.3645000000, -2.3460000000]])") + db.Upload(map[string]model.DataForm{"decimal64v": reDecimal64v}) + res, _ := db.RunScript(`ex = exec cdecimal64 from loadTable(dbName, 'pt'); + eqObj(ex, decimal64v)`) + So(res.(*model.Scalar).Value(), ShouldBeTrue) }) }) }) - Convey("test dfsTable 1024 rows", func() { - rowNum = 1030 - _, err = db.RunScript(CreateDecimalTypeScript(rowNum)) + Convey("test dfsTable 65536 rows", func() { + rowNum = 70000 + dbPath, s := CreateAllTypesDFSTableScript(rowNum) + defer db.DropDatabase(&api.DropDatabaseRequest{Directory: dbPath}) + _, err = db.RunScript(s) So(err, ShouldBeNil) Convey("Test select single col from dfsTable:", func() { Convey("Test select decimal32v col from dfsTable:", func() { - s, err := db.RunScript("select decimal32v from loadTable(dbName, `pt)") + s, err := db.RunScript("select cdecimal32 from loadTable(dbName, `pt)") So(err, ShouldBeNil) memTable := s.(*model.Table) reDecimal32v := memTable.GetColumnByName(memTable.GetColumnNames()[0]) - So(reDecimal32v.GetDataType(), ShouldEqual, model.DtDecimal32) + So(reDecimal32v.GetDataType(), ShouldEqual, model.DtDecimal32+64) So(reDecimal32v.GetDataForm(), ShouldResemble, model.DfVector) So(reDecimal32v.Rows(), ShouldEqual, rowNum) - temp1 := []string{} - temp2 := []string{} - temp3 := []string{} - for i := 0; i < 171; i++ { - temp1 = append(temp1, "0.235") - temp2 = append(temp2, "-1.203") - temp3 = append(temp3, "-0.235") - } - for i := 0; i < 171; i++ { - if reDecimal32v.Get(i).String() != temp1[i] { - So(1, ShouldEqual, 0) - } - if reDecimal32v.Get(i+172).String() != temp2[i] { - So(1, ShouldEqual, 0) - } - if reDecimal32v.Get(i+172+172).String() != temp3[i] { - So(1, ShouldEqual, 0) - } - } + db.Upload(map[string]model.DataForm{"decimal32v": reDecimal32v}) + res, _ := db.RunScript(`ex = exec cdecimal32 from loadTable(dbName, 'pt'); + eqObj(ex, decimal32v)`) + So(res.(*model.Scalar).Value(), ShouldBeTrue) }) Convey("Test select decimal64v col from dfsTable:", func() { - s, err := db.RunScript("select decimal64v from loadTable(dbName, `pt)") + s, err := db.RunScript("select cdecimal64 from loadTable(dbName, `pt)") So(err, ShouldBeNil) memTable := s.(*model.Table) reDecimal64v := memTable.GetColumnByName(memTable.GetColumnNames()[0]) - So(reDecimal64v.GetDataType(), ShouldEqual, model.DtDecimal64) + So(reDecimal64v.GetDataType(), ShouldEqual, model.DtDecimal64+64) So(reDecimal64v.GetDataForm(), ShouldResemble, model.DfVector) So(reDecimal64v.Rows(), ShouldEqual, rowNum) - So(reDecimal64v.Get(0).String(), ShouldEqual, "0.0000000000") - temp1 := []string{} - temp2 := []string{} - temp3 := []string{} - for i := 0; i < 171; i++ { - temp1 = append(temp1, "0.0000000000") - temp2 = append(temp2, "-1.2034500000") - temp3 = append(temp3, "-0.2356464800") - } - for i := 0; i < 171; i++ { - if reDecimal64v.Get(i).String() != temp1[i] { - So(1, ShouldEqual, 0) - } - if reDecimal64v.Get(i+172).String() != temp2[i] { - So(1, ShouldEqual, 0) - } - if reDecimal64v.Get(i+172+172).String() != temp3[i] { - So(1, ShouldEqual, 0) - } - } + db.Upload(map[string]model.DataForm{"decimal64v": reDecimal64v}) + res, _ := db.RunScript(`ex = exec cdecimal64 from loadTable(dbName, 'pt'); + eqObj(ex, decimal64v)`) + So(res.(*model.Scalar).Value(), ShouldBeTrue) }) }) }) diff --git a/test/dropPartition_tabletMultiple_test.go b/test/dropPartition_tabletMultiple_test.go index fce83cf..5d1f0c4 100644 --- a/test/dropPartition_tabletMultiple_test.go +++ b/test/dropPartition_tabletMultiple_test.go @@ -4,105 +4,81 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) var host5 = getRandomClusterAddress() var ddb, _ = api.NewSimpleDolphinDBClient(context.TODO(), host5, setup.UserName, setup.Password) -func Test_DropPartition_tabletMultiple_prepare(t *testing.T) { - t.Parallel() - Convey("Test_DropPartition_tabletMultiple_prepare", t, func() { - Convey("Drop all Databases", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - dbPaths := []string{DfsDBPath, DiskDBPath} - for _, dbPath := range dbPaths { - script := ` - if(existsDatabase("` + dbPath + `")){ - dropDatabase("` + dbPath + `") - } - if(exists("` + dbPath + `")){ - rmdir("` + dbPath + `", true) - } - ` - _, err := ddb.RunScript(script) - So(err, ShouldBeNil) - re, err := ddb.RunScript(`existsDatabase("` + dbPath + `")`) - So(err, ShouldBeNil) - isExitsDatabase := re.(*model.Scalar).DataType.Value() - So(isExitsDatabase, ShouldBeFalse) - } - }) - }) -} func Test_DropPartition_tabletMultiple_range_drop_single(t *testing.T) { t.Parallel() Convey("Test_DropPartition_tabletMultiple_range_drop_single:", t, func() { Convey("Test_DropPartition_tabletMultiple_range_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "10001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + // rs, err := LoadTableBySQL(ddb, "10001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where id >= 10001")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/1_10001'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("'/1_10001'")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_range_drop_all_tables:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "10001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where id >= 10001")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/1_10001'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("'/1_10001'")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "'/1_10001'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("'/1_10001'")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -112,66 +88,68 @@ func Test_DropPartition_tabletMultiple_range_drop_multiple(t *testing.T) { Convey("Test_DropPartition_tabletMultiple_range_drop_multiple:", t, func() { Convey("Test_DropPartition_tabletMultiple_range_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "30001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where id >= 30001")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) + // err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) + + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("['/1_10001', '/10001_20001', '/20001_30001']")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_range_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "30001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where id >=30001")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("['/1_10001', '/10001_20001', '/20001_30001']")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("['/1_10001', '/10001_20001', '/20001_30001']")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -182,66 +160,66 @@ func Test_DropPartition_tabletMultiple_hash_drop_single(t *testing.T) { Convey("Test_DropPartition_tabletMultiple_hash_drop_single:", t, func() { Convey("Test_DropPartition_tabletMultiple_hash_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "10", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id != %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where id !=10")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/Key0'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("'/Key0'")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_hash_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "10", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id != %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where id !=10")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/Key0'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("'/Key0'")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "'/Key0'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("'/Key0'")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -251,33 +229,33 @@ func Test_DropPartition_tabletMultiple_hash_drop_multiple(t *testing.T) { Convey("Test_DropPartition_tabletMultiple_hash_drop_multiple:", t, func() { Convey("Test_DropPartition_tabletMultiple_hash_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2..9", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id in %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where id in 2..9")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/Key0', '/Key1']`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("['/Key0', '/Key1']")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_hash_drop_all_table:", func() { @@ -320,66 +298,66 @@ func Test_DropPartition_tabletMultiple_value_drop_single(t *testing.T) { Convey("Test_DropPartition_tabletMultiple_value_drop_single:", t, func() { Convey("Test_DropPartition_tabletMultiple_value_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.01.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date != %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date !=2010.01.01")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/20100101'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("'/20100101'")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_value_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.01.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date != %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date !=2010.01.01")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/20100101'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("'/20100101'")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "'/20100101'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("'/20100101'")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -389,66 +367,68 @@ func Test_DropPartition_tabletMultiple_value_drop_multiple(t *testing.T) { Convey("Test_DropPartition_tabletMultiple_value_drop_multiple:", t, func() { Convey("Test_DropPartition_tabletMultiple_value_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(date, 2010.01.01+[0, 7, 14, 21])", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where!in(date, 2010.01.01+[0, 7, 14, 21])")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("['/20100101', '/20100108', '/20100115', '/20100122']")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_value_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(date, 2010.01.01+[0, 7, 14, 21])", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where!in(date, 2010.01.01+[0, 7, 14, 21])")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) + + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("['/20100101', '/20100108', '/20100115', '/20100122']")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) + + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("['/20100101', '/20100108', '/20100115', '/20100122']")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -458,66 +438,66 @@ func Test_DropPartition_tabletMultiple_list_drop_single(t *testing.T) { Convey("Test_DropPartition_tabletMultiple_list_drop_single:", t, func() { Convey("Test_DropPartition_tabletMultiple_list_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(sym,`AMD`QWE`CES)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where!in(sym,`AMD`QWE`CES)")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/List0'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("'/List0'")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_list_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(sym,`AMD`QWE`CES)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where!in(sym,`AMD`QWE`CES)")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/List0'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("'/List0'")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "'/List0'") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("'/List0'")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -527,66 +507,66 @@ func Test_DropPartition_tabletMultiple_list_drop_multiple(t *testing.T) { Convey("Test_DropPartition_tabletMultiple_list_drop_multiple:", t, func() { Convey("Test_DropPartition_tabletMultiple_list_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(sym,`DOP`ASZ`FSD`BBVC)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where!in(sym,`DOP`ASZ`FSD`BBVC)")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/List1', '/List2']`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("['/List1', '/List2']")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_list_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(sym,`DOP`ASZ`FSD`BBVC)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where!in(sym,`DOP`ASZ`FSD`BBVC)")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/List1', '/List2']`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("['/List1', '/List2']")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `['/List1', '/List2']`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("['/List1', '/List2']")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -596,66 +576,66 @@ func Test_DropPartition_tabletMultiple_compo_range_range_drop_level1_single(t *t Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level1_single:", t, func() { Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level1_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.02.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date >=2010.02.01")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "2010.01.01") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("2010.01.01")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level1_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.02.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date >=2010.02.01")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "2010.01.01") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("2010.01.01")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "2010.01.01") + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("2010.01.01")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -665,66 +645,66 @@ func Test_DropPartition_tabletMultiple_compo_range_range_drop_level1_multiple(t Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level1_multiple:", t, func() { Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level1_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.03.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date >=2010.03.01")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[2010.01.01, 2010.02.01]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("[2010.01.01, 2010.02.01]")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level1_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.03.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date >=2010.03.01")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[2010.01.01, 2010.02.01]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("[2010.01.01, 2010.02.01]")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `[2010.01.01, 2010.02.01]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("[2010.01.01, 2010.02.01]")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -734,66 +714,66 @@ func Test_DropPartition_tabletMultiple_compo_range_range_drop_level2_single(t *t Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level2_single:", t, func() { Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level2_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.02.01 or id >= 3", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date >=2010.02.01 or id >= 3")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[2010.01.01, 1]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("[2010.01.01, 1]")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level2_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.02.01 or id >= 3", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date >=2010.02.01 or id >= 3")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[2010.01.01, 1]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths("[2010.01.01, 1]")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `[2010.01.01, 1]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths("[2010.01.01, 1]")) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -803,66 +783,66 @@ func Test_DropPartition_tabletMultiple_compo_range_range_drop_level2_multiple(t Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level2_multiple:", t, func() { Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level2_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "date >= 2010.03.01 or !between(id, 3:6)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date >=date >= 2010.03.01 or !between(id, 3:6)")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths(`[[2010.01.01,2010.02.01], [3,5]]`)) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletMultiple_compo_range_range_drop_level2_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedbChunkGranularity(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "date >= 2010.03.01 or !between(id, 3:6)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := ddb.LoadTableBySQL(new(api.LoadTableBySQLRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetSQL("select * from loadTable('" + DfsDBPath + "','" + DfsTBName1 + "') where date >=date >= 2010.03.01 or !between(id, 3:6)")) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1).SetPartitionPaths(`[[2010.01.01,2010.02.01], [3,5]]`)) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) + err = ddb.DropPartition(new(api.DropPartitionRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName2).SetPartitionPaths(`[[2010.01.01,2010.02.01], [3,5]]`)) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(DfsTBName2)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) diff --git a/test/dropPartition_tabletSingle_test.go b/test/dropPartition_tabletSingle_test.go index f1544a7..e65c29a 100644 --- a/test/dropPartition_tabletSingle_test.go +++ b/test/dropPartition_tabletSingle_test.go @@ -4,106 +4,81 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) var host6 = getRandomClusterAddress() +var ddb2, _ = api.NewSimpleDolphinDBClient(context.TODO(), host6, setup.UserName, setup.Password) -func TestDropPartition_tabletSingle(t *testing.T) { - t.Parallel() - Convey("Test_DropPartition_tabletSingle_prepare", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host6, setup.UserName, setup.Password) - So(err, ShouldBeNil) - Convey("Drop all Databases", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - dbPaths := []string{DfsDBPath, DiskDBPath} - for _, dbPath := range dbPaths { - script := ` - if(existsDatabase("` + dbPath + `")){ - dropDatabase("` + dbPath + `") - } - if(exists("` + dbPath + `")){ - rmdir("` + dbPath + `", true) - } - ` - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - re, err := ddb.RunScript(`existsDatabase("` + dbPath + `")`) - So(err, ShouldBeNil) - isExitsDatabase := re.(*model.Scalar).DataType.Value() - So(isExitsDatabase, ShouldBeFalse) - } - }) - }) -} func Test_DropPartition_tabletSingle_range_drop_single(t *testing.T) { t.Parallel() Convey("Test_DropPartition_tabletSingle_range_drop_single:", t, func() { Convey("Test_DropPartition_tabletSingle_range_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "10001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "10001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/1_10001'") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "'/1_10001'") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_range_drop_all_tables:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "10001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "10001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/1_10001'") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "'/1_10001'") So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "'/1_10001'") + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, "'/1_10001'") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -113,66 +88,68 @@ func Test_DropPartition_tabletSingle_range_drop_multiple(t *testing.T) { Convey("Test_DropPartition_tabletSingle_range_drop_multiple:", t, func() { Convey("Test_DropPartition_tabletSingle_range_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "30001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "30001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_range_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "30001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "30001", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, `['/1_10001', '/10001_20001', '/20001_30001']`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -182,66 +159,68 @@ func Test_DropPartition_tabletSingle_hash_drop_single(t *testing.T) { Convey("Test_DropPartition_tabletSingle_hash_drop_single:", t, func() { Convey("Test_DropPartition_tabletSingle_hash_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "10", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id != %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "10", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id != %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/Key0'") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "'/Key0'") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_hash_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "10", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id != %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "10", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id != %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/Key0'") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "'/Key0'") So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "'/Key0'") + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, "'/Key0'") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -251,66 +230,68 @@ func Test_DropPartition_tabletSingle_hash_drop_multiple(t *testing.T) { Convey("Test_DropPartition_tabletSingle_hash_drop_multiple:", t, func() { Convey("Test_DropPartition_tabletSingle_hash_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2..9", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id in %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2..9", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id in %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/Key0', '/Key1']`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `['/Key0', '/Key1']`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_hash_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2..9", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id in %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2..9", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where id in %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/Key0', '/Key1']`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `['/Key0', '/Key1']`) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `['/Key0', '/Key1']`) + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, `['/Key0', '/Key1']`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -320,66 +301,68 @@ func Test_DropPartition_tabletSingle_value_drop_single(t *testing.T) { Convey("Test_DropPartition_tabletSingle_value_drop_single:", t, func() { Convey("Test_DropPartition_tabletSingle_value_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.01.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date != %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2010.01.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date != %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/20100101'") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "'/20100101'") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_value_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.01.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date != %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2010.01.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date != %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/20100101'") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "'/20100101'") So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "'/20100101'") + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, "'/20100101'") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -389,66 +372,68 @@ func Test_DropPartition_tabletSingle_value_drop_multiple(t *testing.T) { Convey("Test_DropPartition_tabletSingle_value_drop_multiple:", t, func() { Convey("Test_DropPartition_tabletSingle_value_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(date, 2010.01.01+[0, 7, 14, 21])", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "!in(date, 2010.01.01+[0, 7, 14, 21])", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_value_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(date, 2010.01.01+[0, 7, 14, 21])", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "!in(date, 2010.01.01+[0, 7, 14, 21])", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, `['/20100101', '/20100108', '/20100115', '/20100122']`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -458,66 +443,68 @@ func Test_DropPartition_tabletSingle_list_drop_single(t *testing.T) { Convey("Test_DropPartition_tabletSingle_list_drop_single:", t, func() { Convey("Test_DropPartition_tabletSingle_list_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(sym,`AMD`QWE`CES)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "!in(sym,`AMD`QWE`CES)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/List0'") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "'/List0'") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_list_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(sym,`AMD`QWE`CES)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "!in(sym,`AMD`QWE`CES)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "'/List0'") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "'/List0'") So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "'/List0'") + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, "'/List0'") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -527,66 +514,68 @@ func Test_DropPartition_tabletSingle_list_drop_multiple(t *testing.T) { Convey("Test_DropPartition_tabletSingle_list_drop_multiple:", t, func() { Convey("Test_DropPartition_tabletSingle_list_drop_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(sym,`DOP`ASZ`FSD`BBVC)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "!in(sym,`DOP`ASZ`FSD`BBVC)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/List1', '/List2']`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `['/List1', '/List2']`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_list_drop_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "!in(sym,`DOP`ASZ`FSD`BBVC)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "!in(sym,`DOP`ASZ`FSD`BBVC)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `['/List1', '/List2']`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `['/List1', '/List2']`) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `['/List1', '/List2']`) + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, `['/List1', '/List2']`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -596,66 +585,68 @@ func Test_DropPartition_tabletSingle_compo_range_range_drop_single(t *testing.T) Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level1_single:", t, func() { Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level1_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.02.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2010.02.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "2010.01.01") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "2010.01.01") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level1_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.02.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2010.02.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, "2010.01.01") + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, "2010.01.01") So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, "2010.01.01") + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, "2010.01.01") So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -665,66 +656,68 @@ func Test_DropPartition_tabletSingle_compo_range_range_drop_multiple(t *testing. Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level1_multiple:", t, func() { Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level1_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.03.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2010.03.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[2010.01.01, 2010.02.01]`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `[2010.01.01, 2010.02.01]`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level1_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.03.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2010.03.01", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[2010.01.01, 2010.02.01]`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `[2010.01.01, 2010.02.01]`) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `[2010.01.01, 2010.02.01]`) + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, `[2010.01.01, 2010.02.01]`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -734,66 +727,68 @@ func Test_DropPartition_tabletSingle_compo_range_range_drop_level2(t *testing.T) Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level2_single:", t, func() { Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level2_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.02.01 or id >= 3", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2010.02.01 or id >= 3", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[2010.01.01, 1]`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `[2010.01.01, 1]`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level2_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "2010.02.01 or id >= 3", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "2010.02.01 or id >= 3", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[2010.01.01, 1]`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `[2010.01.01, 1]`) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `[2010.01.01, 1]`) + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, `[2010.01.01, 1]`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -803,66 +798,68 @@ func Test_DropPartition_tabletSingle_compo_range_range_drop_level2_multiple(t *t Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level2_multiple:", t, func() { Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level2_only_one_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "date >= 2010.03.01 or !between(id, 3:6)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "date >= 2010.03.01 or !between(id, 3:6)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, originTable2) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) Convey("Test_DropPartition_tabletSingle_compo_range_range_drop_level2_all_table:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "date >= 2010.03.01 or !between(id, 3:6)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "date >= 2010.03.01 or !between(id, 3:6)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName1, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) + err = DropPartition(ddb2, DfsTBName1, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) So(err, ShouldBeNil) - err = DropPartition(ddb, DfsTBName2, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) + err = DropPartition(ddb2, DfsTBName2, DfsDBPath, `[[2010.01.01,2010.02.01], [3,5]]`) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) }) @@ -871,7 +868,7 @@ func Test_DropPartition_tabletSingle_compo_range_list_drop_single(t *testing.T) t.Parallel() Convey("Test_DropPartition_tabletSingle_SetDBHandle:", t, func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) ddbScript := ` @@ -885,41 +882,42 @@ func Test_DropPartition_tabletSingle_compo_range_list_drop_single(t *testing.T) db.createPartitionedTable(tdata,"` + DfsTBName1 + `",["date", "id"]).append!(tdata) db.createPartitionedTable(tdata,"` + DfsTBName2 + `",["date", "id"]).append!(tdata) ` - _, err = ddb.RunScript(ddbScript) + _, err = ddb2.RunScript(ddbScript) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + defer ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + re2, err := ddb2.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - originTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - originTable2, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + originTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) re := CompareTables(originTable1, originTable2) So(err, ShouldBeNil) So(re, ShouldBeTrue) - rs, err := LoadTableBySQL(ddb, "date >= 2010.03.01 or !between(id, 3:6)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) + rs, err := LoadTableBySQL(ddb2, "date >= 2010.03.01 or !between(id, 3:6)", "select * from loadTable('"+DfsDBPath+"','"+DfsTBName1+"') where date >= %s", DfsDBPath, DfsTBName1) So(err, ShouldBeNil) t1 := new(api.DropPartitionRequest). SetPartitionPaths(`[[2010.01.01,2010.02.01], [3,5]]`). SetDBPath(DfsDBPath). SetTableName(DfsTBName1).SetDBHandle("db") - err = ddb.DropPartition(t1) + err = ddb2.DropPartition(t1) So(err, ShouldBeNil) t2 := new(api.DropPartitionRequest). SetPartitionPaths(`[[2010.01.01,2010.02.01], [3,5]]`). SetDBPath(DfsDBPath). SetTableName(DfsTBName2).SetDBHandle("db") - err = ddb.DropPartition(t2) + err = ddb2.DropPartition(t2) So(err, ShouldBeNil) - reTable1, err := LoadTable(ddb, DfsTBName1, DfsDBPath) + reTable1, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName1).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) - reTable2, err := LoadTable(ddb, DfsTBName2, DfsDBPath) + reTable2, err := ddb2.LoadTable(new(api.LoadTableRequest).SetTableName(DfsTBName2).SetDatabase(DfsDBPath)) So(err, ShouldBeNil) reData1 := CompareTables(reTable1, rs) So(reData1, ShouldBeTrue) reData2 := CompareTables(reTable2, rs) So(reData2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb2.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) }) } diff --git a/test/existsDatabase_test.go b/test/existsDatabase_test.go index 8bf7c8a..407e7d5 100644 --- a/test/existsDatabase_test.go +++ b/test/existsDatabase_test.go @@ -4,258 +4,239 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) var host7 = getRandomClusterAddress() + func TestExistDatabaseAndDropDatabase(t *testing.T) { t.Parallel() Convey("Test ExistDatabase and dropDatabase prepare", t, func() { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host7, setup.UserName, setup.Password) So(err, ShouldBeNil) - Convey("Drop all Databases", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - dbPaths := []string{DfsDBPath, DiskDBPath} - for _, dbPath := range dbPaths { - script := ` - if(existsDatabase("` + dbPath + `")){ - dropDatabase("` + dbPath + `") - } - if(exists("` + dbPath + `")){ - rmdir("` + dbPath + `", true) - } - ` - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - re, err := ddb.RunScript(`existsDatabase("` + dbPath + `")`) - So(err, ShouldBeNil) - isExitsDatabase := re.(*model.Scalar).DataType.Value() - So(isExitsDatabase, ShouldBeFalse) - } - }) Convey("Test_ExistDatabase_wrong_db_exception", func() { - _, err := ddb.RunScript(`existsDatabase(shjbdj)`) - So(err, ShouldNotBeNil) + res, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: "adgasw"}) + So(res, ShouldBeFalse) + So(err, ShouldBeNil) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_dimension:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsDimensiondb(DfsDBPath, TbName1, TbName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_range:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_hash:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_value:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_list:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_compo_range_range:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_compo_range_value:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeValuedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_compo_range_list:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeListdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_dfs_compo_range_hash:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DfsDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_disk_unpartitioned_table:", func() { - re1, err := ExistsDatabase(ddb, DiskDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDiskUnpartitioneddb(DiskDBPath, TbName1, TbName2) - re2, err := ExistsTable(ddb, DiskDBPath, TbName1) + re2, err := ddb.ExistsTable(&api.ExistsTableRequest{TableName: TbName1, DBPath: DiskDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DiskDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DiskDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DiskDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_create_disk_range_db:", func() { - re1, err := ExistsDatabase(ddb, DiskDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - CreateDiskRangedb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + CreateDiskRangedb(DiskDBPath, TbName1, TbName2) + re2, err := ddb.ExistsTable(&api.ExistsTableRequest{TableName: TbName1, DBPath: DiskDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DiskDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DiskDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DiskDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_create_disk_hash_db:", func() { - re1, err := ExistsDatabase(ddb, DiskDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - CreateDiskHashdb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + CreateDiskHashdb(DiskDBPath, TbName1, TbName2) + re2, err := ddb.ExistsTable(&api.ExistsTableRequest{TableName: TbName1, DBPath: DiskDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DiskDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DiskDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DiskDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_create_disk_value_db:", func() { - re1, err := ExistsDatabase(ddb, DiskDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - CreateDiskValuedb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + CreateDiskValuedb(DiskDBPath, TbName1, TbName2) + re2, err := ddb.ExistsTable(&api.ExistsTableRequest{TableName: TbName1, DBPath: DiskDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DiskDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DiskDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DiskDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_create_disk_list_db:", func() { - re1, err := ExistsDatabase(ddb, DiskDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - CreateDiskListdb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + CreateDiskListdb(DiskDBPath, TbName1, TbName2) + re2, err := ddb.ExistsTable(&api.ExistsTableRequest{TableName: TbName1, DBPath: DiskDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DiskDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DiskDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DiskDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_ExistDatabase_and_dropDatabase_create_compo_range_range_db:", func() { - re1, err := ExistsDatabase(ddb, DiskDBPath) + re1, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - CreateDiskCompoRangeRangedb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + CreateDiskCompoRangeRangedb(DiskDBPath, TbName1, TbName2) + re2, err := ddb.ExistsTable(&api.ExistsTableRequest{TableName: TbName1, DBPath: DiskDBPath}) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DiskDBPath) + err = ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DiskDBPath}) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DiskDBPath) + re3, err := ddb.ExistsDatabase(&api.ExistsDatabaseRequest{Path: DiskDBPath}) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) diff --git a/test/existsTable_test.go b/test/existsTable_test.go index 12fdab7..bd63d18 100644 --- a/test/existsTable_test.go +++ b/test/existsTable_test.go @@ -4,64 +4,40 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) var host8 = getRandomClusterAddress() + func TestDropTableException(t *testing.T) { t.Parallel() Convey("Test_existsTable_and_dropTable_prepare", t, func() { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host8, setup.UserName, setup.Password) So(err, ShouldBeNil) - Convey("Test_existsTable_dropDatabase", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - dbPaths := []string{DfsDBPath, DiskDBPath} - for _, dbPath := range dbPaths { - script := ` - if(existsDatabase("` + dbPath + `")){ - dropDatabase("` + dbPath + `") - } - if(exists("` + dbPath + `")){ - rmdir("` + dbPath + `", true) - } - ` - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - re, err := ddb.RunScript(`existsDatabase("` + dbPath + `")`) - So(err, ShouldBeNil) - isExitsDatabase := re.(*model.Scalar).DataType.Value() - So(isExitsDatabase, ShouldBeFalse) - } - }) Convey("Test_dropTable_wrong_Table_exception", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, "mt1") + re1, err := ddb.ExistsTable(&api.ExistsTableRequest{DBPath: DfsDBPath, TableName: TbName1}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - CreateDfsDimensiondb(DfsDBPath, TbName1, TbName2) - err = DropTable(ddb, "mt", DfsDBPath) + CreateDfsDimensiondb(DfsDBPath, DfsTBName1, DfsTBName2) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(TbName1).SetDBPath(DfsDBPath)) So(err, ShouldNotBeNil) }) Convey("Test_dropTable_wrong_dbpath_exception", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, "dfs://test1", TbName1) + re1, err := ddb.ExistsTable(&api.ExistsTableRequest{DBPath: DfsDBPath, TableName: TbName1}) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsDimensiondb(DfsDBPath, TbName1, TbName2) - err = DropTable(ddb, TbName1, "dfs://test1") + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + err = ddb.DropTable(&api.DropTableRequest{TableName: TbName1, DBPath: "dfs://wrong_dbpath"}) So(err, ShouldNotBeNil) }) Convey("Test_dropTable_only_DBHandle_dbPath_exception", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, TbName1) - So(err, ShouldBeNil) - if re1 == true { - _, err = ddb.RunScript("dropDatabase('" + DfsDBPath + "')") - So(err, ShouldBeNil) - } ddbScript := ` dbPath="` + DfsDBPath + `" if(existsDatabase(dbPath)) @@ -69,10 +45,11 @@ func TestDropTableException(t *testing.T) { db=database(dbPath, RANGE, 1..10) n=100000 tdata=table(sort(take(2010.01.01..2010.12.31, n)) as date, 1..n as id, take(["AMD", "QWE", "CES", "DOP", "ASZ", "FSD", "BBVC", "AWQ", "DS"], n) as sym, rand(100, n) as val) - db.createTable(tdata, "` + TbName1 + `").append!(tdata) - db.createTable(tdata, "` + TbName2 + `").append!(tdata) + db.createTable(tdata, "` + DfsTBName1 + `").append!(tdata) + db.createTable(tdata, "` + DfsTBName2 + `").append!(tdata) ` _, err = ddb.RunScript(ddbScript) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) t := new(api.DropTableRequest). SetDBPath(DfsDBPath).SetDBHandle("db") @@ -103,242 +80,250 @@ func TestExistsTableAndDropTable(t *testing.T) { ` _, err = ddb.RunScript(script) So(err, ShouldBeNil) - re, err := ddb.RunScript(`existsDatabase("` + dbPath + `")`) - So(err, ShouldBeNil) - isExitsDatabase := re.(*model.Scalar).DataType.Value() - So(isExitsDatabase, ShouldBeFalse) } }) Convey("Test_existsTable_dfs_dimension", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, TbName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) - re2, err := ExistsTable(ddb, DfsDBPath, TbName2) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(TbName2)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) CreateDfsDimensiondb(DfsDBPath, TbName1, TbName2) - re3, err := ExistsTable(ddb, DfsDBPath, TbName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) So(re3, ShouldBeTrue) - re4, err := ExistsTable(ddb, DfsDBPath, TbName2) + re4, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(TbName2)) So(err, ShouldBeNil) So(re4, ShouldBeTrue) - err = DropTable(ddb, TbName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(TbName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - err = DropTable(ddb, TbName2, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(TbName2).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re5, err := ExistsTable(ddb, DfsDBPath, TbName1) + re5, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) So(re5, ShouldBeFalse) - re6, err := ExistsTable(ddb, DfsDBPath, TbName2) + re6, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(TbName2)) So(err, ShouldBeNil) So(re6, ShouldBeFalse) }) Convey("Test_existsTable_dfs_value", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_dfs_range", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_dfs_hash", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_dfs_list", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_dfs_compo_range_range", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_dfs_compo_range_value", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeValuedb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_dfs_compo_range_list", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeListdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_dfs_compo_range_hash", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeHashdb(DfsDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + defer ddb.DropDatabase(&api.DropDatabaseRequest{Directory: DfsDBPath}) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DfsDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_disk_unpartitioned_table", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsTable(ddb, DfsDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DfsDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDiskUnpartitioneddb(DiskDBPath, TbName1, TbName2) - re2, err := ExistsTable(ddb, DiskDBPath, TbName1) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, TbName1, DiskDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(TbName1).SetDBPath(DiskDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DiskDBPath, "tdata") + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName("tdata")) So(err, ShouldBeNil) So(re3, ShouldBeFalse) - err = DropDatabase(ddb, DiskDBPath) - So(err, ShouldBeNil) }) Convey("Test_existsTable_disk_range", func() { - re1, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDiskRangedb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DiskDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DiskDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_disk_value", func() { - re1, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDiskValuedb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DiskDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DiskDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_disk_list", func() { - re1, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDiskListdb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DiskDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DiskDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_disk_hash", func() { - re1, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDiskHashdb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DiskDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DiskDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_existsTable_disk_compo_range_range", func() { - re1, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re1, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDiskCompoRangeRangedb(DiskDBPath, DfsTBName1, DfsTBName2) - re2, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) + re2, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re2, ShouldBeTrue) - err = DropTable(ddb, DfsTBName1, DiskDBPath) + err = ddb.DropTable(new(api.DropTableRequest).SetTableName(DfsTBName1).SetDBPath(DiskDBPath)) So(err, ShouldBeNil) - re3, err := ExistsTable(ddb, DiskDBPath, DfsTBName1) + re3, err := ddb.ExistsTable(new(api.ExistsTableRequest).SetDBPath(DiskDBPath).SetTableName(DfsTBName1)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) diff --git a/test/extras/basicChart_test.go b/test/extras/basicChart_test.go index c8e0072..94d106e 100644 --- a/test/extras/basicChart_test.go +++ b/test/extras/basicChart_test.go @@ -4,9 +4,9 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/extras/basicDataTypeList_test.go b/test/extras/basicDataTypeList_test.go index d2310f4..070ce5c 100644 --- a/test/extras/basicDataTypeList_test.go +++ b/test/extras/basicDataTypeList_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/extras/basicDataType_test.go b/test/extras/basicDataType_test.go index b672533..792e729 100644 --- a/test/extras/basicDataType_test.go +++ b/test/extras/basicDataType_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/extras/basicDataform_test.go b/test/extras/basicDataform_test.go index 05b2433..3fe2676 100644 --- a/test/extras/basicDataform_test.go +++ b/test/extras/basicDataform_test.go @@ -4,8 +4,8 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/extras/basicDictionary_test.go b/test/extras/basicDictionary_test.go index ae1e449..edfeeca 100644 --- a/test/extras/basicDictionary_test.go +++ b/test/extras/basicDictionary_test.go @@ -4,8 +4,8 @@ import ( "bytes" "testing" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/extras/basicMatrix_test.go b/test/extras/basicMatrix_test.go index 21ef8af..3321f62 100644 --- a/test/extras/basicMatrix_test.go +++ b/test/extras/basicMatrix_test.go @@ -3,7 +3,7 @@ package test import ( "testing" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/extras/basicTable_test.go b/test/extras/basicTable_test.go index 71ce1fa..9ece1f8 100644 --- a/test/extras/basicTable_test.go +++ b/test/extras/basicTable_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/dialer/protocol" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/dialer/protocol" + "github.com/dolphindb/api-go/v3/model" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/extras/basicVector_test.go b/test/extras/basicVector_test.go index 80f6a67..9110c2c 100644 --- a/test/extras/basicVector_test.go +++ b/test/extras/basicVector_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/model" + "github.com/dolphindb/api-go/v3/model" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/loadTableBySQL_test.go b/test/loadTableBySQL_test.go index e72ff45..fa9494a 100644 --- a/test/loadTableBySQL_test.go +++ b/test/loadTableBySQL_test.go @@ -4,50 +4,33 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) var host10 = getRandomClusterAddress() + func TestLoadTableBySQL(t *testing.T) { t.Parallel() Convey("Test LoadTableBySQL prepare", t, func() { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host10, setup.UserName, setup.Password) So(err, ShouldBeNil) - Convey("Drop all Databases", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - dbPaths := []string{DfsDBPath, DiskDBPath} - for _, dbPath := range dbPaths { - script := ` - if(existsDatabase("` + dbPath + `")){ - dropDatabase("` + dbPath + `") - } - if(exists("` + dbPath + `")){ - rmdir("` + dbPath + `", true) - } - ` - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - re, err := ddb.RunScript(`existsDatabase("` + dbPath + `")`) - So(err, ShouldBeNil) - isExitsDatabase := re.(*model.Scalar).DataType.Value() - So(isExitsDatabase, ShouldBeFalse) - } - }) Convey("Test_LoadTableBySQL_dfs_dimension:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsDimensiondb(DfsDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) _, err = LoadTableBySQL(ddb, "[2010.01.05, 2010.01.15, 2010.01.19]", "select * from loadTable('"+DfsDBPath+"','"+TbName1+"') where date in %s", DfsDBPath, TbName1) So(err, ShouldNotBeNil) }) Convey("Test_LoadTableBySQL_dfs_range:", func() { DfsDBPath := "dfs://" + generateRandomString(8) CreateDfsRangedb(DfsDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -57,16 +40,17 @@ func TestLoadTableBySQL(t *testing.T) { So(re1, ShouldBeTrue) err = DropDatabase(ddb, DfsDBPath) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTableBySQL_dfs_hash:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -76,16 +60,17 @@ func TestLoadTableBySQL(t *testing.T) { So(re2, ShouldBeTrue) err = DropDatabase(ddb, DfsDBPath) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTableBySQL_dfs_value:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -95,16 +80,17 @@ func TestLoadTableBySQL(t *testing.T) { So(re2, ShouldBeTrue) err = DropDatabase(ddb, DfsDBPath) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTableBySQL_dfs_list:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -114,16 +100,17 @@ func TestLoadTableBySQL(t *testing.T) { So(re2, ShouldBeTrue) err = DropDatabase(ddb, DfsDBPath) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTableBySQL_dfs_compo:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -133,17 +120,19 @@ func TestLoadTableBySQL(t *testing.T) { So(re2, ShouldBeTrue) err = DropDatabase(ddb, DfsDBPath) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTableBySQL_disk_unpartitioned:", func() { CreateDiskUnpartitioneddb(DiskDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) _, err := LoadTableBySQL(ddb, "[2010.01.05, 2010.01.15, 2010.01.19]", "select * from loadTable('"+DiskDBPath+"','"+TbName1+"') where date in %s", DiskDBPath, TbName1) So(err, ShouldNotBeNil) }) Convey("Test_LoadTableBySQL_disk_range:", func() { CreateDiskRangedb(DiskDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -154,6 +143,7 @@ func TestLoadTableBySQL(t *testing.T) { }) Convey("Test_LoadTableBySQL_disk_hash:", func() { CreateDiskHashdb(DiskDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -164,6 +154,7 @@ func TestLoadTableBySQL(t *testing.T) { }) Convey("Test_LoadTableBySQL_disk_value:", func() { CreateDiskValuedb(DiskDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -174,6 +165,7 @@ func TestLoadTableBySQL(t *testing.T) { }) Convey("Test_LoadTableBySQL_disk_list:", func() { CreateDiskListdb(DiskDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) @@ -184,6 +176,7 @@ func TestLoadTableBySQL(t *testing.T) { }) Convey("Test_LoadTableBySQL_disk_compo_range_range:", func() { CreateDiskCompoRangeRangedb(DiskDBPath, TbName1, TbName2) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DiskDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where date in [2010.01.05, 2010.01.15, 2010.01.19]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) diff --git a/test/loadTable_test.go b/test/loadTable_test.go index 376333e..10d0b58 100644 --- a/test/loadTable_test.go +++ b/test/loadTable_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) @@ -18,280 +18,261 @@ func TestLoadTable(t *testing.T) { Convey("Test LoadTable prepare", t, func() { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host9, setup.UserName, setup.Password) So(err, ShouldBeNil) - Convey("Drop all Databases", func() { - DfsDBPath := "dfs://" + generateRandomString(8) - dbPaths := []string{DfsDBPath, DiskDBPath} - for _, dbPath := range dbPaths { - script := ` - if(existsDatabase("` + dbPath + `")){ - dropDatabase("` + dbPath + `") - } - if(exists("` + dbPath + `")){ - rmdir("` + dbPath + `", true) - } - ` - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - re, err := ddb.RunScript(`existsDatabase("` + dbPath + `")`) - So(err, ShouldBeNil) - isExitsDatabase := re.(*model.Scalar).DataType.Value() - So(isExitsDatabase, ShouldBeFalse) - } - }) Convey("Test_LoadTable_dfs_dimension:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsDimensiondb(DfsDBPath, TbName1, TbName2) + // defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) _, err = ddb.RunScript(fmt.Sprintf(`select * from %s`, "''")) So(err, ShouldNotBeNil) So(err.Error(), ShouldContainSubstring, `RefId:S02033`) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DfsDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re2 := CompareTablesDataformTable(exTmp, reTmp) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_range:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, TbName1, TbName2) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DfsDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re2 := CompareTablesDataformTable(exTmp, reTmp) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_range_memoryMode_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, TbName1, TbName2) - _, err = LoadTableMemoryMode(ddb, TbName1, DfsDBPath, true) + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetMemoryMode(true)) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_range_partitions_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsRangedb(DfsDBPath, TbName1, TbName2) - _, err = LoadTablePartitions(ddb, TbName1, DfsDBPath, "5000") + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetPartitions("5000")) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_hash:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, TbName1, TbName2) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DfsDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re2 := CompareTablesDataformTable(exTmp, reTmp) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_hash_memoryMode_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, TbName1, TbName2) - _, err = LoadTableMemoryMode(ddb, TbName1, DfsDBPath, true) + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetMemoryMode(true)) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_hash_partitions_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsHashdb(DfsDBPath, TbName1, TbName2) - _, err = LoadTablePartitions(ddb, TbName1, DfsDBPath, "1") + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetPartitions("1")) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_value:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, TbName1, TbName2) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DfsDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re2 := CompareTablesDataformTable(exTmp, reTmp) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_value_memoryMode_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, TbName1, TbName2) - _, err = LoadTableMemoryMode(ddb, TbName1, DfsDBPath, true) + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetMemoryMode(true)) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_value_partitions_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsValuedb(DfsDBPath, TbName1, TbName2) - _, err = LoadTablePartitions(ddb, TbName1, DfsDBPath, "2010.01.01") + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetPartitions("2010.01.01")) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_list:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, TbName1, TbName2) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DfsDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re2 := CompareTablesDataformTable(exTmp, reTmp) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_list_memoryMode_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, TbName1, TbName2) - _, err = LoadTableMemoryMode(ddb, TbName1, DfsDBPath, true) + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetMemoryMode(true)) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_list_partitions_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsListdb(DfsDBPath, TbName1, TbName2) - _, err = LoadTablePartitions(ddb, TbName1, DfsDBPath, "`DOP") + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetPartitions("`DOP")) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_compo:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, TbName1, TbName2) tmp, err := ddb.RunScript(`select * from loadTable("` + DfsDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DfsDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re2 := CompareTablesDataformTable(exTmp, reTmp) So(re2, ShouldBeTrue) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re3, err := ExistsDatabase(ddb, DfsDBPath) + re3, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re3, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_compo_range_range_memoryMode_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, TbName1, TbName2) - _, err = LoadTableMemoryMode(ddb, TbName1, DfsDBPath, true) + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetMemoryMode(true)) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) Convey("Test_LoadTable_dfs_compo_range_range_partitions_exception:", func() { DfsDBPath := "dfs://" + generateRandomString(8) - re1, err := ExistsDatabase(ddb, DfsDBPath) + re1, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re1, ShouldBeFalse) CreateDfsCompoRangeRangedb(DfsDBPath, TbName1, TbName2) - _, err = LoadTablePartitions(ddb, TbName1, DfsDBPath, "2010.01.01") + _, err = ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DfsDBPath).SetTableName(TbName1).SetPartitions("2010.01.01")) So(err, ShouldNotBeNil) - err = DropDatabase(ddb, DfsDBPath) + err = ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) So(err, ShouldBeNil) - re2, err := ExistsDatabase(ddb, DfsDBPath) + re2, err := ddb.ExistsDatabase(new(api.ExistsDatabaseRequest).SetPath(DfsDBPath)) So(err, ShouldBeNil) So(re2, ShouldBeFalse) }) @@ -300,7 +281,7 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DiskDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -310,7 +291,7 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DiskDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -320,7 +301,9 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where id < 20001`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, `[5000, 15000]`) + // reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, `[5000, 15000]`) + + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1).SetPartitions("[5000, 15000]")) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -331,7 +314,7 @@ func TestLoadTable(t *testing.T) { So(err, ShouldBeNil) exTmp := tmp.(*model.Table) // before, _ := ddb.RunScript("exec memSize from getSessionMemoryStat()") - reTmp, err := LoadTableMemoryMode(ddb, TbName1, DiskDBPath, true) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1).SetMemoryMode(true)) So(err, ShouldBeNil) // after, _ := ddb.RunScript("exec memSize from getSessionMemoryStat()") re1 := CompareTablesDataformTable(exTmp, reTmp) @@ -345,7 +328,7 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DiskDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -355,7 +338,7 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where id in [1, 3, 5]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, "[1, 3, 5]") + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1).SetPartitions("[1, 3, 5]")) So(err, ShouldBeNil) re := CompareTablesDataformTable(exTmp, reTmp) So(re, ShouldBeTrue) @@ -366,7 +349,7 @@ func TestLoadTable(t *testing.T) { So(err, ShouldBeNil) exTmp := tmp.(*model.Table) before, _ := ddb.RunScript("exec memSize from getSessionMemoryStat()") - reTmp, err := LoadTableMemoryMode(ddb, TbName1, DiskDBPath, true) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1).SetMemoryMode(true)) So(err, ShouldBeNil) after, _ := ddb.RunScript("exec memSize from getSessionMemoryStat()") re1 := CompareTablesDataformTable(exTmp, reTmp) @@ -380,7 +363,7 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DiskDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -390,7 +373,8 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where id in [2010.01.01, 2010.01.30]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, "[2010.01.01, 2010.01.30]") + // reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, "[2010.01.01, 2010.01.30]") + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1).SetPartitions("[2010.01.01, 2010.01.30]")) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -400,7 +384,7 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DiskDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -410,7 +394,9 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where sym in ["DOP", "ASZ", "FSD", "BBVC","AWQ","DS"]`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, `["DOP", "FSD", "AWQ"]`) + // reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, `["DOP", "FSD", "AWQ"]`) + + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1).SetPartitions(`["DOP", "FSD", "AWQ"]`)) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -421,7 +407,7 @@ func TestLoadTable(t *testing.T) { So(err, ShouldBeNil) exTmp := tmp.(*model.Table) before, _ := ddb.RunScript("exec memSize from getSessionMemoryStat()") - reTmp, err := LoadTableMemoryMode(ddb, TbName1, DiskDBPath, true) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1).SetMemoryMode(true)) So(err, ShouldBeNil) after, _ := ddb.RunScript("exec memSize from getSessionMemoryStat()") re1 := CompareTablesDataformTable(exTmp, reTmp) @@ -435,7 +421,7 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `")`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTable(ddb, TbName1, DiskDBPath) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1)) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -445,7 +431,8 @@ func TestLoadTable(t *testing.T) { tmp, err := ddb.RunScript(`select * from loadTable("` + DiskDBPath + `", "` + TbName1 + `") where date between 2010.01.01:2010.01.31 or date between 2010.04.01:2010.04.30`) So(err, ShouldBeNil) exTmp := tmp.(*model.Table) - reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, `[2010.01.01, 2010.04.25]`) + // reTmp, err := LoadTablePartitions(ddb, TbName1, DiskDBPath, `[2010.01.01, 2010.04.25]`) + reTmp, err := ddb.LoadTable(new(api.LoadTableRequest).SetDatabase(DiskDBPath).SetTableName(TbName1).SetPartitions("[2010.01.01, 2010.04.25]")) So(err, ShouldBeNil) re1 := CompareTablesDataformTable(exTmp, reTmp) So(re1, ShouldBeTrue) @@ -457,6 +444,7 @@ func TestLoadTable(t *testing.T) { t = table(1 2 3 as c1, rand(100.00, 3) as c2); db.createPartitionedTable(t, '` + tbName + `', 'c1').append!(t)`) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(dbName)) l := &api.LoadTableRequest{ Database: dbName, TableName: tbName, @@ -467,7 +455,8 @@ func TestLoadTable(t *testing.T) { s := lt.GetHandle() res, _ := ddb.RunScript("select * from " + s) ex, _ := ddb.RunScript(s + `=select * from loadTable("` + dbName + `", "` + tbName + `");` + s) - So(res, ShouldEqual, ex.(*model.Table)) + // So(res, ShouldEqual, ex.(*model.Table)) + So(res, ShouldResemble, ex.(*model.Table)) } }) }) diff --git a/test/loadText_test.go b/test/loadText_test.go index 33fb362..60ff30c 100644 --- a/test/loadText_test.go +++ b/test/loadText_test.go @@ -4,13 +4,14 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) var host11 = getRandomClusterAddress() + func TestLoadTest(t *testing.T) { t.Parallel() Convey("test_loadText_prepare", t, func() { @@ -28,7 +29,7 @@ func TestLoadTest(t *testing.T) { So(err, ShouldBeNil) ex := tmp.(*model.Table) So(err, ShouldBeNil) - re, err := LoadTextFileName(ddb, data) + re, err := ddb.LoadText(new(api.LoadTextRequest).SetFileName(data)) So(err, ShouldBeNil) result := CompareTablesDataformTable(ex, re) So(result, ShouldBeTrue) @@ -37,7 +38,7 @@ func TestLoadTest(t *testing.T) { tmp, err := ddb.RunScript("select * from loadText(\"" + data + "\", ';')") ex := tmp.(*model.Table) So(err, ShouldBeNil) - re, err := LoadTextDelimiter(ddb, data, ";") + re, err := ddb.LoadText(new(api.LoadTextRequest).SetFileName(data).SetDelimiter(";")) So(err, ShouldBeNil) result := CompareTablesDataformTable(ex, re) So(result, ShouldBeTrue) diff --git a/test/multigoroutinetable_test.go b/test/multigoroutinetable_test.go index db92a0a..7fa0f97 100644 --- a/test/multigoroutinetable_test.go +++ b/test/multigoroutinetable_test.go @@ -4,14 +4,13 @@ import ( "context" "fmt" "strconv" - "sync" "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - mtw "github.com/dolphindb/api-go/multigoroutinetable" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + mtw "github.com/dolphindb/api-go/v3/multigoroutinetable" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) @@ -23,7 +22,6 @@ var ( ) var host12 = getRandomClusterAddress() -var waitGroup sync.WaitGroup func CreateTimeList(n int, timeFomat string, timeList []string) []time.Time { ex := []time.Time{} @@ -123,80 +121,63 @@ func insertalldatatype(mtt *mtw.MultiGoroutineTable) Tuple { return Tuple{colBool, colchar, colshort, colInt, collong, coldate, colmonthv, coltimestamp, colfloat, coldouble, colstring, colsym, coluuid, colInt128, colipaddr, coldecimal32, coldecimal64, coldecimal128} } -func threadinsertData(mtt *mtw.MultiGoroutineTable, n int) { - i := 0 - for { - err := mtt.Insert("AAPL"+strconv.Itoa(i%10), - time.Date(1969, time.Month(12), i%10+1, 23, i%10, 50, 000, time.UTC), - float64(22.5)+float64(i), float64(14.6)+float64(i), int32(i%10), float64(i)) - AssertNil(err) +func threadinsertData(mtt *mtw.MultiGoroutineTable, imT string) { + implconn, _ := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) + defer implconn.Close() + t, err := implconn.RunScript("select * from " + imT + " order by tradeDate") + AssertNil(err) + for i := 0; i < t.(*model.Table).Rows(); i++ { + col0Val := t.(*model.Table).GetColumnByIndex(0).Get(i).Value() + col1Val := t.(*model.Table).GetColumnByIndex(1).Get(i).Value() + col2Val := t.(*model.Table).GetColumnByIndex(2).Get(i).Value() + col3Val := t.(*model.Table).GetColumnByIndex(3).Get(i).Value() + col4Val := t.(*model.Table).GetColumnByIndex(4).Get(i).Value() + col5Val := t.(*model.Table).GetColumnByIndex(5).Get(i).Value() + // fmt.Println("col0Val:", col0Val, "col1Val:", col1Val, "col2Val:", col2Val, "col3Val:", col3Val, "col4Val:", col4Val, "col5Val:", col5Val) + err = mtt.Insert(col0Val, col1Val, col2Val, col3Val, col4Val, col5Val) if err != nil { - fmt.Println(err) - break - } - if i == n-1 { - break + panic(err) } - i++ } - waitGroup.Done() + // waitGroup.Done() } -func insertDataTotable(n int, tableName string) { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) - AssertNil(err) - var symarr []string - var datetimearr []time.Time - var floatarr1 []float64 - var floatarr2 []float64 - var intarr []int32 - var floatarr3 []float64 - for i := 0; i < n; i++ { - symarr = append(symarr, "AAPL"+strconv.Itoa(i%10)) - datetimearr = append(datetimearr, time.Date(1969, time.Month(12), i%10+1, 23, i%10, 50, 000, time.UTC)) - floatarr1 = append(floatarr1, float64(22.5)+float64(i)) - floatarr2 = append(floatarr2, float64(14.6)+float64(i)) - intarr = append(intarr, int32(i%10)) - floatarr3 = append(floatarr3, float64(i)) - } - sym, _ := model.NewDataTypeListFromRawData(model.DtString, symarr) - tradeDatev, _ := model.NewDataTypeListFromRawData(model.DtDatetime, datetimearr) - tradePrice, _ := model.NewDataTypeListFromRawData(model.DtDouble, floatarr1) - vwap, _ := model.NewDataTypeListFromRawData(model.DtDouble, floatarr2) - volume, _ := model.NewDataTypeListFromRawData(model.DtInt, intarr) - valueTrade, _ := model.NewDataTypeListFromRawData(model.DtDouble, floatarr3) - tmp := model.NewTable([]string{"sym", "tradeDate", "tradePrice", "vwap", "volume", "valueTrade"}, - []*model.Vector{model.NewVector(sym), model.NewVector(tradeDatev), model.NewVector(tradePrice), - model.NewVector(vwap), model.NewVector(volume), model.NewVector(valueTrade)}) - _, err = ddb.RunFunc("tableInsert{"+tableName+"}", []model.DataForm{tmp}) - AssertNil(err) - AssertNil(ddb.Close()) -} +// func insertDataTotable(n int, tableName string) { +// ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) +// AssertNil(err) +// var symarr []string +// var datetimearr []time.Time +// var floatarr1 []float64 +// var floatarr2 []float64 +// var intarr []int32 +// var floatarr3 []float64 +// for i := 0; i < n; i++ { +// symarr = append(symarr, "AAPL"+strconv.Itoa(i%10)) +// datetimearr = append(datetimearr, time.Date(1969, time.Month(12), i%10+1, 23, i%10, 50, 000, time.UTC)) +// floatarr1 = append(floatarr1, float64(22.5)+float64(i)) +// floatarr2 = append(floatarr2, float64(14.6)+float64(i)) +// intarr = append(intarr, int32(i%10)) +// floatarr3 = append(floatarr3, float64(i)) +// } +// sym, _ := model.NewDataTypeListFromRawData(model.DtString, symarr) +// tradeDatev, _ := model.NewDataTypeListFromRawData(model.DtDatetime, datetimearr) +// tradePrice, _ := model.NewDataTypeListFromRawData(model.DtDouble, floatarr1) +// vwap, _ := model.NewDataTypeListFromRawData(model.DtDouble, floatarr2) +// volume, _ := model.NewDataTypeListFromRawData(model.DtInt, intarr) +// valueTrade, _ := model.NewDataTypeListFromRawData(model.DtDouble, floatarr3) +// tmp := model.NewTable([]string{"sym", "tradeDate", "tradePrice", "vwap", "volume", "valueTrade"}, +// []*model.Vector{model.NewVector(sym), model.NewVector(tradeDatev), model.NewVector(tradePrice), +// model.NewVector(vwap), model.NewVector(volume), model.NewVector(valueTrade)}) +// _, err = ddb.RunFunc("tableInsert{"+tableName+"}", []model.DataForm{tmp}) +// AssertNil(err) +// AssertNil(ddb.Close()) +// } func TestMultiGoroutineTable_exception(t *testing.T) { Convey("test_multiGoroutineTable_prepare", t, func() { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - Convey("Drop all Databases", func() { - dbPaths := []string{DBdfsPath, DiskDBPath} - for _, dbPath := range dbPaths { - script := ` - if(existsDatabase("` + dbPath + `")){ - dropDatabase("` + dbPath + `") - } - if(exists("` + dbPath + `")){ - rmdir("` + dbPath + `", true) - } - ` - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - re, err := ddb.RunScript(`existsDatabase("` + dbPath + `")`) - So(err, ShouldBeNil) - isExitsDatabase := re.(*model.Scalar).DataType.Value() - So(isExitsDatabase, ShouldBeFalse) - } - }) Convey("test_multiGoroutineTable_exception", func() { Convey("test_multiGoroutineTable_error_hostName_exception", func() { scriptDFSHASH := ` @@ -209,6 +190,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -234,6 +216,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -259,6 +242,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -284,6 +268,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -309,6 +294,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -334,6 +320,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -359,6 +346,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -384,6 +372,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -409,6 +398,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -434,6 +424,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -459,6 +450,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 0, @@ -484,6 +476,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: -1, @@ -509,6 +502,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 0, BatchSize: 1, @@ -534,6 +528,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: -3, BatchSize: 1, @@ -568,6 +563,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptusernograntwrite) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -595,6 +591,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { scriptMemoryTable := "t = table(1000:0, `id`x, [LONG, LONG]);share t as shareTable;" _, err = ddb.RunScript(scriptMemoryTable) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -622,6 +619,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -647,6 +645,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -672,6 +671,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 3, BatchSize: 1, @@ -697,6 +697,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -725,6 +726,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { scriptMemoryTable := "t = table(1000:0, `id`x, [LONG, LONG]);share t as shareTable;" _, err = ddb.RunScript(scriptMemoryTable) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -752,6 +754,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -779,6 +782,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -806,6 +810,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { ` _, err = ddb.RunScript(scriptDFSHASH) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -826,6 +831,7 @@ func TestMultiGoroutineTable_exception(t *testing.T) { scriptGoroutineCount := "t = table(1000:0, `date`id`values,[TIMESTAMP,SYMBOL,INT]);share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -862,7 +868,8 @@ func TestMultiGoroutineTable_exception(t *testing.T) { So(mtt.GetStatus().IsExit, ShouldBeTrue) }) Convey("TestMultiGoroutineTable_insert_dfs_value_value_ex", func() { - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -873,12 +880,13 @@ func TestMultiGoroutineTable_exception(t *testing.T) { "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\", \"volume\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "sym", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -886,10 +894,6 @@ func TestMultiGoroutineTable_exception(t *testing.T) { } _, err = mtw.NewMultiGoroutineTable(opt) So(err, ShouldNotBeNil) - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) }) }) }) @@ -905,6 +909,7 @@ func TestMultiGoroutineTable_all_data_type(t *testing.T) { share t as all_data_type` _, err = ddb.RunScript(scriptalldatatype) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("all_data_type").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 1, @@ -988,8 +993,6 @@ func TestMultiGoroutineTable_all_data_type(t *testing.T) { So(redecimal128v[i], ShouldResemble, coldecimal128[i]) } - _, err = ddb.RunScript("undef(`all_data_type, SHARED)") - So(err, ShouldBeNil) err = ddb.Close() So(err, ShouldBeNil) }) @@ -1002,6 +1005,7 @@ func TestMultiGoroutineTable_GoroutineCount(t *testing.T) { s := "t = table(1:0, `date`id`values,[TIMESTAMP,SYMBOL,INT]);share t as t1;" _, err = ddb.RunScript(s) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 5, BatchSize: 10, @@ -1038,6 +1042,7 @@ func TestMultiGoroutineTable_null(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1058,8 +1063,7 @@ func TestMultiGoroutineTable_null(t *testing.T) { So(err, ShouldBeNil) reTable := re.(*model.Table) So(reTable.Rows(), ShouldEqual, 1) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) Convey("test_multithreadTableWriterTest_insert_parted_null", func() { @@ -1068,6 +1072,7 @@ func TestMultiGoroutineTable_null(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1088,8 +1093,7 @@ func TestMultiGoroutineTable_null(t *testing.T) { So(err, ShouldBeNil) reTable := re.(*model.Table) So(reTable.Rows(), ShouldEqual, 1) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) err = ddb.Close() So(err, ShouldBeNil) @@ -1103,6 +1107,7 @@ func TestMultiGoroutineTable_getStatus_write_successful(t *testing.T) { scriptGoroutineCount := "t = streamTable(1000:0, `intv`datev,[INT,DATE]);" + "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1126,8 +1131,7 @@ func TestMultiGoroutineTable_getStatus_write_successful(t *testing.T) { So(status.ErrMsg, ShouldEqual, "") So(status.IsExit, ShouldBeTrue) So(status.SentRows, ShouldEqual, 15) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + err = ddb.Close() So(err, ShouldBeNil) }) @@ -1140,6 +1144,7 @@ func TestMultithreadTableWriterTest_getStatus_write_successful_normalData(t *tes scriptGoroutineCount := "t = streamTable(1000:0, `intv`datev,[INT,DATE]);" + "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 100000, @@ -1168,8 +1173,7 @@ func TestMultithreadTableWriterTest_getStatus_write_successful_normalData(t *tes So(status.ErrMsg, ShouldEqual, "") So(status.IsExit, ShouldBeTrue) So(status.SentRows, ShouldEqual, 15) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + err = ddb.Close() So(err, ShouldBeNil) }) @@ -1184,6 +1188,7 @@ func TestMultiGoroutineTable_insert_bool(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1212,8 +1217,7 @@ func TestMultiGoroutineTable_insert_bool(t *testing.T) { So(reTable.GetColumnByName("bool").Data.Value()[0], ShouldEqual, true) So(reTable.GetColumnByName("bool").Data.Value()[1], ShouldEqual, false) So(reTable.GetColumnByName("bool").Get(2).IsNull(), ShouldEqual, true) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + err = ddb.Close() So(err, ShouldBeNil) }) @@ -1227,6 +1231,7 @@ func TestMultiGoroutineTable_insert_byte_int32_int64_int16(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1254,8 +1259,6 @@ func TestMultiGoroutineTable_insert_byte_int32_int64_int16(t *testing.T) { So(reTable.GetColumnByName("short").String(), ShouldEqual, "vector([1, 1])") So(reTable.GetColumnByName("char").Data.Value()[0], ShouldEqual, 1) So(reTable.GetColumnByName("char").Get(1).IsNull(), ShouldEqual, true) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) err = ddb.Close() So(err, ShouldBeNil) }) @@ -1271,6 +1274,7 @@ func TestMultiGoroutineTable_insert_float32_float64(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1298,8 +1302,7 @@ func TestMultiGoroutineTable_insert_float32_float64(t *testing.T) { So(reTable.GetColumnByName("floatv").Get(1).IsNull(), ShouldEqual, true) So(reTable.GetColumnByName("doublev").Data.Value()[0], ShouldEqual, float64(5.6)) So(reTable.GetColumnByName("doublev").Get(1).IsNull(), ShouldEqual, true) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -1313,6 +1316,7 @@ func TestMultiGoroutineTable_streamTable_insert_timetype(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 5, @@ -1385,8 +1389,7 @@ func TestMultiGoroutineTable_streamTable_insert_timetype(t *testing.T) { So(reTable.GetColumnByName("timev").Get(2).String(), ShouldEqual, "23:59:59.154") So(reTable.GetColumnByName("nanotimev").Get(2).String(), ShouldEqual, "23:59:59.154140487") So(reTable.GetColumnByName("nanotimestampv").Get(2).IsNull(), ShouldEqual, true) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -1400,6 +1403,7 @@ func TestMultiGoroutineTable_memTable_insert_timetype(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 5, @@ -1472,8 +1476,7 @@ func TestMultiGoroutineTable_memTable_insert_timetype(t *testing.T) { So(reTable.GetColumnByName("timev").Get(2).String(), ShouldEqual, "23:59:59.154") So(reTable.GetColumnByName("nanotimev").Get(2).String(), ShouldEqual, "23:59:59.154140487") So(reTable.GetColumnByName("nanotimestampv").Get(2).IsNull(), ShouldEqual, true) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -1491,6 +1494,7 @@ func TestMultiGoroutineTable_dfsTable_insert_timetype(t *testing.T) { pt=db.createPartitionedTable(t, "` + DfsTableName1 + `", 'datev')` _, err = ddb.RunScript(scriptdfshashtable) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 5, @@ -1563,8 +1567,7 @@ func TestMultiGoroutineTable_dfsTable_insert_timetype(t *testing.T) { So(reTable.GetColumnByName("timev").Get(2).String(), ShouldEqual, "23:59:59.154") So(reTable.GetColumnByName("nanotimev").Get(2).String(), ShouldEqual, "23:59:59.154140487") So(reTable.GetColumnByName("nanotimestampv").Get(2).IsNull(), ShouldEqual, true) - _, err = ddb.RunScript("dropDatabase('" + DBdfsPath + "')") - So(err, ShouldBeNil) + }) } @@ -1582,6 +1585,7 @@ func TestMultiGoroutineTable_dimensionTable_insert_timetype(t *testing.T) { pt=db.createTable(t, "` + DfsTableName1 + `")` _, err = ddb.RunScript(scriptdfshashtable) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DBdfsPath)) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 5, @@ -1654,8 +1658,7 @@ func TestMultiGoroutineTable_dimensionTable_insert_timetype(t *testing.T) { So(reTable.GetColumnByName("timev").Get(2).String(), ShouldEqual, "23:59:59.154") So(reTable.GetColumnByName("nanotimev").Get(2).String(), ShouldEqual, "23:59:59.154140487") So(reTable.GetColumnByName("nanotimestampv").Get(2).IsNull(), ShouldEqual, true) - _, err = ddb.RunScript("dropDatabase('" + DBdfsPath + "')") - So(err, ShouldBeNil) + }) } @@ -1669,6 +1672,7 @@ func TestMultiGoroutineTable_memTable_insert_localTime(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 5, @@ -1741,8 +1745,7 @@ func TestMultiGoroutineTable_memTable_insert_localTime(t *testing.T) { So(reTable.GetColumnByName("timev").Get(2).String(), ShouldEqual, "23:59:59.154") So(reTable.GetColumnByName("nanotimev").Get(2).String(), ShouldEqual, "23:59:59.154140487") So(reTable.GetColumnByName("nanotimestampv").Get(2).IsNull(), ShouldEqual, true) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -1751,7 +1754,8 @@ func TestMultiGoroutineTable_insert_dfs_part_null(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - scriptGoroutineCount := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + scriptGoroutineCount := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -1760,12 +1764,13 @@ func TestMultiGoroutineTable_insert_dfs_part_null(t *testing.T) { "pt = db.createTable(t,`pt);" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 5, Throttle: 1000, PartitionCol: "boolv", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -1776,7 +1781,7 @@ func TestMultiGoroutineTable_insert_dfs_part_null(t *testing.T) { err = mtt.Insert(byte(1), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) So(err, ShouldBeNil) mtt.WaitForGoroutineCompletion() - re, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt);") + re, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt);") So(err, ShouldBeNil) reTable := re.(*model.Table) So(reTable.Rows(), ShouldEqual, 1) @@ -1803,8 +1808,7 @@ func TestMultiGoroutineTable_insert_dfs_part_null(t *testing.T) { So(reTable.GetColumnByName("ipaddrv").String(), ShouldEqual, "vector([0.0.0.0])") So(reTable.GetColumnByName("int128v").String(), ShouldEqual, "vector([00000000000000000000000000000000])") So(reTable.GetColumnByName("id").String(), ShouldEqual, "vector([])") - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -1818,6 +1822,7 @@ func TestMultiGoroutineTable_insert_empty_arrayVector(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1842,8 +1847,7 @@ func TestMultiGoroutineTable_insert_empty_arrayVector(t *testing.T) { reArrayv := reTable.GetColumnByName("arrayv") So(reIDv.String(), ShouldEqual, "vector([10])") So(reArrayv.String(), ShouldEqual, "vector([[]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -1857,6 +1861,7 @@ func TestMultiGoroutineTable_insert_arrayVector_different_length(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1887,8 +1892,7 @@ func TestMultiGoroutineTable_insert_arrayVector_different_length(t *testing.T) { So(reTable.GetColumnByName("arrayv").GetVectorValue(0).String(), ShouldEqual, "vector([1, 3])") So(reTable.GetColumnByName("arrayv").GetVectorValue(1).String(), ShouldEqual, "vector([])") So(reTable.GetColumnByName("arrayv").GetVectorValue(2).String(), ShouldEqual, "vector([1, 2, ])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -1902,6 +1906,7 @@ func TestMultiGoroutineTable_insert_arrayVector_char(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1928,8 +1933,7 @@ func TestMultiGoroutineTable_insert_arrayVector_char(t *testing.T) { reArrayv := reTable.GetColumnByName("charArr") So(reIDv.String(), ShouldEqual, "vector([10, 10])") So(reArrayv.String(), ShouldEqual, "vector([[], [, 4]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -1943,6 +1947,7 @@ func TestMultiGoroutineTable_insert_arrayVector_int(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -1969,8 +1974,7 @@ func TestMultiGoroutineTable_insert_arrayVector_int(t *testing.T) { reArrayv := reTable.GetColumnByName("Arr") So(reIDv.String(), ShouldEqual, "vector([10, 3])") So(reArrayv.String(), ShouldEqual, "vector([[], [, 4]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -1984,6 +1988,7 @@ func TestMultiGoroutineTable_insert_arrayVector_bool(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2010,8 +2015,7 @@ func TestMultiGoroutineTable_insert_arrayVector_bool(t *testing.T) { reArrayv := reTable.GetColumnByName("Arr") So(reIDv.String(), ShouldEqual, "vector([10, 3])") So(reArrayv.String(), ShouldEqual, "vector([[], [, true]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2025,6 +2029,7 @@ func TestMultiGoroutineTable_insert_arrayVector_long(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2053,8 +2058,7 @@ func TestMultiGoroutineTable_insert_arrayVector_long(t *testing.T) { reArrayv := reTable.GetColumnByName("Arr") So(reIDv.String(), ShouldEqual, "vector([10, 3])") So(reArrayv.String(), ShouldEqual, "vector([[], [, 45]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2068,6 +2072,7 @@ func TestMultiGoroutineTable_insert_arrayVector_short(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2096,8 +2101,7 @@ func TestMultiGoroutineTable_insert_arrayVector_short(t *testing.T) { reArrayv := reTable.GetColumnByName("Arr") So(reIDv.String(), ShouldEqual, "vector([10, 3])") So(reArrayv.String(), ShouldEqual, "vector([[], [, 15]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2111,6 +2115,7 @@ func TestMultiGoroutineTable_insert_arrayVector_float(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2137,8 +2142,7 @@ func TestMultiGoroutineTable_insert_arrayVector_float(t *testing.T) { reArrayv := reTable.GetColumnByName("Arr") So(reIDv.String(), ShouldEqual, "vector([10, 3])") So(reArrayv.String(), ShouldEqual, "vector([[], [, 2.6]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2152,6 +2156,7 @@ func TestMultiGoroutineTable_insert_arrayVector_double(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2178,8 +2183,7 @@ func TestMultiGoroutineTable_insert_arrayVector_double(t *testing.T) { reArrayv := reTable.GetColumnByName("Arr") So(reIDv.String(), ShouldEqual, "vector([10, 3])") So(reArrayv.String(), ShouldEqual, "vector([[], [, 2.6]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + So(err, ShouldBeNil) }) } @@ -2194,6 +2198,7 @@ func TestMultiGoroutineTable_insert_arrayVector_date_month(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2222,8 +2227,7 @@ func TestMultiGoroutineTable_insert_arrayVector_date_month(t *testing.T) { So(reIDv.String(), ShouldEqual, "vector([10, 3])") So(reArray1v.String(), ShouldEqual, "vector([[], [, 1969.12.05, ]])") So(reArray2v.String(), ShouldEqual, "vector([[], [, 1969.12M]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2237,6 +2241,7 @@ func TestMultiGoroutineTable_insert_arrayVector_time_minute_month(t *testing.T) "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2267,8 +2272,7 @@ func TestMultiGoroutineTable_insert_arrayVector_time_minute_month(t *testing.T) So(reArray1v.String(), ShouldEqual, "vector([[], [, 23:56:59.456, ]])") So(reArray2v.String(), ShouldEqual, "vector([[], [, 23:56m]])") So(reArray3v.String(), ShouldEqual, "vector([[], [, 23:56:59]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2282,6 +2286,7 @@ func TestMultiGoroutineTable_insert_arrayVector_datetime_timestamp_nanotime_nano "share t as t1;" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2314,8 +2319,7 @@ func TestMultiGoroutineTable_insert_arrayVector_datetime_timestamp_nanotime_nano So(reArray2v.String(), ShouldEqual, "vector([[], [, 1969.12.05T23:56:59.456]])") So(reArray3v.String(), ShouldEqual, "vector([[], [, 23:56:59.456789123]])") So(reArray4v.String(), ShouldEqual, "vector([[, 1970.02.05T23:56:59.999999999, ], []])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2359,8 +2363,7 @@ func TestMultiGoroutineTable_insert_arrayVector_otherType(t *testing.T) { So(reArray1v.String(), ShouldEqual, "vector([[5d212a78-cc48-e3b1-4235-b4d91473ee87, 5d212a78-cc48-e3b1-4235-b4d91473ee87, 00000000-0000-0000-0000-000000000000], [00000000-0000-0000-0000-000000000000]])") So(reArray2v.String(), ShouldEqual, "vector([[e1671797c52e15f763380b45e841ec32, 00000000000000000000000000000000, e1671797c52e15f763380b45e841ec32], [00000000000000000000000000000000]])") So(reArray3v.String(), ShouldEqual, "vector([[192.168.1.13, 192.168.1.84, 0.0.0.0], [0.0.0.0]])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2374,6 +2377,7 @@ func TestMultiGoroutineTable_insert_blob(t *testing.T) { "share t as t1" _, err = ddb.RunScript(scriptGoroutineCount) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2396,8 +2400,7 @@ func TestMultiGoroutineTable_insert_blob(t *testing.T) { So(reTable.Rows(), ShouldEqual, 1) reArray1v := reTable.GetColumnByName("blobv") So(reArray1v.String(), ShouldEqual, "vector([aaaaadsfasdfaa])") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2411,6 +2414,7 @@ func TestMultiGoroutineTable_insert_arrayVector_wrong_type(t *testing.T) { "share t as t1" _, err = ddb.RunScript(s) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 10, @@ -2427,8 +2431,7 @@ func TestMultiGoroutineTable_insert_arrayVector_wrong_type(t *testing.T) { err = mtt.Insert([]int32{1, 2, 3}, []float32{1.1, 2.2, 3.3}) So(err, ShouldNotBeNil) So(err.Error(), ShouldContainSubstring, "the type of input must be []float64 when datatype is DtDouble") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2442,6 +2445,7 @@ func TestMultiGoroutineTable_insert_uuid_int128_ipaddr(t *testing.T) { "share t as t1;" _, err = ddb.RunScript(script1) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1, @@ -2483,8 +2487,7 @@ func TestMultiGoroutineTable_insert_uuid_int128_ipaddr(t *testing.T) { So(reTable.GetColumnByName("ipaddrv").String(), ShouldEqual, "vector([192.168.100.20, 192.168.100.20, 192.168.100.20])") status := mtt.GetStatus() So(len(c1), ShouldEqual, status.UnSentRows+status.SentRows) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2497,6 +2500,7 @@ func TestMultiGoroutineTable_keytable(t *testing.T) { "[SYMBOL, DATETIME, DOUBLE, FLOAT, INT, DOUBLE])\n ;share t as t1;" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 10, @@ -2524,8 +2528,7 @@ func TestMultiGoroutineTable_keytable(t *testing.T) { status := mtt.GetStatus() So(status.SentRows, ShouldEqual, 10000) So(status.UnSentRows, ShouldEqual, 0) - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) + }) } @@ -2534,21 +2537,23 @@ func TestMultiGoroutineTable_insert_dt_multipleThreadCount(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, 2012.01.01..2012.01.30)\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n ;share t as t1;" + + "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;" + "\tcreateTable(dbHandle=db, table=t, tableName=`pt)\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 10, Throttle: 1000, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2556,10 +2561,6 @@ func TestMultiGoroutineTable_insert_dt_multipleThreadCount(t *testing.T) { } _, err = mtw.NewMultiGoroutineTable(opt) So(err.Error(), ShouldContainSubstring, "the parameter GoroutineCount must be 1 for a dimension table") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) }) } @@ -2568,21 +2569,23 @@ func TestMultiGoroutineTable_insert_tsdb_dt_multipleThreadCount(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, 2012.01.01..2012.01.30,,'TSDB')\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n ;share t as t1;" + + "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;" + "\tcreateTable(dbHandle=db, table=t, tableName=`pt,sortColumns=`sym)\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) opt := &mtw.Option{ GoroutineCount: 2, BatchSize: 10, Throttle: 1000, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2590,10 +2593,6 @@ func TestMultiGoroutineTable_insert_tsdb_dt_multipleThreadCount(t *testing.T) { } _, err = mtw.NewMultiGoroutineTable(opt) So(err.Error(), ShouldContainSubstring, "the parameter GoroutineCount must be 1 for a dimension table") - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) }) } func TestMultiGoroutineTable_insert_dt_multipleThread_groutine(t *testing.T) { @@ -2601,21 +2600,26 @@ func TestMultiGoroutineTable_insert_dt_multipleThread_groutine(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, 2012.01.01..2012.01.30)\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n ;share t as t1;" + + // "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + + "share t as t1;" + "\tcreateTable(dbHandle=db, table=t, tableName=`pt)\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 10, Throttle: 1000, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2623,16 +2627,10 @@ func TestMultiGoroutineTable_insert_dt_multipleThread_groutine(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + // insertDataTotable(n, "t1") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -2641,10 +2639,6 @@ func TestMultiGoroutineTable_insert_dt_multipleThread_groutine(t *testing.T) { for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) }) } @@ -2653,21 +2647,24 @@ func TestMultiGoroutineTable_insert_dt_multipleThread_tsdb_groutine(t *testing.T ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, 2012.01.01..2012.01.30,,'TSDB')\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n ;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreateTable(dbHandle=db, table=t, tableName=`pt, sortColumns=`sym)\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 10, Throttle: 1000, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2675,16 +2672,9 @@ func TestMultiGoroutineTable_insert_dt_multipleThread_tsdb_groutine(t *testing.T } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -2693,10 +2683,7 @@ func TestMultiGoroutineTable_insert_dt_multipleThread_tsdb_groutine(t *testing.T for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -2705,21 +2692,24 @@ func TestMultiGoroutineTable_insert_dt_oneThread(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, 2012.01.01..2012.01.30)\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n ;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreateTable(dbHandle=db, table=t, tableName=`pt)\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 10, Throttle: 1000, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2727,16 +2717,9 @@ func TestMultiGoroutineTable_insert_dt_oneThread(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 1 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -2745,10 +2728,6 @@ func TestMultiGoroutineTable_insert_dt_oneThread(t *testing.T) { for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) }) } @@ -2757,21 +2736,24 @@ func TestMultiGoroutineTable_insert_dfs_value(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, month(2012.01.01)+0..1)\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n ;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 10, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2779,16 +2761,9 @@ func TestMultiGoroutineTable_insert_dfs_value(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -2797,10 +2772,7 @@ func TestMultiGoroutineTable_insert_dfs_value(t *testing.T) { for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -2809,21 +2781,24 @@ func TestMultiGoroutineTable_insert_dfs_hash(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, HASH, [SYMBOL,3])\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n ;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"sym\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 10, Throttle: 2, PartitionCol: "sym", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2831,16 +2806,9 @@ func TestMultiGoroutineTable_insert_dfs_hash(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -2849,10 +2817,7 @@ func TestMultiGoroutineTable_insert_dfs_hash(t *testing.T) { for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1,SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -2861,21 +2826,26 @@ func TestMultiGoroutineTable_insert_dfs_list(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + - "if(exists(Database)){\n" + - "\tdropDatabase(Database)\t\n" + - "}\n" + - "db=database(Database, LIST, [`AAPL0`AAPL1`AAPL2, `AAPL3`AAPL4`AAPL5, `AAPL6`AAPL7`AAPL8`AAPL9])\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n ;share t as t1;" + - "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"sym\"])\n" + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := + "db = '" + DfsDBPath + "'\n" + + "if(exists(db)){\n" + + "\tdropDatabase(db)\t\n" + + "}\n" + + "db=database(db, LIST, [`AD`BP, `ZQ`FJS, `AWP`GPW])\n" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);go;share t as t1;" + + "createPartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"sym\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ - GoroutineCount: 1, - BatchSize: 10, - Throttle: 20, + GoroutineCount: 3, + BatchSize: 100, + Throttle: 200, PartitionCol: "sym", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2883,28 +2853,14 @@ func TestMultiGoroutineTable_insert_dfs_list(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - reTable2 := re2.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + ans, _ := ddb.RunScript(` + res = select * from loadTable("` + DfsDBPath + `","pt") order by sym,tradeDate; + ex = select * from t1 order by sym,tradeDate; + all(each(eqObj, res.values(), ex.values())) + `) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) }) } @@ -2913,23 +2869,27 @@ func TestMultiGoroutineTable_insert_dfs_value_value(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_TestMultiGoroutineTable" + fmt.Print(DfsDBPath) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db1=database(\"\", VALUE, 1969.12.01..1969.12.10)\n" + "\tdb2=database(\"\", VALUE, 0..10)\n" + "\tdb=database(Database, COMPO, [db1, db2], , \"OLAP\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, take(2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+10),10000) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, take(1..10, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\", \"volume\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2937,28 +2897,15 @@ func TestMultiGoroutineTable_insert_dfs_value_value(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - reTable2 := re2.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + ans, _ := ddb.RunScript(` + res = select * from loadTable("` + DfsDBPath + `","pt") order by sym,tradeDate,tradePrice; + ex = select * from t1 order by sym,tradeDate,tradePrice; + all(each(eqObj, res.values(), ex.values())) + `) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) + }) } @@ -2967,23 +2914,26 @@ func TestMultiGoroutineTable_insert_dfs_value_range(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db1=database(\"\", VALUE, 1969.12.01..1969.12.10)\n" + - "\tdb2=database(\"\", RANGE,0 5 10)\n" + + "\tdb2=database(\"\", RANGE,0 50000 100000)\n" + "\tdb=database(Database, COMPO, [db1, db2], , \"OLAP\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\", \"volume\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -2991,28 +2941,15 @@ func TestMultiGoroutineTable_insert_dfs_value_range(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - reTable2 := re2.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + ans, _ := ddb.RunScript(` + res = select * from loadTable("` + DfsDBPath + `","pt") order by sym,tradeDate; + ex = select * from t1 order by sym,tradeDate; + all(each(eqObj, res.values(), ex.values())) + `) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) + }) } @@ -3021,23 +2958,26 @@ func TestMultiGoroutineTable_insert_dfs_range_value(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db1=database(\"\", VALUE, 1969.12.01..1969.12.10)\n" + - "\tdb2=database(\"\", RANGE,0 5 10)\n" + + "\tdb2=database(\"\", RANGE,0 50000 100000)\n" + "\tdb=database(Database, COMPO, [db2, db1], , \"OLAP\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"volume\", \"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3045,28 +2985,15 @@ func TestMultiGoroutineTable_insert_dfs_range_value(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - reTable2 := re2.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + ans, _ := ddb.RunScript(` + res = select * from loadTable("` + DfsDBPath + `","pt") order by sym,tradeDate; + ex = select * from t1 order by sym,tradeDate; + all(each(eqObj, res.values(), ex.values())) + `) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) + }) } @@ -3075,23 +3002,26 @@ func TestMultiGoroutineTable_insert_dfs_range_range(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + - "db1=database(\"\", RANGE, 1969.12.01 1969.12.05 1969.12.11)\n" + - "\tdb2=database(\"\", RANGE,0 5 11)\n" + + "db1=database(\"\", RANGE, 2012.02.01 2012.02.05 2012.02.11)\n" + + "\tdb2=database(\"\", RANGE,0 50000 100000)\n" + "\tdb=database(Database, COMPO, [db2, db1], , \"OLAP\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"volume\", \"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3099,28 +3029,15 @@ func TestMultiGoroutineTable_insert_dfs_range_range(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - reTable2 := re2.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + ans, _ := ddb.RunScript(` + res = select * from loadTable("` + DfsDBPath + `","pt") order by sym,tradeDate; + ex = select * from t1 order by sym,tradeDate; + all(each(eqObj, res.values(), ex.values())) + `) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) + }) } @@ -3129,23 +3046,26 @@ func TestMultiGoroutineTable_insert_dfs_range_hash(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + - "db1=database(\"\", RANGE, 1969.12.01 1969.12.05 1969.12.11)\n" + + "db1=database(\"\", RANGE, 2012.02.01 2012.02.05 2012.02.11)\n" + "\tdb2=database(\"\", HASH,[INT,3])\n" + "\tdb=database(Database, COMPO, [db1, db2], , \"OLAP\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\", \"volume\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3153,28 +3073,15 @@ func TestMultiGoroutineTable_insert_dfs_range_hash(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - reTable2 := re2.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + ans, _ := ddb.RunScript(` + res = select * from loadTable("` + DfsDBPath + `","pt") order by sym,tradeDate; + ex = select * from t1 order by sym,tradeDate; + all(each(eqObj, res.values(), ex.values())) + `) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) + }) } @@ -3183,23 +3090,26 @@ func TestMultiGoroutineTable_insert_dfs_hash_range(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + - "db1=database(\"\", RANGE, 1969.12.01 1969.12.05 1969.12.11)\n" + + "db1=database(\"\", RANGE, 2012.02.01 2012.02.05 2012.02.11)\n" + "\tdb2=database(\"\", HASH,[INT,3])\n" + "\tdb=database(Database, COMPO, [db2, db1], , \"OLAP\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"volume\", \"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3207,28 +3117,14 @@ func TestMultiGoroutineTable_insert_dfs_hash_range(t *testing.T) { } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - reTable2 := re2.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + ans, _ := ddb.RunScript(` + res = select * from loadTable("` + DfsDBPath + `","pt") order by sym,tradeDate; + ex = select * from t1 order by sym,tradeDate; + all(each(eqObj, res.values(), ex.values())) + `) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) }) } @@ -3237,7 +3133,8 @@ func TestMultiGoroutineTable_insert_dfs_hash_hash_chunkGranularity_database(t *t ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -3248,12 +3145,14 @@ func TestMultiGoroutineTable_insert_dfs_hash_hash_chunkGranularity_database(t *t "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\",\"sym\"],compressMethods={tradeDate:\"delta\", volume:\"delta\"})\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3261,16 +3160,9 @@ func TestMultiGoroutineTable_insert_dfs_hash_hash_chunkGranularity_database(t *t } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3279,10 +3171,7 @@ func TestMultiGoroutineTable_insert_dfs_hash_hash_chunkGranularity_database(t *t for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3291,23 +3180,26 @@ func TestMultiGoroutineTable_insert_dfs_hash_value_chunkGranularity_database(t * ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db1=database(\"\", HASH, [DATEHOUR,3])\n" + "\tdb2=database(\"\", VALUE, 0..10)\n" + "\tdb=database(Database, COMPO, [db1, db2], , \"OLAP\", chunkGranularity=\"DATABASE\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\",\"volume\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3315,16 +3207,9 @@ func TestMultiGoroutineTable_insert_dfs_hash_value_chunkGranularity_database(t * } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3333,10 +3218,7 @@ func TestMultiGoroutineTable_insert_dfs_hash_value_chunkGranularity_database(t * for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3345,23 +3227,26 @@ func TestMultiGoroutineTable_insert_dfs_hash_range_chunkGranularity_database(t * ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db1=database(\"\", HASH, [DATEHOUR,3])\n" + - "\tdb2=database(\"\", RANGE, 0 5 11)\n" + + "\tdb2=database(\"\", RANGE, 0 50000 100000)\n" + "\tdb=database(Database, COMPO, [db1, db2], , \"OLAP\", chunkGranularity=\"DATABASE\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\",\"volume\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3369,28 +3254,15 @@ func TestMultiGoroutineTable_insert_dfs_hash_range_chunkGranularity_database(t * } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - reTable2 := re2.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + ans, _ := ddb.RunScript(` + res = select * from loadTable("` + DfsDBPath + `","pt") order by sym,tradeDate; + ex = select * from t1 order by sym,tradeDate; + all(each(eqObj, res.values(), ex.values())) + `) + So(ans.(*model.Scalar).Value(), ShouldBeTrue) + }) } @@ -3399,23 +3271,26 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partirtioncoldatetime ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db1=database(\"\", VALUE, date(1969.12.01)+0..10)\n" + "\tdb2=database(\"\", HASH, [SYMBOL, 2])\n" + "\tdb=database(Database, COMPO, [db1, db2], , \"OLAP\", chunkGranularity=\"DATABASE\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\",\"sym\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3423,16 +3298,9 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partirtioncoldatetime } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3441,10 +3309,7 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partirtioncoldatetime for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3453,23 +3318,26 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partitioncoltimestamp ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db1=database(\"\", VALUE, date(1969.12.01)+0..10)\n" + "\tdb2=database(\"\", HASH, [SYMBOL, 2])\n" + "\tdb=database(Database, COMPO, [db1, db2], , \"OLAP\", chunkGranularity=\"DATABASE\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, TIMESTAMP, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\",\"sym\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3477,16 +3345,9 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partitioncoltimestamp } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3495,10 +3356,7 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partitioncoltimestamp for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3507,7 +3365,8 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partitioncolnanotimes ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -3518,12 +3377,14 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partitioncolnanotimes "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\",\"sym\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3531,16 +3392,9 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partitioncolnanotimes } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3549,10 +3403,7 @@ func TestMultiGoroutineTable_insert_PartitionType_datehour_partitioncolnanotimes for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3561,21 +3412,24 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, datehour(1969.12.01)+0..10)\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3583,16 +3437,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3601,10 +3448,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3613,21 +3457,24 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, datehour(1969.12.01)+0..10)\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, TIMESTAMP, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3635,16 +3482,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3653,10 +3493,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3665,7 +3502,8 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -3674,12 +3512,14 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3687,16 +3527,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3705,10 +3538,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3717,7 +3547,8 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -3726,12 +3557,14 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3739,16 +3572,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3757,10 +3583,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3769,21 +3592,24 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + - "db=database(Database, RANGE, [1969.12.01, 1969.12.05, 1969.12.11])\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "db=database(Database, RANGE, 2012.02.01 2012.02.05 2012.02.11)\n" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3791,16 +3617,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3809,10 +3628,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3821,21 +3637,24 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + - "db=database(Database, RANGE, [1969.12.01, 1969.12.05, 1969.12.11])\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, TIMESTAMP, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "db=database(Database, RANGE, 2012.02.01 2012.02.05 2012.02.11)\n" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3843,16 +3662,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3861,10 +3673,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3873,7 +3682,8 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -3882,12 +3692,14 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3895,16 +3707,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3913,10 +3718,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_date_partiti for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3925,21 +3727,24 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_month_partit ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, month(1..10))\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3947,16 +3752,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_month_partit } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -3965,10 +3763,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_month_partit for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -3977,21 +3772,24 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_month_partit ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + DfsDBPath := "dfs://test_" + generateRandomString(10) + script := "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + "db=database(Database, VALUE, month(1..10))\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, TIMESTAMP, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + + "t= table(rand(`AD`BP`ZQ`FJS`AWP`GPW, 10000) as sym, 2012.02.01T09:30:00.000..(2012.02.01T09:30:00.000+9999) as tradeDate, rand(100.0000, 10000) as tradePrice, rand(10000.00, 10000) as vwap, rand(100000, 10000) as volume, rand(100.000, 10000) as valueTrade);share t as t1;" + "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"tradeDate\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 1, BatchSize: 1000, Throttle: 20, PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -3999,16 +3797,9 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_month_partit } mtt, err := mtw.NewMultiGoroutineTable(opt) So(err, ShouldBeNil) - threadTime := 10 - n := 1000 - waitGroup.Add(threadTime) - for i := 0; i < threadTime; i++ { - go threadinsertData(mtt, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt, "t1") mtt.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade") So(err, ShouldBeNil) @@ -4017,10 +3808,7 @@ func TestMultiGoroutineTable_insert_dfs_PartitionType_partitiontype_month_partit for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -4029,8 +3817,9 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_sameTable ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() + DfsDBPath := "dfs://test_" + generateRandomString(10) script := "\n" + - "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -4039,12 +3828,14 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_sameTable " ;share t as t1;\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"volume\"])\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt := &mtw.Option{ GoroutineCount: 2, - BatchSize: 100000, + BatchSize: 100, Throttle: 100, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -4113,7 +3904,7 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_sameTable } mtt1.WaitForGoroutineCompletion() mtt2.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt) order by volume,valueTrade") So(err, ShouldBeNil) re2, err := ddb.RunScript("select * from t1 order by volume,valueTrade") So(err, ShouldBeNil) @@ -4122,10 +3913,7 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_sameTable for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, reTable2.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } @@ -4134,8 +3922,9 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_different ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() + DfsDBPath := "dfs://test_" + generateRandomString(10) script := "\n" + - "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -4147,12 +3936,14 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_different "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt4, partitionColumns=[\"volume\"]);\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt1 := &mtw.Option{ GoroutineCount: 2, BatchSize: 10, Throttle: 1000, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt1", UserID: setup.UserName, Password: setup.Password, @@ -4165,7 +3956,7 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_different BatchSize: 30, Throttle: 1000, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt2", UserID: setup.UserName, Password: setup.Password, @@ -4178,7 +3969,7 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_different BatchSize: 100, Throttle: 1000, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt3", UserID: setup.UserName, Password: setup.Password, @@ -4191,7 +3982,7 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_different BatchSize: 10, Throttle: 1000, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt4", UserID: setup.UserName, Password: setup.Password, @@ -4240,13 +4031,13 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_different mtt2.WaitForGoroutineCompletion() mtt3.WaitForGoroutineCompletion() mtt4.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt1) order by volume,valueTrade") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt1) order by volume,valueTrade") So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt2) order by volume,valueTrade") + re2, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt2) order by volume,valueTrade") So(err, ShouldBeNil) - re3, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt3) order by volume,valueTrade") + re3, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt3) order by volume,valueTrade") So(err, ShouldBeNil) - re4, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt4) order by volume,valueTrade") + re4, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt4) order by volume,valueTrade") So(err, ShouldBeNil) ex, err := ddb.RunScript("select * from t1 order by volume,valueTrade") So(err, ShouldBeNil) @@ -4261,10 +4052,7 @@ func TestMultiGoroutineTable_insert_dfs_multiple_mutithreadTableWriter_different So(reTable3.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) So(reTable4.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) + }) } func TestMultiGoroutineTable_insert_tsdb_keepDuplicates(t *testing.T) { @@ -4272,8 +4060,9 @@ func TestMultiGoroutineTable_insert_tsdb_keepDuplicates(t *testing.T) { ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() + DfsDBPath := "dfs://test_" + generateRandomString(10) script := "\n" + - "Database = \"dfs://test_MultithreadedTableWriter\"\n" + + "Database = '" + DfsDBPath + "'\n" + "if(exists(Database)){\n" + "\tdropDatabase(Database)\t\n" + "}\n" + @@ -4286,12 +4075,14 @@ func TestMultiGoroutineTable_insert_tsdb_keepDuplicates(t *testing.T) { "createTable(dbHandle=db, table=t, tableName=`pt4, sortColumns=`volume`tradeDate,compressMethods={volume:\"delta\"},keepDuplicates=LAST);\n" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) opt1 := &mtw.Option{ GoroutineCount: 2, BatchSize: 1000, Throttle: 100, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt1", UserID: setup.UserName, Password: setup.Password, @@ -4304,7 +4095,7 @@ func TestMultiGoroutineTable_insert_tsdb_keepDuplicates(t *testing.T) { BatchSize: 30, Throttle: 1000, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt2", UserID: setup.UserName, Password: setup.Password, @@ -4317,7 +4108,7 @@ func TestMultiGoroutineTable_insert_tsdb_keepDuplicates(t *testing.T) { BatchSize: 100, Throttle: 1000, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt3", UserID: setup.UserName, Password: setup.Password, @@ -4330,7 +4121,7 @@ func TestMultiGoroutineTable_insert_tsdb_keepDuplicates(t *testing.T) { BatchSize: 100, Throttle: 1000, PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", + Database: DfsDBPath, TableName: "pt4", UserID: setup.UserName, Password: setup.Password, @@ -4338,27 +4129,22 @@ func TestMultiGoroutineTable_insert_tsdb_keepDuplicates(t *testing.T) { } mtt4, err := mtw.NewMultiGoroutineTable(opt4) So(err, ShouldBeNil) - n := 100 - waitGroup.Add(40) - for i := 0; i < 10; i++ { - go threadinsertData(mtt1, n) - go threadinsertData(mtt2, n) - go threadinsertData(mtt3, n) - go threadinsertData(mtt4, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() + threadinsertData(mtt1, "t1") + threadinsertData(mtt2, "t1") + threadinsertData(mtt3, "t1") + threadinsertData(mtt4, "t1") + mtt1.WaitForGoroutineCompletion() mtt2.WaitForGoroutineCompletion() mtt3.WaitForGoroutineCompletion() mtt4.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt1) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") + re1, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt1) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") So(err, ShouldBeNil) - re2, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt2) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") + re2, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt2) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") So(err, ShouldBeNil) - re3, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt3) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") + re3, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt3) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") So(err, ShouldBeNil) - re4, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt4) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") + re4, err := ddb.RunScript("select * from loadTable('" + DfsDBPath + "',`pt4) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") So(err, ShouldBeNil) ex1, err := ddb.RunScript("select * from t1 where isDuplicated([volume, tradeDate], LAST)=false order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") So(err, ShouldBeNil) @@ -4376,169 +4162,7 @@ func TestMultiGoroutineTable_insert_tsdb_keepDuplicates(t *testing.T) { So(reTable3.GetColumnByIndex(i).String(), ShouldEqual, exTable1.GetColumnByIndex(i).String()) So(reTable4.GetColumnByIndex(i).String(), ShouldEqual, exTable1.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) - }) -} - -func TestMultiGoroutineTable_insert_dfs_length_eq_1024(t *testing.T) { - Convey("func TestMultiGoroutineTable_insert_dfs_length_eq_1024", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) - So(err, ShouldBeNil) - defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + - "if(exists(Database)){\n" + - "\tdropDatabase(Database)\t\n" + - "}\n" + - "db1=database(\"\", RANGE, 1969.12.01+(0..11))\n" + - "\tdb2=database(\"\", HASH,[INT,3])\n" + - "\tdb=database(Database, COMPO, [db2, db1], , \"OLAP\", chunkGranularity=\"DATABASE\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL,DATEHOUR, DOUBLE, DOUBLE, INT, DOUBLE])\nshare t as t1;" + - "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"volume\",\"tradeDate\"])\n" - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - opt1 := &mtw.Option{ - GoroutineCount: 2, - BatchSize: 10, - Throttle: 1000, - PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", - TableName: "pt", - UserID: setup.UserName, - Password: setup.Password, - Address: host12, - } - mtt1, err := mtw.NewMultiGoroutineTable(opt1) - So(err, ShouldBeNil) - n := 1024 - waitGroup.Add(1) - for i := 0; i < 1; i++ { - go threadinsertData(mtt1, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() - mtt1.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - ex, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - exTable := ex.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) - }) -} - -func TestMultiGoroutineTable_insert_dfs_length_eq_1048576(t *testing.T) { - Convey("func TestMultiGoroutineTable_insert_dfs_length_eq_1048576", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) - So(err, ShouldBeNil) - defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + - "if(exists(Database)){\n" + - "\tdropDatabase(Database)\t\n" + - "}\n" + - "db1=database(\"\", RANGE, 1969.12.01+(0..11))\n" + - "\tdb2=database(\"\", HASH,[INT,3])\n" + - "\tdb=database(Database, COMPO, [db2, db1], , \"OLAP\", chunkGranularity=\"DATABASE\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL,DATEHOUR, DOUBLE, DOUBLE, INT, DOUBLE])\nshare t as t1;" + - "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"volume\",\"tradeDate\"])\n" - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - opt1 := &mtw.Option{ - GoroutineCount: 2, - BatchSize: 10, - Throttle: 1000, - PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", - TableName: "pt", - UserID: setup.UserName, - Password: setup.Password, - Address: host12, - } - mtt1, err := mtw.NewMultiGoroutineTable(opt1) - So(err, ShouldBeNil) - n := 1048576 - waitGroup.Add(1) - for i := 0; i < 1; i++ { - go threadinsertData(mtt1, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() - mtt1.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - ex, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - exTable := ex.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) - }) -} -func TestMultiGoroutineTable_insert_dfs_length_eq_3000000(t *testing.T) { - Convey("func TestMultiGoroutineTable_insert_dfs_length_eq_3000000", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) - So(err, ShouldBeNil) - defer ddb.Close() - script := "Database = \"dfs://test_MultithreadedTableWriter\"\n" + - "if(exists(Database)){\n" + - "\tdropDatabase(Database)\t\n" + - "}\n" + - "db1=database(\"\", RANGE, 1969.12.01+(0..11))\n" + - "\tdb2=database(\"\", HASH,[INT,3])\n" + - "\tdb=database(Database, COMPO, [db2, db1], , \"OLAP\", chunkGranularity=\"DATABASE\")\n" + - "t=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL,DATEHOUR, DOUBLE, DOUBLE, INT, DOUBLE])\nshare t as t1;" + - "\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"volume\",\"tradeDate\"])\n" - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - opt1 := &mtw.Option{ - GoroutineCount: 2, - BatchSize: 10000, - Throttle: 100, - PartitionCol: "volume", - Database: "dfs://test_MultithreadedTableWriter", - TableName: "pt", - UserID: setup.UserName, - Password: setup.Password, - Address: host12, - } - mtt1, err := mtw.NewMultiGoroutineTable(opt1) - So(err, ShouldBeNil) - n := 3000000 - waitGroup.Add(1) - for i := 0; i < 1; i++ { - threadinsertData(mtt1, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() - mtt1.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt) order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - ex, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - exTable := ex.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") - So(err, ShouldBeNil) }) } @@ -4553,6 +4177,8 @@ func TestMultiGoroutineTable_insert_streamTable_multipleThread(t *testing.T) { "tt=table(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share tt as " + t2 + ";" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj(t1).SetObjType("SHARED")) + defer ddb.Undef(new(api.UndefRequest).SetObj(t2).SetObjType("SHARED")) opt1 := &mtw.Option{ GoroutineCount: 2, BatchSize: 10, @@ -4566,13 +4192,7 @@ func TestMultiGoroutineTable_insert_streamTable_multipleThread(t *testing.T) { } mtt1, err := mtw.NewMultiGoroutineTable(opt1) So(err, ShouldBeNil) - n := 1000 - waitGroup.Add(10) - for i := 0; i < 10; i++ { - go threadinsertData(mtt1, n) - insertDataTotable(n, t1) - } - waitGroup.Wait() + threadinsertData(mtt1, t1) mtt1.WaitForGoroutineCompletion() re1, err := ddb.RunScript("select * from " + t2 + " order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") So(err, ShouldBeNil) @@ -4599,6 +4219,8 @@ func TestMultiGoroutineTable_insert_streamtable_200cols(t *testing.T) { "addColumn(tt,\"col\"+string(1..200),take([DOUBLE],200));share tt as trades;" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.Undef(new(api.UndefRequest).SetObj("t1").SetObjType("SHARED")) + defer ddb.Undef(new(api.UndefRequest).SetObj("trades").SetObjType("SHARED")) opt1 := &mtw.Option{ GoroutineCount: 2, BatchSize: 10000, @@ -4647,79 +4269,8 @@ func TestMultiGoroutineTable_insert_streamtable_200cols(t *testing.T) { for i := 0; i < len(reTable1.GetColumnNames()); i++ { So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("undef(`trades, SHARED)") - So(err, ShouldBeNil) - }) -} -func TestMultiGoroutineTable_insert_dfstable_200cols(t *testing.T) { - Convey("func TestMultiGoroutineTable_insert_dfstable_200cols", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) - So(err, ShouldBeNil) - defer ddb.Close() - script := "t=table(1:0, `sym`tradeDate, [SYMBOL,TIMESTAMP]);\n" + - "addColumn(t,\"col\"+string(1..200),take([DOUBLE],200));share t as t1;" + - "Database = \"dfs://test_MultithreadedTableWriter\"\n" + - "if(exists(Database)){\n" + - "\tdropDatabase(Database)\t\n" + - "}\n" + - "db=database(Database, VALUE, date(1..2),,'TSDB');\n" + - "createPartitionedTable(dbHandle=db, table=t, tableName=`pt1, partitionColumns=[\"tradeDate\"],sortColumns=`sym,compressMethods={tradeDate:\"delta\"});" - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - opt1 := &mtw.Option{ - GoroutineCount: 2, - BatchSize: 1000, - Throttle: 1000, - PartitionCol: "tradeDate", - Database: "dfs://test_MultithreadedTableWriter", - TableName: "pt1", - UserID: setup.UserName, - Password: setup.Password, - Address: host12, - } - mtt1, err := mtw.NewMultiGoroutineTable(opt1) - So(err, ShouldBeNil) - for ind := 0; ind < 10; ind++ { - row := make([]model.DataForm, 202) - dt, err := model.NewDataType(model.DtString, "AAPL") - AssertNil(err) - row[0] = model.NewScalar(dt) - dt, err = model.NewDataType(model.DtNanoTimestamp, time.Date(2022, time.Month(1), 1+ind%10, 1, 1, 0, 0, time.UTC)) - AssertNil(err) - row[1] = model.NewScalar(dt) - i := float64(ind) - for j := 0; j < 200; j++ { - dt, err = model.NewDataType(model.DtDouble, i+0.1) - AssertNil(err) - row[j+2] = model.NewScalar(dt) - } - _, err = ddb.RunFunc("tableInsert{t1}", row) - So(err, ShouldBeNil) - err = mtt1.Insert("AAPL", time.Date(2022, time.Month(1), 1+ind%10, 1, 1, 0, 0, time.UTC), i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, - i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, - i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, - i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, - i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, - i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, - i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1, i+0.1) - AssertNil(err) - } - mtt1.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from loadTable('dfs://test_MultithreadedTableWriter',`pt1) order by sym,tradeDate;") - So(err, ShouldBeNil) - ex, err := ddb.RunScript("select * from t1 order by sym,tradeDate;") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - exTable := ex.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_MultithreadedTableWriter\")") + _, err = ddb.RunScript("undef(`trades, SHARED)") So(err, ShouldBeNil) }) } @@ -4729,8 +4280,9 @@ func TestMultiGoroutineTable_concurrentWrite_getFailedData_when_unfinished_write ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) So(err, ShouldBeNil) defer ddb.Close() + DfsDBPath := "dfs://test_" + generateRandomString(10) script := "login(`admin,`123456)\n" + - "Database = \"dfs://test_mtw_concurrentWrite_FailedData\"\n" + + "Database = '" + DfsDBPath + "'\n" + "if(existsDatabase(Database)){\n" + "\tdropDB(Database)\n" + "}\n" + @@ -4739,12 +4291,13 @@ func TestMultiGoroutineTable_concurrentWrite_getFailedData_when_unfinished_write "pt = db.createPartitionedTable(t,`pt,`id)" _, err = ddb.RunScript(script) So(err, ShouldBeNil) + defer ddb.DropDatabase(new(api.DropDatabaseRequest).SetDirectory(DfsDBPath)) opt1 := &mtw.Option{ GoroutineCount: 2, BatchSize: 1000, Throttle: 1000, PartitionCol: "id", - Database: "dfs://test_mtw_concurrentWrite_FailedData", + Database: DfsDBPath, TableName: "pt", UserID: setup.UserName, Password: setup.Password, @@ -4769,143 +4322,5 @@ func TestMultiGoroutineTable_concurrentWrite_getFailedData_when_unfinished_write // unwrittenLength += len(v[2].([]int32)) } So(failedData+unwrittenLength+int(reTable.Value().(int32)), ShouldEqual, 10000) - _, err = ddb.RunScript("dropDatabase(\"dfs://test_mtw_concurrentWrite_FailedData\")") - So(err, ShouldBeNil) - }) -} - -func TestMultiGoroutineTable_insert_streamTable_eq_1024(t *testing.T) { - Convey("func TestMultiGoroutineTable_insert_streamTable_eq_1024", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) - So(err, ShouldBeNil) - defer ddb.Close() - script := "t=streamTable(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + - "tt=streamTable(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share tt as t2;" - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - opt1 := &mtw.Option{ - GoroutineCount: 2, - BatchSize: 100000, - Throttle: 1000, - PartitionCol: "volume", - Database: "", - TableName: "t2", - UserID: setup.UserName, - Password: setup.Password, - Address: host12, - } - mtt1, err := mtw.NewMultiGoroutineTable(opt1) - So(err, ShouldBeNil) - n := 1024 - waitGroup.Add(1) - for i := 0; i < 1; i++ { - go threadinsertData(mtt1, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() - mtt1.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from t2 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - ex, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - exTable := ex.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - }) -} - -func TestMultiGoroutineTable_insert_streamTable_eq_1048576(t *testing.T) { - Convey("func TestMultiGoroutineTable_insert_streamTable_eq_1048576", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) - So(err, ShouldBeNil) - defer ddb.Close() - script := "t=streamTable(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + - "tt=streamTable(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share tt as t2;" - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - opt1 := &mtw.Option{ - GoroutineCount: 2, - BatchSize: 100000, - Throttle: 1000, - PartitionCol: "volume", - Database: "", - TableName: "t2", - UserID: setup.UserName, - Password: setup.Password, - Address: host12, - } - mtt1, err := mtw.NewMultiGoroutineTable(opt1) - So(err, ShouldBeNil) - n := 1048576 - waitGroup.Add(1) - for i := 0; i < 1; i++ { - go threadinsertData(mtt1, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() - mtt1.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from t2 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - ex, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - exTable := ex.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("undef(`t2, SHARED)") - So(err, ShouldBeNil) - }) -} - -func TestMultiGoroutineTable_insert_streamTable_eq_3000000(t *testing.T) { - Convey("func TestMultiGoroutineTable_insert_streamTable_eq_3000000", t, func() { - ddb, err := api.NewSimpleDolphinDBClient(context.TODO(), host12, setup.UserName, setup.Password) - So(err, ShouldBeNil) - defer ddb.Close() - script := "t=streamTable(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share t as t1;" + - "tt=streamTable(1:0, `sym`tradeDate`tradePrice`vwap`volume`valueTrade, [SYMBOL, DATETIME, DOUBLE, DOUBLE, INT, DOUBLE])\n;share tt as t2;" - _, err = ddb.RunScript(script) - So(err, ShouldBeNil) - opt1 := &mtw.Option{ - GoroutineCount: 2, - BatchSize: 100000, - Throttle: 1000, - PartitionCol: "volume", - Database: "", - TableName: "t2", - UserID: setup.UserName, - Password: setup.Password, - Address: host12, - } - mtt1, err := mtw.NewMultiGoroutineTable(opt1) - So(err, ShouldBeNil) - n := 3000000 - waitGroup.Add(1) - for i := 0; i < 1; i++ { - go threadinsertData(mtt1, n) - insertDataTotable(n, "t1") - } - waitGroup.Wait() - mtt1.WaitForGoroutineCompletion() - re1, err := ddb.RunScript("select * from t2 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - ex, err := ddb.RunScript("select * from t1 order by sym,tradeDate,tradePrice,vwap,volume,valueTrade;") - So(err, ShouldBeNil) - reTable1 := re1.(*model.Table) - exTable := ex.(*model.Table) - for i := 0; i < len(reTable1.GetColumnNames()); i++ { - So(reTable1.GetColumnByIndex(i).String(), ShouldEqual, exTable.GetColumnByIndex(i).String()) - } - _, err = ddb.RunScript("undef(`t1, SHARED)") - So(err, ShouldBeNil) - _, err = ddb.RunScript("undef(`t2, SHARED)") - So(err, ShouldBeNil) }) } diff --git a/test/newTableFromRawData_test.go b/test/newTableFromRawData_test.go index 8eb5428..f3dae87 100644 --- a/test/newTableFromRawData_test.go +++ b/test/newTableFromRawData_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/newTableFromStruct_test.go b/test/newTableFromStruct_test.go index 58f2ef3..1cbb908 100644 --- a/test/newTableFromStruct_test.go +++ b/test/newTableFromStruct_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/ploadText_test.go b/test/ploadText_test.go index a17d44b..206a8ba 100644 --- a/test/ploadText_test.go +++ b/test/ploadText_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/run_function_test.go b/test/run_function_test.go index 3723546..42f87c1 100644 --- a/test/run_function_test.go +++ b/test/run_function_test.go @@ -8,9 +8,9 @@ import ( "os" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/saveTable_test.go b/test/saveTable_test.go index a8cc363..10645c9 100644 --- a/test/saveTable_test.go +++ b/test/saveTable_test.go @@ -4,9 +4,9 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/saveText_test.go b/test/saveText_test.go index 032ba02..80fdbb0 100644 --- a/test/saveText_test.go +++ b/test/saveText_test.go @@ -4,9 +4,9 @@ import ( "context" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/sql_test.go b/test/sql_test.go index 2c268d4..823d3a1 100644 --- a/test/sql_test.go +++ b/test/sql_test.go @@ -5,9 +5,9 @@ import ( "strconv" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) diff --git a/test/streaming/goroutineClient_reverse_test.go b/test/streaming/goroutineClient_reverse_test.go index 489b870..ca1c973 100644 --- a/test/streaming/goroutineClient_reverse_test.go +++ b/test/streaming/goroutineClient_reverse_test.go @@ -8,10 +8,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/streaming" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/streaming" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) @@ -205,7 +205,7 @@ func TestGoroutineClient_tableName_handler_offset_reconnect_success_r(t *testing _, err = gcConn_r.RunScript("stopPublishTable('" + setup.IP + "'," + strings.Split(host, ":")[1] + ",'" + st + "')") So(err, ShouldBeNil) - time.Sleep(10 * time.Second) + time.Sleep(12 * time.Second) res, _ := gcConn_r.RunScript("res = select * from " + receive + " order by tag;ex = select * from " + st + " order by tag;each(eqObj, ex.values(), res.values())") for _, val := range res.(*model.Vector).Data.Value() { So(val, ShouldBeTrue) diff --git a/test/streaming/goroutineClient_test.go b/test/streaming/goroutineClient_test.go index ba74dc0..cf6285b 100644 --- a/test/streaming/goroutineClient_test.go +++ b/test/streaming/goroutineClient_test.go @@ -8,10 +8,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/streaming" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/streaming" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) diff --git a/test/streaming/goroutinePooledClient_reverse_test.go b/test/streaming/goroutinePooledClient_reverse_test.go index f7c8df2..ff485d6 100644 --- a/test/streaming/goroutinePooledClient_reverse_test.go +++ b/test/streaming/goroutinePooledClient_reverse_test.go @@ -7,10 +7,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/streaming" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/streaming" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) @@ -410,7 +410,7 @@ func TestNewGoroutinePooledClient_tableName_handler_offset_reconnect_success_r(t time.Sleep(2 * time.Second) _, err = gpcConn_r.RunScript("stopPublishTable('" + setup.IP + "'," + strings.Split(host2, ":")[1] + ",'" + st + "')") So(err, ShouldBeNil) - + time.Sleep(2 * time.Second) _, err = gpcConn_r.RunScript("n=500;t=table(1..n+500 as tag,now()+1..n+500 as ts,rand(100.0,n) as data);" + "" + st + ".append!(t)") So(err, ShouldBeNil) time.Sleep(2 * time.Second) diff --git a/test/streaming/goroutinePooledClient_test.go b/test/streaming/goroutinePooledClient_test.go index 7c6fd30..9becbea 100644 --- a/test/streaming/goroutinePooledClient_test.go +++ b/test/streaming/goroutinePooledClient_test.go @@ -7,10 +7,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/streaming" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/streaming" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) diff --git a/test/streaming/pollingClient_reverse_test.go b/test/streaming/pollingClient_reverse_test.go index 36f9f06..7ff9e32 100644 --- a/test/streaming/pollingClient_reverse_test.go +++ b/test/streaming/pollingClient_reverse_test.go @@ -8,10 +8,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/streaming" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/streaming" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) @@ -1342,9 +1342,9 @@ func TestNewPollingClient_subscribe_with_StreamDeserializer_arrayVector_r(t *tes {model.DtIP, "take(ipaddr('192.168.1.1'), 2)"}, {model.DtIP, "array(IPADDR, 2,2,NULL)"}, {model.DtUUID, "take(uuid('12345678-1234-1234-1234-123456789012'), 2)"}, {model.DtUUID, "array(UUID, 2,2,NULL)"}, {model.DtInt128, "take(int128(`e1671797c52e15f763380b45e841ec32), 2)"}, {model.DtInt128, "array(INT128, 2,2,NULL)"}, - {model.DtDecimal32, "decimal32(rand('-1.123''''2.23468965412', 2), 8)"}, {model.DtDecimal32, "array(DECIMAL32(2), 2,2,NULL)"}, - {model.DtDecimal64, "decimal64(rand('-1.123''''2.123123123123123123', 2), 15)"}, {model.DtDecimal64, "array(DECIMAL64(15), 2,2,NULL)"}, - {model.DtDecimal128, "decimal128(rand('-1.123''''2.123123123123123123123123123', 2), 25)"}, {model.DtDecimal128, "array(DECIMAL128(25), 2,2,NULL)"}, + //{model.DtDecimal32, "decimal32(rand('-1.123''''2.23468965412', 2), 8)"}, {model.DtDecimal32, "array(DECIMAL32(2), 2,2,NULL)"}, + //{model.DtDecimal64, "decimal64(rand('-1.123''''2.123123123123123123', 2), 15)"}, {model.DtDecimal64, "array(DECIMAL64(15), 2,2,NULL)"}, + //{model.DtDecimal128, "decimal128(rand('-1.123''''2.123123123123123123123123123', 2), 25)"}, {model.DtDecimal128, "array(DECIMAL128(25), 2,2,NULL)"}, {model.DtComplex, "take(complex(1,2), 2)"}, {model.DtComplex, "array(COMPLEX, 2,2,NULL)"}, {model.DtPoint, "take(point(1, 2), 2)"}, {model.DtPoint, "array(POINT, 2,2,NULL)"}, } diff --git a/test/streaming/pollingClient_test.go b/test/streaming/pollingClient_test.go index d83989e..adcfa6b 100644 --- a/test/streaming/pollingClient_test.go +++ b/test/streaming/pollingClient_test.go @@ -8,10 +8,10 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/streaming" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/streaming" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) diff --git a/test/streaming/util.go b/test/streaming/util.go index 83bcc77..ab8be96 100644 --- a/test/streaming/util.go +++ b/test/streaming/util.go @@ -11,10 +11,10 @@ import ( "sync" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/streaming" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/streaming" + "github.com/dolphindb/api-go/v3/test/setup" ) var ( diff --git a/test/table_test.go b/test/table_test.go index 52a9371..e944d78 100644 --- a/test/table_test.go +++ b/test/table_test.go @@ -7,9 +7,9 @@ import ( "testing" "time" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert" ) diff --git a/test/undef_test.go b/test/undef_test.go index a001e60..76af91f 100644 --- a/test/undef_test.go +++ b/test/undef_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" . "github.com/smartystreets/goconvey/convey" ) diff --git a/test/util.go b/test/util.go index 6b299fb..37e5949 100644 --- a/test/util.go +++ b/test/util.go @@ -7,9 +7,9 @@ import ( "math/big" "reflect" - "github.com/dolphindb/api-go/api" - "github.com/dolphindb/api-go/model" - "github.com/dolphindb/api-go/test/setup" + "github.com/dolphindb/api-go/v3/api" + "github.com/dolphindb/api-go/v3/model" + "github.com/dolphindb/api-go/v3/test/setup" ) var (