datasonnet / datasonnet-mapper

A modern, template-based, open source data transformation language
Apache License 2.0
27 stars 14 forks source link

Unable to use DS libraries within an import file #84

Open JakeMHughes opened 3 years ago

JakeMHughes commented 3 years ago

We only seem to be able to use sjsonnet libraries inside of imported files. ( the ds namespace is not recognized)

Here is a simple junit test you can add to the ImportTest.java file to verify:

    @Test
    void importWithLib() {
        Mapper mapper = new Mapper("import 'example.ds'", Collections.emptyList(), Collections.singletonMap("example.ds", "{test: ds.contains([1,2],1)}"));
        String result = mapper.transform("{}");
        assertEquals("{\"test\":true}", result);
    }

The error response is sjsonnet.Error Unknown variable ds at .... so it does seem to initially evaluate correctly but has issues when actually used

jam01 commented 3 years ago

added test that confirms this bug here https://github.com/datasonnet/datasonnet-mapper/commit/e7b96046d3eeb5c147f561449e8b34b04383f802