Skip to content

Commit

Permalink
katib manager db error (#476)
Browse files Browse the repository at this point in the history
* katib manager db error

condition is keyword of mysql, we need escape it in sql

* fix test case error

* use status to replace condition as column name
  • Loading branch information
hougangliu authored and k8s-ci-robot committed Apr 29, 2019
1 parent 2b55c69 commit c93eb1f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions pkg/db/v1alpha2/db_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (d *dbConn) DBInit() {
trial_template TEXT,
parallel_trial_count INT,
max_trial_count INT,
condition TINYINT,
status TINYINT,
metrics_collector_type TEXT,
start_time DATETIME(6),
completion_time DATETIME(6),
Expand All @@ -30,11 +30,11 @@ func (d *dbConn) DBInit() {
_, err = db.Exec(`CREATE TABLE IF NOT EXISTS trials
(id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
experiment_name TEXT NOT NULL,
experiment_name VARCHAR(255) NOT NULL,
parameter_assignments TEXT,
run_spec TEXT,
observation TEXT,
condition TINYINT,
status TINYINT,
start_time DATETIME(6),
completion_time DATETIME(6),
FOREIGN KEY(experiment_name) REFERENCES experiments(name) ON DELETE CASCADE)`)
Expand Down
16 changes: 8 additions & 8 deletions pkg/db/v1alpha2/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (d *dbConn) RegisterExperiment(experiment *v1alpha2.Experiment) error {
algorithm,
trial_template,
parallel_trial_count,
max_trial_count,
condition,
max_trial_count,
status,
metrics_collector_type,
start_time,
completion_time,
Expand Down Expand Up @@ -284,7 +284,7 @@ func (d *dbConn) GetExperiment(experimentName string) (*v1alpha2.Experiment, err
}

func (d *dbConn) GetExperimentList() ([]*v1alpha2.ExperimentSummary, error) {
rows, err := d.db.Query("SELECT name, condition, start_time, completion_time FROM experiments")
rows, err := d.db.Query(`SELECT name, status, start_time, completion_time FROM experiments`)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -346,8 +346,8 @@ func (d *dbConn) UpdateExperimentStatus(experimentName string, newStatus *v1alph
}
completion_time = c_time.UTC().Format(mysqlTimeFmt)
}
_, err = d.db.Exec(`UPDATE experiments SET condition = ? ,
start_time = ?,
_, err = d.db.Exec(`UPDATE experiments SET status = ?,
start_time = ?,
completion_time = ? WHERE name = ?`,
newStatus.Condition,
start_time,
Expand Down Expand Up @@ -460,7 +460,7 @@ func (d *dbConn) RegisterTrial(trial *v1alpha2.Trial) error {
parameter_assignments,
run_spec,
observation,
condition,
status,
start_time,
completion_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
trial.Name,
Expand Down Expand Up @@ -630,8 +630,8 @@ func (d *dbConn) UpdateTrialStatus(trialName string, newStatus *v1alpha2.TrialSt
}
formattedCompletionTime = completion_time.UTC().Format(mysqlTimeFmt)
}
_, err = d.db.Exec(`UPDATE trials SET condition = ? ,
start_time = ?,
_, err = d.db.Exec(`UPDATE trials SET status = ?,
start_time = ?,
completion_time = ?,
observation = ? WHERE name = ?`,
newStatus.Condition,
Expand Down
18 changes: 9 additions & 9 deletions pkg/db/v1alpha2/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var experimentColums = []string{
"trial_template",
"parallel_trial_count",
"max_trial_count",
"condition",
"status",
"metrics_collector_type",
"start_time",
"completion_time",
Expand All @@ -41,7 +41,7 @@ var trialColumns = []string{
"parameter_assignments",
"run_spec",
"observation",
"condition",
"status",
"start_time",
"completion_time",
}
Expand Down Expand Up @@ -116,8 +116,8 @@ func TestRegisterExperiment(t *testing.T) {
algorithm,
trial_template,
parallel_trial_count,
max_trial_count,
condition,
max_trial_count,
status,
metrics_collector_type,
start_time,
completion_time,
Expand Down Expand Up @@ -169,8 +169,8 @@ func TestGetExperiment(t *testing.T) {
}

func TestGetExperimentList(t *testing.T) {
mock.ExpectQuery("SELECT name, condition, start_time, completion_time FROM experiments").WillReturnRows(
sqlmock.NewRows([]string{"name", "condition", "start_time", "completion_time"}).AddRow(
mock.ExpectQuery("SELECT name, status, start_time, completion_time FROM experiments").WillReturnRows(
sqlmock.NewRows([]string{"name", "status", "start_time", "completion_time"}).AddRow(
"test1",
api_pb.ExperimentStatus_CREATED,
"2016-12-31 20:02:05.123456",
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestUpdateExperimentStatus(t *testing.T) {
start_time := "2016-12-31 20:02:05.123456"
completion_time := ""

mock.ExpectExec(`UPDATE experiments SET condition = \? ,
mock.ExpectExec(`UPDATE experiments SET status = \?,
start_time = \?,
completion_time = \? WHERE name = \?`,
).WithArgs(condition, start_time, completion_time, exp_name).WillReturnResult(sqlmock.NewResult(1, 1))
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestRegisterTrial(t *testing.T) {
parameter_assignments,
run_spec,
observation,
condition,
status,
start_time,
completion_time\)`,
).WithArgs(
Expand Down Expand Up @@ -386,7 +386,7 @@ func TestUpdateTrialStatus(t *testing.T) {
start_time := "2016-12-31 20:02:05.123456"
completion_time := ""

mock.ExpectExec(`UPDATE trials SET condition = \? ,
mock.ExpectExec(`UPDATE trials SET status = \?,
start_time = \?,
completion_time = \?,
observation = \? WHERE name = \?`,
Expand Down

0 comments on commit c93eb1f

Please sign in to comment.