提交 fcb471f7 编写于 作者: martianzhang's avatar martianzhang

Merge branch 'go-sql-driver' of github.com:XiaoMi/soar into go-sql-driver

......@@ -17,12 +17,10 @@
package database
import (
"database/sql"
"fmt"
"time"
"strings"
"database/sql"
"time"
"github.com/XiaoMi/soar/common"
"github.com/ziutek/mymysql/mysql"
......@@ -92,7 +90,6 @@ func (db *Connector) SamplingData(onlineConn *Connector, database string, tables
} else {
where = common.Config.SamplingCondition
}
err = db.startSampling(onlineConn.Conn, database, table, where)
}
return err
......@@ -143,17 +140,17 @@ func (db *Connector) startSampling(onlineConn *sql.DB, database, table string, w
values = append(values, fmt.Sprintf(`unhex("%s")`, fmt.Sprintf("%x", val)))
}
}
}
valuesStr = append(valuesStr, "("+strings.Join(values, `,`)+")")
valuesCount++
if maxValuesCount <= valuesCount {
err = db.doSampling(table, columnsStr, strings.Join(valuesStr, `,`))
if err != nil {
break
valuesStr = append(valuesStr, "("+strings.Join(values, `,`)+")")
valuesCount++
if maxValuesCount <= valuesCount {
err = db.doSampling(table, columnsStr, strings.Join(valuesStr, `,`))
if err != nil {
break
}
values = make([]string, 0)
valuesStr = make([]string, 0)
valuesCount = 0
}
values = make([]string, 0)
valuesStr = make([]string, 0)
valuesCount = 0
}
}
res.Close()
......
......@@ -282,3 +282,60 @@ func TestCreateDatabase(t *testing.T) {
}
common.Log.Debug("Exiting function: %s", common.GetFunctionName())
}
func TestCreateTable(t *testing.T) {
orgSamplingCondition := common.Config.SamplingCondition
common.Config.SamplingCondition = "LIMIT 1"
vEnv, rEnv := BuildEnv()
defer vEnv.CleanUp()
// TODO: support VIEW,
tables := []string{
"actor",
// "actor_info", // VIEW
"address",
"category",
"city",
"country",
"customer",
"customer_list",
"film",
"film_actor",
"film_category",
"film_list",
"film_text",
"inventory",
"language",
"nicer_but_slower_film_list",
"payment",
"rental",
// "sales_by_film_category", // VIEW
// "sales_by_store", // VIEW
"staff",
"staff_list",
"store",
}
for _, table := range tables {
err := vEnv.createTable(rEnv, "sakila", table)
if err != nil {
t.Error(err)
}
}
common.Config.SamplingCondition = orgSamplingCondition
}
func TestCreateDatabase(t *testing.T) {
vEnv, rEnv := BuildEnv()
defer vEnv.CleanUp()
err := vEnv.createDatabase(rEnv, "sakila")
if err != nil {
t.Error(err)
}
if vEnv.DBHash("sakila") == "sakila" {
t.Errorf("database: sakila rehashed failed!")
}
if vEnv.DBHash("not_exist_db") != "not_exist_db" {
t.Errorf("database: not_exist_db rehashed!")
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册