Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/db/v1beta1/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (d *dbConn) RegisterObservationLog(trialName string, observationLog *v1beta
sqlQuery += "(?, ?, ?, ?),"
values = append(values, trialName, sqlTimeStr, mlog.Metric.Name, mlog.Metric.Value)
}
if len(values) == 0 {
// No valid metric logs to insert, skip Prepare/Exec.
return nil
}
sqlQuery = sqlQuery[0 : len(sqlQuery)-1]

// Prepare the statement
Expand Down
30 changes: 30 additions & 0 deletions pkg/db/v1beta1/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@ func TestRegisterObservationLog(t *testing.T) {

}

func TestRegisterObservationLogNoValidEntries(t *testing.T) {
obsLog := &api_pb.ObservationLog{
MetricLogs: []*api_pb.MetricLog{
{
TimeStamp: "",
Metric: &api_pb.Metric{
Name: "f1_score",
Value: "88.95",
},
},
},
}

err := dbInterface.RegisterObservationLog("test1_trial1", obsLog)
if err != nil {
t.Errorf("RegisterObservationLog failed: %v", err)
}
}

func TestRegisterObservationLogEmptyMetricLogs(t *testing.T) {
obsLog := &api_pb.ObservationLog{
MetricLogs: []*api_pb.MetricLog{},
}

err := dbInterface.RegisterObservationLog("test1_trial1", obsLog)
if err != nil {
t.Errorf("RegisterObservationLog failed: %v", err)
}
}

func TestGetObservationLog(t *testing.T) {
mock.ExpectQuery("SELECT").WillReturnRows(
sqlmock.NewRows([]string{"time", "metric_name", "value"}).AddRow(
Expand Down
5 changes: 5 additions & 0 deletions pkg/db/v1beta1/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func (d *dbConn) RegisterObservationLog(trialName string, observationLog *v1beta
index_of_qparam += 4
}

if len(values) == 0 {
// No valid metric logs to insert, skip Prepare/Exec.
return nil
}

statement = statement[:len(statement)-1]

// Prepare the statement
Expand Down
30 changes: 30 additions & 0 deletions pkg/db/v1beta1/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ func TestRegisterObservationLog(t *testing.T) {

}

func TestRegisterObservationLogNoValidEntries(t *testing.T) {
obsLog := &api_pb.ObservationLog{
MetricLogs: []*api_pb.MetricLog{
{
TimeStamp: "",
Metric: &api_pb.Metric{
Name: "f1_score",
Value: "88.95",
},
},
},
}

err := dbInterface.RegisterObservationLog("test1_trial1", obsLog)
if err != nil {
t.Errorf("RegisterObservationLog failed: %v", err)
}
}

func TestRegisterObservationLogEmptyMetricLogs(t *testing.T) {
obsLog := &api_pb.ObservationLog{
MetricLogs: []*api_pb.MetricLog{},
}

err := dbInterface.RegisterObservationLog("test1_trial1", obsLog)
if err != nil {
t.Errorf("RegisterObservationLog failed: %v", err)
}
}

func TestGetObservationLog(t *testing.T) {
mock.ExpectQuery("SELECT").WillReturnRows(
sqlmock.NewRows([]string{"time", "metric_name", "value"}).AddRow(
Expand Down