Skip to content

Commit

Permalink
updated dsunit udf
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Sep 20, 2024
1 parent 8c3dc19 commit 2c8ec55
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.77.1
0.77.2
6 changes: 3 additions & 3 deletions endly/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ pipeline:
- export GOARCH=amd64
- go build -ldflags="-X 'main.Version=${Ver}'"
- tar cvzf endly_linux_${Ver}_amd64.tar.gz endly
- export GOOS=windows
- go build -ldflags="-X 'main.Version=${Ver}'"
- tar cvzf endly_windows_${Ver}_amd64.tar.gz endly
- export GOOS=darwin
- go build -ldflags="-X 'main.Version=${Ver}'"
- tar cvzf endly_darwin_${Ver}_amd64.tar.gz endly
- export GOOS=darwin
- export GOARCH=arm64
- go build -ldflags="-X 'main.Version=${Ver}'"
- tar cvzf endly_darwin_${Ver}_arm64.tar.gz endly
- export GOOS=windows
- go build -ldflags="-X 'main.Version=${Ver}'"
- tar cvzf endly_windows_${Ver}_amd64.tar.gz endly
1 change: 0 additions & 1 deletion endly/endly.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import (
)

func main() {

bootstrap.Bootstrap()
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ require (
github.com/viant/bgc v0.9.0
github.com/viant/dsc v0.19.0
github.com/viant/dsunit v0.11.1-0.20240315154953-016b93c322c2
github.com/viant/scy v0.12.0
github.com/viant/toolbox v0.37.1-0.20240920190350-4edcb037fba9
github.com/viant/scy v0.12.1
github.com/viant/toolbox v0.37.1-0.20240920204202-12309d1bb97c
github.com/yuin/gopher-lua v1.1.1 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0
Expand Down Expand Up @@ -203,6 +203,7 @@ require (
google.golang.org/grpc v1.63.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gotest.tools/v3 v3.5.1 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,8 @@ github.com/viant/parsly v0.3.3-0.20240717150634-e1afaedb691b h1:3q166tV28yFdbFV+
github.com/viant/parsly v0.3.3-0.20240717150634-e1afaedb691b/go.mod h1:85fneXJbErKMGhSQto3A5ElTQCwl3t74U9cSV0waBHw=
github.com/viant/pgo v0.11.0 h1:PNuYVhwTfyrAHGBO6lxaMFuHP4NkjKV8ULecz3OWk8c=
github.com/viant/pgo v0.11.0/go.mod h1:MFzHmkRFZlciugEgUvpl/3grK789PBSH4dUVSLOSo+Q=
github.com/viant/scy v0.12.0 h1:Fo0DHviM1LHjj2XmtgIERmeh+z4X66AUXnUCTswFXT4=
github.com/viant/scy v0.12.0/go.mod h1:Lz1VPlmjVi4ydZ5ikP/d5uQS/xYs22HG23++PgLRlKQ=
github.com/viant/scy v0.12.1 h1:kFtFXexMZrr41laAplKiKwuZo7KRikKgbXVvsXeYsTI=
github.com/viant/scy v0.12.1/go.mod h1:yHDc9YmfDqhxiMPZcCRS+rb9KUjMNZniWZ9LMQoM0KI=
github.com/viant/sqlparser v0.7.4 h1:/jXiB2zC9cDXTwR0TgF2evrHC5oQPCAkkf0KZfe9Vks=
github.com/viant/sqlparser v0.7.4/go.mod h1:2QRGiGZYk2/pjhORGG1zLVQ9JO+bXFhqIVi31mkCRPg=
github.com/viant/sqlx v0.15.2-0.20240802175425-e8a939a4cf7b h1:tNkwnYy1K5ZYuElmaTP+L/SbJeq7qHbcVM5dglVPlt4=
Expand All @@ -1346,6 +1346,8 @@ github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMI
github.com/viant/toolbox v0.34.5/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/viant/toolbox v0.37.1-0.20240920190350-4edcb037fba9 h1:ZNZOh2Regsr8YO5ypilU47U7DIkoUKgIx6xofChgjRQ=
github.com/viant/toolbox v0.37.1-0.20240920190350-4edcb037fba9/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/viant/toolbox v0.37.1-0.20240920204202-12309d1bb97c h1:/+EGnMFfdo2cHaFfK0rVf+RYxryMT3RAotLB37HinHs=
github.com/viant/toolbox v0.37.1-0.20240920204202-12309d1bb97c/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/viant/velty v0.2.1-0.20230927172116-ba56497b5c85 h1:zKk+6hqUipkJXCPCHyFXzGtil1sfh80r6UZmloBNEDo=
github.com/viant/velty v0.2.1-0.20230927172116-ba56497b5c85/go.mod h1:Q/UXviI2Nli8WROEpYd/BELMCSvnulQeyNrbPmMiS/Y=
github.com/viant/x v0.3.0 h1:/3A0z/uySGxMo6ixH90VAcdjI00w5e3REC1zg5hzhJA=
Expand Down
72 changes: 60 additions & 12 deletions service/testing/dsunit/udf.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ func convertMultiTables(tables map[string]interface{}, state data.Map, prefix st
for i, item := range tableDataSlice {
itemMap := item.(map[string]interface{})

caseTag := ""
caseTagValue, hasTag := itemMap["!tag"]
if hasTag {
caseTag = toolbox.AsString(caseTagValue)
delete(itemMap, "!tag")
}

sequencerValues := sequencerMapping.GetMap(sequencer)
for k, v := range itemMap {
if v == nil {
Expand All @@ -144,21 +151,30 @@ func convertMultiTables(tables map[string]interface{}, state data.Map, prefix st
if _, ok := v.([]string); ok {
continue
}
value := toolbox.AsString(v)
if strings.Contains(value, "$Data") || strings.Contains(value, "$uuid") {
itemMap[k] = sequencerMapping.Expand(strings.Replace(value, "/", ".", 1))
}

if strings.Contains(value, "$") {
expr, key := getSequencerExpr(value, sequencer)
seqValue, ok := sequencerValues[key]
if !ok {
seqValue, ok = sequencerValues.GetValue(key)
switch value := v.(type) {
case string:
if strings.Contains(value, "$Data") || strings.Contains(value, "$uuid") {
itemMap[k] = sequencerMapping.Expand(strings.Replace(value, "/", ".", 1))
} else {
expanded, ok := expandSequenceExpr(value, toolbox.AsString(caseTag), sequencerMapping, sequencer, sequencerValues, state)
if ok {
itemMap[k] = expanded
}
}
if ok {
itemMap[k] = strings.ReplaceAll(value, expr, toolbox.AsString(seqValue))
case map[interface{}]interface{}:
for key, keyValue := range value {
stringKey, ok := key.(string)
if !ok {
continue
}
expanded, ok := expandSequenceExpr(stringKey, toolbox.AsString(caseTag), sequencerMapping, sequencer, sequencerValues, state)
if ok {
value[expanded] = keyValue
delete(value, key)
}
}
}

}

tableDataSlice[i] = itemMap
Expand All @@ -169,6 +185,32 @@ func convertMultiTables(tables map[string]interface{}, state data.Map, prefix st
return result, nil
}

func expandSequenceExpr(value, caseTag string, sequencerMapping data.Map, sequencer string, sequencerValues data.Map, state data.Map) (interface{}, bool) {
if caseTag != "" && strings.Contains(value, "${tag}") {
value = strings.Replace(value, "${tag}", toolbox.AsString(caseTag), 1)
}

if strings.Contains(value, "$") {
expr, key := getSequencerExpr(value, sequencer)
seqValue, ok := sequencerValues[key]
if !ok {
seqValue, ok = sequencerValues.GetValue(key)
}
if !ok {
return value, false
}
value = strings.ReplaceAll(value, expr, toolbox.AsString(seqValue))
if strings.Contains(value, "$") {
if strings.HasPrefix(value, "$AsInt") {
value = value[7 : len(value)-1]
}
value = state.ExpandAsText(value)
}
return value, true
}
return value, false
}

func getSequencerExpr(value string, sequencer string) (string, string) {
expr := "$" + sequencer + "."
index := strings.Index(value, expr)
Expand All @@ -181,6 +223,12 @@ func getSequencerExpr(value string, sequencer string) (string, string) {
}
expr = value[index:]
value = value[index+1+len(sequencer+"."):]
if idx := strings.Index(value, ")"); idx != -1 {
value = value[:idx]
if idx = strings.Index(expr, ")"); idx != -1 {
expr = expr[:idx]
}
}
return expr, value
}

Expand Down

0 comments on commit 2c8ec55

Please sign in to comment.