Skip to content

Commit

Permalink
[Admin/artifacts] Fix parsing of query inputs (#196)
Browse files Browse the repository at this point in the history
When admin runs an artifact query that has partition values that are parameterized by other inputs, it must first convert those inputs to strings as all partition values are strings.  The parsing for integers was incorrect.

See this for example user code.
https://github.com/unionai/unionai/blob/7e554d70753a3cb0abbb424a143a40a3a26d7f16/tests/functional/workflows/ingest_data.py#L71

The query was coming to the backend without the "depth" partition.
  • Loading branch information
wild-endeavor committed Apr 8, 2024
1 parent 80edae2 commit 494cbcc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flyteadmin/pkg/manager/impl/execution_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,11 +750,15 @@ func (m *ExecutionManager) getStringFromInput(ctx context.Context, inputBinding
p := inputVal.GetScalar().GetPrimitive()
switch p.GetValue().(type) {
case *core.Primitive_Integer:
strVal = p.GetStringValue()
strVal = fmt.Sprintf("%d", p.GetInteger())
case *core.Primitive_Datetime:
t := time.Unix(p.GetDatetime().Seconds, int64(p.GetDatetime().Nanos))
t = t.In(time.UTC)
strVal = t.Format("2006-01-02")
if t.Hour() == 0 && t.Minute() == 0 && t.Second() == 0 {
strVal = t.Format("2006-01-02")
} else {
strVal = t.Format("2006-01-02T15:04:05Z07:00")
}
case *core.Primitive_StringValue:
strVal = p.GetStringValue()
case *core.Primitive_FloatValue:
Expand Down
42 changes: 42 additions & 0 deletions flyteadmin/pkg/manager/impl/execution_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6035,3 +6035,45 @@ func TestQueryTemplate(t *testing.T) {
assert.Error(t, err)
})
}

func TestLiteralParsing(t *testing.T) {
ctx := context.Background()

aDate := time.Date(
2063, 4, 5, 00, 00, 00, 0, time.UTC)
aTime := time.Date(
2063, 4, 5, 15, 42, 00, 0, time.UTC)

rawInputs := map[string]interface{}{
"aStr": "hello world",
"anInt": 1,
"aFloat": 6.62607015e-34,
"aDate": aDate,
"aTime": aTime,
"aBool": true,
}

otherInputs, err := coreutils.MakeLiteralMap(rawInputs)
assert.NoError(t, err)

m := ExecutionManager{}
testCases := []struct {
varName string
expectedString string
}{
{"aStr", "hello world"},
{"anInt", "1"},
{"aFloat", "0.00"},
{"aDate", "2063-04-05"},
{"aTime", "2063-04-05T15:42:00Z"},
{"aBool", "true"},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("Parse %s", tc.varName), func(t *testing.T) {
binding := core.InputBindingData{Var: tc.varName}
strVal, err := m.getStringFromInput(ctx, binding, otherInputs.Literals)
assert.NoError(t, err)
assert.Equal(t, tc.expectedString, strVal)
})
}
}

0 comments on commit 494cbcc

Please sign in to comment.