Search in sources :

Example 1 with Function

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function in project legend-engine by finos.

the class TestRelationalExecutor method testGMTTimeZonePlanWithDifferentSerializationFormats.

@Test
public void testGMTTimeZonePlanWithDifferentSerializationFormats() throws IOException {
    String planString = "{\"_type\":\"simple\",\"authDependent\":false,\"kerberos\":null,\"serializer\":{\"name\":\"pure\",\"version\":\"vX_X_X\"},\"templateFunctions\":[\"<#function renderCollection collection separator><#return collection?join(separator)></#function>\",\"<#function collectionSize collection> <#return collection?size> </#function>\"],\"rootExecutionNode\":{\"_type\":\"relationalTdsInstantiation\",\"resultType\":{\"_type\":\"tds\",\"tdsColumns\":[{\"name\":\"testDateTime\",\"type\":\"DateTime\",\"doc\":null,\"relationalType\":\"TIMESTAMP\",\"enumMapping\":{}}]},\"executionNodes\":[{\"_type\":\"sql\",\"resultType\":{\"_type\":\"dataType\",\"dataType\":\"meta::pure::metamodel::type::Any\"},\"executionNodes\":[],\"resultSizeRange\":null,\"implementation\":null,\"sqlQuery\":\"select \\\"root\\\".testDateTime as \\\"testDateTime\\\" from ProductSynonymTable as \\\"root\\\"\",\"onConnectionCloseCommitQuery\":null,\"onConnectionCloseRollbackQuery\":null,\"connection\":{\"_type\": \"RelationalDatabaseConnection\",\"type\": \"H2\",\"authenticationStrategy\" : {\"_type\" : \"test\"},\"datasourceSpecification\" : {\"_type\" : \"static\",\"databaseName\" : \"testDB\",\"host\":\"127.0.0.1\",\"port\" : \"" + serverPort + "\"},\"timeZone\":\"GMT\"},\"resultColumns\":[{\"label\":\"\\\"testDateTime\\\"\",\"dataType\":\"TIMESTAMP\"}]}],\"resultSizeRange\":null,\"implementation\":null},\"globalImplementationSupport\":null}";
    SingleExecutionPlan plan = objectMapper.readValue(planString, SingleExecutionPlan.class);
    RelationalResult result_default = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"testDateTime\",\"type\":\"DateTime\",\"relationalType\":\"TIMESTAMP\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".testDateTime as \\\"testDateTime\\\" from ProductSynonymTable as \\\"root\\\"\"}], \"result\" : {\"columns\" : [\"testDateTime\"], \"rows\" : [{\"values\": [\"2014-12-04T15:22:23.123456789+0000\"]},{\"values\": [\"2014-12-04T23:22:23.123456789+0000\"]},{\"values\": [\"2014-12-04T08:22:23.000000000+0000\"]},{\"values\": [\"2014-12-04T08:22:23.123000000+0000\"]},{\"values\": [\"2013-12-04T10:22:23.000000000+0000\"]},{\"values\": [\"2013-04-04T08:22:23.123000000+0000\"]}]}}", result_default.flush(new RelationalResultToJsonDefaultSerializer(result_default)));
    RelationalResult result_pureTdsObject = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("[{\"testDateTime\":\"2014-12-04T15:22:23.123456789+0000\"},{\"testDateTime\":\"2014-12-04T23:22:23.123456789+0000\"},{\"testDateTime\":\"2014-12-04T08:22:23.000000000+0000\"},{\"testDateTime\":\"2014-12-04T08:22:23.123000000+0000\"},{\"testDateTime\":\"2013-12-04T10:22:23.000000000+0000\"},{\"testDateTime\":\"2013-04-04T08:22:23.123000000+0000\"}]", result_pureTdsObject.flush(new RelationalResultToPureTDSToObjectSerializer(result_pureTdsObject)));
    RelationalResult result_pureTds = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("{\"columns\":[{\"name\":\"testDateTime\",\"type\":\"DateTime\"}],\"rows\":[{\"values\":[\"2014-12-04T15:22:23.123456789+0000\"]},{\"values\":[\"2014-12-04T23:22:23.123456789+0000\"]},{\"values\":[\"2014-12-04T08:22:23.000000000+0000\"]},{\"values\":[\"2014-12-04T08:22:23.123000000+0000\"]},{\"values\":[\"2013-12-04T10:22:23.000000000+0000\"]},{\"values\":[\"2013-04-04T08:22:23.123000000+0000\"]}]}", result_pureTds.flush(new RelationalResultToPureTDSSerializer(result_pureTds)));
    RelationalResult result_jsonTds = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("{\"columns\":[{\"name\":\"testDateTime\",\"type\":\"DateTime\",\"relationalType\":\"TIMESTAMP\"}],\"rows\":[[\"2014-12-04T15:22:23.123456789+0000\"],[\"2014-12-04T23:22:23.123456789+0000\"],[\"2014-12-04T08:22:23.000000000+0000\"],[\"2014-12-04T08:22:23.123000000+0000\"],[\"2013-12-04T10:22:23.000000000+0000\"],[\"2013-04-04T08:22:23.123000000+0000\"]]}", result_jsonTds.flush(new JSONTDSSerializer(result_jsonTds, false, false)));
    RelationalResult result_csv = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("2014-12-04 15:22:23.123456789\r\n" + "2014-12-04 23:22:23.123456789\r\n" + "2014-12-04 08:22:23.0\r\n" + "2014-12-04 08:22:23.123\r\n" + "2013-12-04 10:22:23.0\r\n" + "2013-04-04 08:22:23.123\r\n", result_csv.flush(new RelationalResultToCSVSerializer(result_csv)));
}
Also used : RelationalResultToPureTDSToObjectSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSToObjectSerializer) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) JSONTDSSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.JSONTDSSerializer) RelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult) RelationalResultToJsonDefaultSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToJsonDefaultSerializer) ExecutionNodeExecutor(org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) RelationalResultToPureTDSSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSSerializer) RelationalResultToCSVSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToCSVSerializer) Test(org.junit.Test)

