Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quiet failures with un-implemented operator #156

Closed
nsenave opened this issue Apr 1, 2022 · 1 comment
Closed

Quiet failures with un-implemented operator #156

nsenave opened this issue Apr 1, 2022 · 1 comment
Assignees
Labels
S Small
Milestone

Comments

@nsenave
Copy link
Contributor

nsenave commented Apr 1, 2022

When evaluating an operator not yet supported, there is sometimes no exception thrown.

Test example with current_date operator using Trevas 0.3.0 (& junit 5)

import fr.insee.vtl.model.Dataset;
import fr.insee.vtl.model.InMemoryDataset;
import fr.insee.vtl.model.Structured;
import org.junit.jupiter.api.Test;

import javax.script.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class SomeTests {

    @Test
    public void testCurrentDate() throws ScriptException {
        //
        Dataset fooDataset = new InMemoryDataset(
                List.of(List.of(1L, "foo")),
                List.of(new Structured.Component("ID", Long.class, Dataset.Role.IDENTIFIER),
                        new Structured.Component("FOO", String.class, Dataset.Role.MEASURE))
        );
        //
        SimpleBindings bindings = new SimpleBindings();
        bindings.put("ds", fooDataset);
        //
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("vtl");
        engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        engine.eval("ds := ds [ calc FOO_YEAR := (substr(cast(current_date(),string),1,4)) ];");

        //
        String currentYear = DateTimeFormatter.ofPattern("yyyy").format(LocalDateTime.now());
        assertEquals(currentYear, ((Dataset) bindings.get("ds")).getDataPoints().get(0).get("FOO_YEAR"));
    }
}

This test logically fails since current_date is not supported in 0.3.0, yet there is neither warning nor exception thrown. (The documentation doesn't cover this case)

@FranckCo FranckCo added the S Small label Apr 11, 2022
@nsenave
Copy link
Contributor Author

nsenave commented Apr 11, 2022

Erratum thanks to @NicoLaval 's answer at issue #155: the operator current_date is actually supported in 0.3.0.

The syntax cast(current_date(), string) is incorrect since date pattern is missing.

Test succeeds when replacing it with cast(current_date(), string, "yyyy-MM-dd")

Still, an exception or warning might be helpful in the wrong case.

@hadrienk hadrienk changed the title Quite failures with un-implemented operator Quiet failures with un-implemented operator Apr 12, 2022
@FranckCo FranckCo added this to the Version 0.4.0 milestone Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S Small
Projects
None yet
Development

No branches or pull requests

3 participants