Skip to content

Commit

Permalink
Change param conflict finder sql to use null-safe equality
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Apr 10, 2024
1 parent fece2ed commit 0862dcf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/api/mlflow/dao/repositories/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/rotisserie/eris"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/clause"

Expand Down Expand Up @@ -88,15 +89,20 @@ func (r ParamRepository) CreateBatch(ctx context.Context, batchSize int, params
func findConflictingParams(tx *gorm.DB, params []models.Param) ([]paramConflict, error) {
var conflicts []paramConflict
placeholders, values := makeParamConflictPlaceholdersAndValues(params, tx.Dialector.Name())
nullSafeEquality := "<=>"
if (tx.Dialector.Name() == postgres.Dialector{}.Name()) {
nullSafeEquality = "IS NOT DISTINCT FROM"
}
sql := fmt.Sprintf(`WITH new(key, run_uuid, value_int, value_float, value_str) AS (%s)
SELECT current.run_uuid, current.key, CONCAT(current.value_int,
current.value_float, current.value_str) as old_value, CONCAT(new.value_int,
new.value_float, new.value_str) as new_value
FROM params AS current
INNER JOIN new USING (run_uuid, key)
WHERE (COALESCE(new.value_int, current.value_int) IS NULL OR new.value_int != current.value_int)
AND (COALESCE(new.value_float, current.value_float) IS NULL OR new.value_float != current.value_float)
AND (COALESCE(new.value_str, current.value_str) IS NULL OR new.value_str != current.value_str)`, placeholders)
WHERE NOT (new.value_int %s current.value_int)
AND NOT (new.value_float %s current.value_float)
AND NOT (new.value_str %s current.value_str)`,
placeholders, nullSafeEquality, nullSafeEquality, nullSafeEquality)
if err := tx.Raw(sql, values...).
Find(&conflicts).Error; err != nil {
return nil, eris.Wrap(err, "error fetching params from db")
Expand Down

0 comments on commit 0862dcf

Please sign in to comment.