Example 2 with Function

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function in project legend-engine by finos.

the class TestRelationalExecutor method testNonGMTTimeZonePlanWithDifferentSerializationFormats.

@Test
public void testNonGMTTimeZonePlanWithDifferentSerializationFormats() throws IOException {
    String planString = "{\"_type\":\"simple\",\"authDependent\":false,\"kerberos\":null,\"serializer\":{\"name\":\"pure\",\"version\":\"vX_X_X\"},\"templateFunctions\":[\"<#function renderCollection collection separator><#return collection?join(separator)></#function>\",\"<#function collectionSize collection> <#return collection?size> </#function>\"],\"rootExecutionNode\":{\"_type\":\"relationalTdsInstantiation\",\"resultType\":{\"_type\":\"tds\",\"tdsColumns\":[{\"name\":\"testDateTime\",\"type\":\"DateTime\",\"doc\":null,\"relationalType\":\"TIMESTAMP\",\"enumMapping\":{}}]},\"executionNodes\":[{\"_type\":\"sql\",\"resultType\":{\"_type\":\"dataType\",\"dataType\":\"meta::pure::metamodel::type::Any\"},\"executionNodes\":[],\"resultSizeRange\":null,\"implementation\":null,\"sqlQuery\":\"select \\\"root\\\".testDateTime as \\\"testDateTime\\\" from ProductSynonymTable as \\\"root\\\"\",\"onConnectionCloseCommitQuery\":null,\"onConnectionCloseRollbackQuery\":null,\"connection\":{\"_type\": \"RelationalDatabaseConnection\",\"type\": \"H2\",\"authenticationStrategy\" : {\"_type\" : \"test\"},\"datasourceSpecification\" : {\"_type\" : \"static\",\"databaseName\" : \"testDB\",\"host\":\"127.0.0.1\",\"port\" : \"" + serverPort + "\"},\"timeZone\":\"US/Arizona\"},\"resultColumns\":[{\"label\":\"\\\"testDateTime\\\"\",\"dataType\":\"TIMESTAMP\"}]}],\"resultSizeRange\":null,\"implementation\":null},\"globalImplementationSupport\":null}";
    SingleExecutionPlan plan = objectMapper.readValue(planString, SingleExecutionPlan.class);
    RelationalResult result_default = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"testDateTime\",\"type\":\"DateTime\",\"relationalType\":\"TIMESTAMP\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".testDateTime as \\\"testDateTime\\\" from ProductSynonymTable as \\\"root\\\"\"}], \"result\" : {\"columns\" : [\"testDateTime\"], \"rows\" : [{\"values\": [\"2014-12-04T22:22:23.123456789+0000\"]},{\"values\": [\"2014-12-05T06:22:23.123456789+0000\"]},{\"values\": [\"2014-12-04T15:22:23.000000000+0000\"]},{\"values\": [\"2014-12-04T15:22:23.123000000+0000\"]},{\"values\": [\"2013-12-04T17:22:23.000000000+0000\"]},{\"values\": [\"2013-04-04T15:22:23.123000000+0000\"]}]}}", result_default.flush(new RelationalResultToJsonDefaultSerializer(result_default)));
    RelationalResult result_pureTdsObject = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("[{\"testDateTime\":\"2014-12-04T22:22:23.123456789+0000\"},{\"testDateTime\":\"2014-12-05T06:22:23.123456789+0000\"},{\"testDateTime\":\"2014-12-04T15:22:23.000000000+0000\"},{\"testDateTime\":\"2014-12-04T15:22:23.123000000+0000\"},{\"testDateTime\":\"2013-12-04T17:22:23.000000000+0000\"},{\"testDateTime\":\"2013-04-04T15:22:23.123000000+0000\"}]", result_pureTdsObject.flush(new RelationalResultToPureTDSToObjectSerializer(result_pureTdsObject)));
    RelationalResult result_pureTds = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("{\"columns\":[{\"name\":\"testDateTime\",\"type\":\"DateTime\"}],\"rows\":[{\"values\":[\"2014-12-04T22:22:23.123456789+0000\"]},{\"values\":[\"2014-12-05T06:22:23.123456789+0000\"]},{\"values\":[\"2014-12-04T15:22:23.000000000+0000\"]},{\"values\":[\"2014-12-04T15:22:23.123000000+0000\"]},{\"values\":[\"2013-12-04T17:22:23.000000000+0000\"]},{\"values\":[\"2013-04-04T15:22:23.123000000+0000\"]}]}", result_pureTds.flush(new RelationalResultToPureTDSSerializer(result_pureTds)));
    RelationalResult result_jsonTds = (RelationalResult) plan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(plan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("{\"columns\":[{\"name\":\"testDateTime\",\"type\":\"DateTime\",\"relationalType\":\"TIMESTAMP\"}],\"rows\":[[\"2014-12-04T22:22:23.123456789+0000\"],[\"2014-12-05T06:22:23.123456789+0000\"],[\"2014-12-04T15:22:23.000000000+0000\"],[\"2014-12-04T15:22:23.123000000+0000\"],[\"2013-12-04T17:22:23.000000000+0000\"],[\"2013-04-04T15:22:23.123000000+0000\"]]}", result_jsonTds.flush(new JSONTDSSerializer(result_jsonTds, false, false)));
}
Also used : RelationalResultToPureTDSToObjectSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSToObjectSerializer) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) JSONTDSSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.JSONTDSSerializer) RelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult) RelationalResultToJsonDefaultSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToJsonDefaultSerializer) ExecutionNodeExecutor(org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) RelationalResultToPureTDSSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSSerializer) Test(org.junit.Test)

