Skip to content

Commit

Permalink
Fix ConfigEvalEngine.evalObjectRecursive().
Browse files Browse the repository at this point in the history
If nested, no information provided, failed to substitute the variable.
This is related to treasure-data#974, treasure-data#678.
  • Loading branch information
You Yamagata committed Apr 8, 2019
1 parent db87da8 commit 3c78545
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ private ObjectNode evalObjectRecursive(ObjectNode local)
throws TemplateException
{
ObjectNode built = local.objectNode();
return evalObjectRecursive(built, built, local);
}

private ObjectNode evalObjectRecursive(ObjectNode built, ObjectNode reference, ObjectNode local)
throws TemplateException
{
for (Map.Entry<String, JsonNode> pair : ImmutableList.copyOf(local.fields())) {
JsonNode value = pair.getValue();
JsonNode evaluated;
Expand All @@ -153,15 +159,15 @@ private ObjectNode evalObjectRecursive(ObjectNode local)
evaluated = value;
}
else if (value.isObject()) {
evaluated = evalObjectRecursive((ObjectNode) value);
evaluated = evalObjectRecursive(local.objectNode(), built, (ObjectNode) value);
}
else if (value.isArray()) {
evaluated = evalArrayRecursive(built, (ArrayNode) value);
}
else if (value.isTextual()) {
// eval using template engine
String code = value.textValue();
evaluated = evalValue(built, code);
evaluated = evalValue(reference, code);
}
else {
evaluated = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public void testBasic()
is(loadYamlResource("/io/digdag/core/agent/eval/basic_expected.dig")));
}

@Test
public void testNestedVars()
throws Exception
{
assertThat(
engine.eval(loadYamlResource("/io/digdag/core/agent/eval/nested_vars.dig"), params()),
is(loadYamlResource("/io/digdag/core/agent/eval/nested_vars_expected.dig")));
}

@Test
public void testLiteral()
throws Exception
Expand Down

0 comments on commit 3c78545

Please sign in to comment.