Search in sources :

Example 1 with JSONTDSSerializer

use of org.finos.legend.engine.plan.execution.stores.relational.serialization.JSONTDSSerializer 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 JSONTDSSerializer

use of org.finos.legend.engine.plan.execution.stores.relational.serialization.JSONTDSSerializer 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)

Aggregations

ExecutionNodeExecutor (org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor)2 ExecutionState (org.finos.legend.engine.plan.execution.nodes.state.ExecutionState)2 RelationalStoreExecutionState (org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState)2 RelationalStoreState (org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState)2 RelationalResult (org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult)2 JSONTDSSerializer (org.finos.legend.engine.plan.execution.stores.relational.serialization.JSONTDSSerializer)2 RelationalResultToJsonDefaultSerializer (org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToJsonDefaultSerializer)2 RelationalResultToPureTDSSerializer (org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSSerializer)2 RelationalResultToPureTDSToObjectSerializer (org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSToObjectSerializer)2 SingleExecutionPlan (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan)2 Test (org.junit.Test)2 RelationalResultToCSVSerializer (org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToCSVSerializer)1