Example 3 with Function

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function in project legend-engine by finos.

the class TestRelationalExecutor method testErrorFromSqlTemplateFreeMarkerProcessingBubblesUp.

@Test
public void testErrorFromSqlTemplateFreeMarkerProcessingBubblesUp() throws IOException {
    String planWithTz = getTemplatePlanWithNoTz().replace("%timeZone%", ",\"timeZone\": \"GMT\"").replace("%templateFunctions%", "\"templateFunctions\": [],");
    String plan = planWithTz.replace("%dateTimeParam%", "testDateTime = '${GMTtoTZ( \\\"[US/Arizona]\\\" dt )}'");
    SingleExecutionPlan executionPlan = objectMapper.readValue(plan, SingleExecutionPlan.class);
    MutableMap<String, Result> vars = Maps.mutable.with("dt", new ConstantResult("2014-12-04T15:22:23"));
    IllegalStateException exception = Assert.assertThrows(IllegalStateException.class, () -> executionPlan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(vars, Lists.mutable.withAll(executionPlan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort)))))));
    assertThat(exception, hasMessage(startsWith("Reprocessing sql failed with vars [dt]")));
    assertThat(exception, hasCause(hasMessage(startsWith("Issue processing freemarker function.  Template with error: select \"root\".name as \"pk_0\", \"root\".synonym as \"pk_1\", \"root\".type as \"pk_2\", \"root\".synonym as \"synonym\", \"root\".type as \"type\", \"root\".testDate as \"testDate\", \"root\".testDateTime as \"testDateTime\", \"root\".from_z as \"k_businessDate\" from ProductSynonymTable as \"root\" where \"root\".testDateTime = 'FreeMarker template error "))));
}
Also used : ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) ExecutionNodeExecutor(org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) RelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) Result(org.finos.legend.engine.plan.execution.result.Result) Test(org.junit.Test)

