Skip to content

Commit

Permalink
feat: quaisi identifier check value type is float 64
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao-Ma5566 committed Apr 23, 2024
1 parent a949286 commit e7f8a6c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions internal/infra/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package infra

import (
"errors"
"fmt"
"io"
"strconv"

"github.com/cgi-fr/jsonline/pkg/jsonline"
"github.com/cgi-fr/sigo/pkg/sigo"
Expand All @@ -35,14 +37,36 @@ type JSONLineRecord struct {
sensitives *[]string
}

func (jlr JSONLineRecord) QuasiIdentifer() []float64 {
func (jlr JSONLineRecord) QuasiIdentifer() ([]float64, error) {
result := []float64{}

for _, key := range *jlr.quasiIdentifers {
result = append(result, (*jlr.row).GetFloat64(key))
value, _ := (*jlr.row).Get(key)
if value == nil {
//nolint: goerr113
err := errors.New("null value in dataset")
return []float64{}, err
}

switch v := value.(type) {
case float64:
result = append(result, v)
case int:
result = append(result, float64(v))
case string:
floatValue, err := strconv.ParseFloat(v, 64)
if err != nil {
return []float64{}, err
}
result = append(result, floatValue)
default:
err := fmt.Errorf("unsupported type: %T", v)
return []float64{}, err
}

}

return result
return result, nil
}

func (jlr JSONLineRecord) Sensitives() []interface{} {
Expand Down

0 comments on commit e7f8a6c

Please sign in to comment.