Skip to content

Commit

Permalink
bugfix: parse int value empty
Browse files Browse the repository at this point in the history
  • Loading branch information
vinllen committed May 18, 2021
1 parent 8276953 commit 7050241
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ runtime.trace
.DS_Store

data
nimo-shake-v*

.cache/
diagnostic/
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2021-05-18
* VERSION: 1.0.12
* BUGFIX: parse int value empty.

2021-04-07
* VERSION: 1.0.11
* IMPROVE: data source support endpoint_url.
Expand Down
15 changes: 14 additions & 1 deletion src/nimo-shake/protocal/type_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/vinllen/mgo/bson"
"github.com/vinllen/mongo-go-driver/bson/primitive"
LOG "github.com/vinllen/log4go"
"strconv"
)
Expand Down Expand Up @@ -181,7 +182,8 @@ func (tc *TypeConverter) convertToDetail(name string, input interface{}) interfa
return input.(bool)
case "N":
v := input.(string)
val, err := bson.ParseDecimal128(v)
// for new driver, we need to parse the value to mongo-go-driver.bson.decimal128, not mgo.bson.decimal128
/* val, err := bson.ParseDecimal128(v)
if err != nil {
LOG.Error("convert N to decimal128 failed[%v]", err)
val2, err := strconv.ParseFloat(v, 64)
Expand All @@ -191,6 +193,17 @@ func (tc *TypeConverter) convertToDetail(name string, input interface{}) interfa
val, _ = bson.ParseDecimal128(fmt.Sprintf("%v", val2))
return val
}*/
val, err := primitive.ParseDecimal128(v)
if err != nil {
LOG.Error("convert N to decimal128 failed[%v]", err)
val2, err := strconv.ParseFloat(v, 64)
if err != nil {
LOG.Crashf("convert N to decimal128 and float64 both failed[%v]", err)
}

val, _ = primitive.ParseDecimal128(fmt.Sprintf("%v", val2))
return val
}
return val
case "S":
Expand Down
1 change: 1 addition & 0 deletions src/nimo-shake/writer/mongodb_community_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (mcw *MongoCommunityWriter) WriteBulk(input []interface{}) error {
models := make([]mongo.WriteModel, len(input))
for i := range models {
models[i] = &mongo.InsertOneModel{Document: input[i]}
LOG.Debug("WriteBulk: %v", input[i])
}

_, err := mcw.conn.Client.Database(mcw.ns.Database).Collection(mcw.ns.Collection).BulkWrite(nil, models)
Expand Down

0 comments on commit 7050241

Please sign in to comment.