Example 4 with Function

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function in project legend-engine by finos.

the class TestPlanExecutionForIn method testInExecutionWithIntegerList.

@Test
public void testInExecutionWithIntegerList() {
    String fetchFunction = "###Pure\n" + "function test::fetch(): Any[1]\n" + "{\n" + "  {nameLengths:Integer[*] | test::Person.all()\n" + "                               ->filter(p:test::Person[1] | $p.fullName->length()->in($nameLengths))\n" + "                               ->project([x | $x.fullName], ['fullName'])}\n" + "}";
    SingleExecutionPlan plan = buildPlanForFetchFunction(fetchFunction, false);
    Map<String, ?> paramWithEmptyList = Maps.mutable.with("nameLengths", Lists.mutable.empty());
    Map<String, ?> paramWithSingleValue = Maps.mutable.with("nameLengths", Lists.mutable.with(2));
    Map<String, ?> paramWithMultipleValues = Maps.mutable.with("nameLengths", Lists.mutable.with(2, 3));
    String expectedResWithEmptyList = "{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"fullName\",\"type\":\"String\",\"relationalType\":\"VARCHAR(100)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".fullName as \\\"fullName\\\" from PERSON as \\\"root\\\" where char_length(\\\"root\\\".fullName) in (null)\"}], \"result\" : {\"columns\" : [\"fullName\"], \"rows\" : []}}";
    String expectedResWithSingleValue = "{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"fullName\",\"type\":\"String\",\"relationalType\":\"VARCHAR(100)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".fullName as \\\"fullName\\\" from PERSON as \\\"root\\\" where char_length(\\\"root\\\".fullName) in (2)\"}], \"result\" : {\"columns\" : [\"fullName\"], \"rows\" : [{\"values\": [\"P1\"]},{\"values\": [\"P2\"]},{\"values\": [\"P3\"]},{\"values\": [\"P4\"]},{\"values\": [\"P5\"]}]}}";
    String expectedResWithMultipleValues = "{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"fullName\",\"type\":\"String\",\"relationalType\":\"VARCHAR(100)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".fullName as \\\"fullName\\\" from PERSON as \\\"root\\\" where char_length(\\\"root\\\".fullName) in (2,3)\"}], \"result\" : {\"columns\" : [\"fullName\"], \"rows\" : [{\"values\": [\"P1\"]},{\"values\": [\"P10\"]},{\"values\": [\"P2\"]},{\"values\": [\"P3\"]},{\"values\": [\"P4\"]},{\"values\": [\"P5\"]}]}}";
    Assert.assertEquals(expectedResWithEmptyList, executePlan(plan, paramWithEmptyList));
    Assert.assertEquals(expectedResWithSingleValue, executePlan(plan, paramWithSingleValue));
    Assert.assertEquals(expectedResWithMultipleValues, executePlan(plan, paramWithMultipleValues));
}
Also used : SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) Test(org.junit.Test)

Example 5 with Function

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function in project legend-engine by finos.

the class TestPlanExecutionForIn method testInExecutionWithStringList.

@Test
public void testInExecutionWithStringList() {
    String fetchFunction = "###Pure\n" + "function test::fetch(): Any[1]\n" + "{\n" + "  {names:String[*] | test::Person.all()\n" + "                        ->filter(p:test::Person[1] | $p.fullName->in($names))\n" + "                        ->project([x | $x.fullName], ['fullName'])}\n" + "}";
    SingleExecutionPlan plan = buildPlanForFetchFunction(fetchFunction, false);
    Map<String, ?> paramWithEmptyList = Maps.mutable.with("names", Lists.mutable.empty());
    Map<String, ?> paramWithSingleValue = Maps.mutable.with("names", Lists.mutable.with("P1"));
    Map<String, ?> paramWithMultipleValues = Maps.mutable.with("names", Lists.mutable.with("P1", "P2"));
    String expectedResWithEmptyList = "{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"fullName\",\"type\":\"String\",\"relationalType\":\"VARCHAR(100)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".fullName as \\\"fullName\\\" from PERSON as \\\"root\\\" where \\\"root\\\".fullName in (null)\"}], \"result\" : {\"columns\" : [\"fullName\"], \"rows\" : []}}";
    String expectedResWithSingleValue = "{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"fullName\",\"type\":\"String\",\"relationalType\":\"VARCHAR(100)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".fullName as \\\"fullName\\\" from PERSON as \\\"root\\\" where \\\"root\\\".fullName in ('P1')\"}], \"result\" : {\"columns\" : [\"fullName\"], \"rows\" : [{\"values\": [\"P1\"]}]}}";
    String expectedResWithMultipleValues = "{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"fullName\",\"type\":\"String\",\"relationalType\":\"VARCHAR(100)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".fullName as \\\"fullName\\\" from PERSON as \\\"root\\\" where \\\"root\\\".fullName in ('P1','P2')\"}], \"result\" : {\"columns\" : [\"fullName\"], \"rows\" : [{\"values\": [\"P1\"]},{\"values\": [\"P2\"]}]}}";
    Assert.assertEquals(expectedResWithEmptyList, executePlan(plan, paramWithEmptyList));
    Assert.assertEquals(expectedResWithSingleValue, executePlan(plan, paramWithSingleValue));
    Assert.assertEquals(expectedResWithMultipleValues, executePlan(plan, paramWithMultipleValues));
}
Also used : SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)59 SingleExecutionPlan (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan)57 List (java.util.List)16 MutableList (org.eclipse.collections.api.list.MutableList)15 ListIterate (org.eclipse.collections.impl.utility.ListIterate)15 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)13 RichIterable (org.eclipse.collections.api.RichIterable)12 Lists (org.eclipse.collections.impl.factory.Lists)12 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)12 Lambda (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)12 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)12 FastList (org.eclipse.collections.impl.list.mutable.FastList)11 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)10 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)10 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)10 Variable (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable)10 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)9 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)8 Objects (java.util.Objects)7 ConstantResult (org.finos.legend.engine.plan.execution.result.ConstantResult)7