From 647205b8def8dc6b467fdfbea63916bb19a8e5e6 Mon Sep 17 00:00:00 2001 From: "helmi.nour" Date: Thu, 13 Oct 2022 22:27:18 +0100 Subject: [PATCH 1/2] move load json & csv to use v2 protocol --- RelationalAI.Test/DatabaseTest.cs | 3 +- RelationalAI.Test/LoadCsvTest.cs | 255 +++++------------------------- RelationalAI.Test/LoadJsonTest.cs | 30 +--- RelationalAI/Client.cs | 8 +- 4 files changed, 52 insertions(+), 244 deletions(-) diff --git a/RelationalAI.Test/DatabaseTest.cs b/RelationalAI.Test/DatabaseTest.cs index 69893e6..15a1119 100644 --- a/RelationalAI.Test/DatabaseTest.cs +++ b/RelationalAI.Test/DatabaseTest.cs @@ -89,8 +89,7 @@ public async Task DatabaseCloneTest() // load some data and model var loadRsp = await client.LoadJsonAsync(Dbname, EngineName, "test_data", TestJson); - Assert.False(loadRsp.Aborted); - Assert.Empty(loadRsp.Output); + Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); var resp = await client.LoadModelsAsync(Dbname, EngineName, TestModel); diff --git a/RelationalAI.Test/LoadCsvTest.cs b/RelationalAI.Test/LoadCsvTest.cs index 9951b60..3e378af 100644 --- a/RelationalAI.Test/LoadCsvTest.cs +++ b/RelationalAI.Test/LoadCsvTest.cs @@ -19,7 +19,7 @@ public class LoadCsvTests : UnitTest "\"bellini\",3,12.25,\"2020-04-04\"\n"; [Fact] - public async Task LoadCsvtTest() + public async Task LoadCsvTest() { var client = CreateClient(); @@ -27,59 +27,18 @@ public async Task LoadCsvtTest() await client.CreateDatabaseAsync(Dbname, EngineName); var loadRsp = await client.LoadCsvAsync(Dbname, EngineName, "sample", Sample); - Assert.False(loadRsp.Aborted); - Assert.Empty(loadRsp.Output); + Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteV1Async(Dbname, EngineName, "def output = sample"); - - var rel = FindRelation(rsp.Output, ":date"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"2020-01-01", "2020-02-02", "2020-03-03", "2020-04-04"} - }, - rel.Columns - ); - - rel = FindRelation(rsp.Output, ":price"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"12.50", "14.25", "11.00", "12.25"} - }, - rel.Columns - ); - - rel = FindRelation(rsp.Output, ":quantity"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"2", "4", "4", "3"} - }, - rel.Columns - ); - - rel = FindRelation(rsp.Output, ":cocktail"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"martini", "sazerac", "cosmopolitan", "bellini"} - }, - rel.Columns - ); + var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample"); + Assert.Equal(rsp.Results[0].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[1].Table, new List { "martini", "sazerac", "cosmopolitan", "bellini" }); + Assert.Equal(rsp.Results[2].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[3].Table, new List { "2020-01-01", "2020-02-02", "2020-03-03", "2020-04-04" }); + Assert.Equal(rsp.Results[4].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[5].Table, new List { "12.50", "14.25", "11.00", "12.25" }); + Assert.Equal(rsp.Results[6].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[7].Table, new List { "2", "4", "4", "3" }); } private const string SampleNoHeader = "" + @@ -98,60 +57,18 @@ public async Task LoadCsvNoHeaderTest() var opts = new CsvOptions().WithHeaderRow(0); var loadRsp = await client.LoadCsvAsync(Dbname, EngineName, "sample_no_header", SampleNoHeader, opts); - Assert.False(loadRsp.Aborted); - Assert.Empty(loadRsp.Output); + Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteV1Async(Dbname, EngineName, "def output = sample_no_header"); - - var rel = FindRelation(rsp.Output, ":COL1"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {1L, 2L, 3L, 4L}, - new object[] {"martini", "sazerac", "cosmopolitan", "bellini"} - }, - rel.Columns - ); - - - rel = FindRelation(rsp.Output, ":COL2"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {1L, 2L, 3L, 4L}, - new object[] {"2", "4", "4", "3"} - }, - rel.Columns - ); - - rel = FindRelation(rsp.Output, ":COL3"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {1L, 2L, 3L, 4L}, - new object[] {"12.50", "14.25", "11.00", "12.25"} - }, - rel.Columns - ); - - rel = FindRelation(rsp.Output, ":COL4"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {1L, 2L, 3L, 4L}, - new object[] {"2020-01-01", "2020-02-02", "2020-03-03", "2020-04-04"} - }, - rel.Columns - ); + var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample_no_header"); + Assert.Equal(rsp.Results[0].Table, new List { 1L, 2L, 3L, 4L }); + Assert.Equal(rsp.Results[1].Table, new List { "martini", "sazerac", "cosmopolitan", "bellini" }); + Assert.Equal(rsp.Results[2].Table, new List { 1L, 2L, 3L, 4L }); + Assert.Equal(rsp.Results[3].Table, new List { "2", "4", "4", "3" }); + Assert.Equal(rsp.Results[4].Table, new List { 1L, 2L, 3L, 4L }); + Assert.Equal(rsp.Results[5].Table, new List { "12.50", "14.25", "11.00", "12.25" }); + Assert.Equal(rsp.Results[6].Table, new List { 1L, 2L, 3L, 4L }); + Assert.Equal(rsp.Results[7].Table, new List { "2020-01-01", "2020-02-02", "2020-03-03", "2020-04-04" }); } private const string SampleAltSyntax = "" + @@ -171,59 +88,18 @@ public async Task LoadCsvAltSyntaxTest() var opts = new CsvOptions().WithDelim('|').WithQuoteChar('\''); var loadRsp = await client.LoadCsvAsync(Dbname, EngineName, "sample_alt_syntax", SampleAltSyntax, opts); - Assert.False(loadRsp.Aborted); - Assert.Empty(loadRsp.Output); + Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteV1Async(Dbname, EngineName, "def output = sample_alt_syntax"); - - var rel = FindRelation(rsp.Output, ":date"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"2020-01-01", "2020-02-02", "2020-03-03", "2020-04-04"} - }, - rel.Columns - ); - - rel = FindRelation(rsp.Output, ":price"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"12.50", "14.25", "11.00", "12.25"} - }, - rel.Columns - ); - - rel = FindRelation(rsp.Output, ":quantity"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"2", "4", "4", "3"} - }, - rel.Columns - ); - - rel = FindRelation(rsp.Output, ":cocktail"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"martini", "sazerac", "cosmopolitan", "bellini"} - }, - rel.Columns - ); + var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample_alt_syntax"); + Assert.Equal(rsp.Results[0].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[1].Table, new List { "martini", "sazerac", "cosmopolitan", "bellini" }); + Assert.Equal(rsp.Results[2].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[3].Table, new List { "2020-01-01", "2020-02-02", "2020-03-03", "2020-04-04" }); + Assert.Equal(rsp.Results[4].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[5].Table, new List { "12.50", "14.25", "11.00", "12.25" }); + Assert.Equal(rsp.Results[6].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[7].Table, new List { "2", "4", "4", "3" }); } [Fact] @@ -244,67 +120,18 @@ public async Task LoadCsvWithSchemaTest() var opts = new CsvOptions().WithSchema(schema); var loadRsp = await client.LoadCsvAsync(Dbname, EngineName, "sample", Sample, opts); - Assert.False(loadRsp.Aborted); - Assert.Empty(loadRsp.Output); + Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteV1Async(Dbname, EngineName, "def output = sample"); - - var rel = FindRelation(rsp.Output, ":date"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"2020-01-01", "2020-02-02", "2020-03-03", "2020-04-04"} - }, - rel.Columns - ); - Assert.Single(rel.RelKey.Values); - Assert.Equal("Dates.Date", rel.RelKey.Values[0]); - - rel = FindRelation(rsp.Output, ":price"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {12.5, 14.25, 11.00, 12.25} - }, - rel.Columns - ); - Assert.Single(rel.RelKey.Values); - Assert.Equal("FixedPointDecimals.FixedDecimal{Int64, 2}", rel.RelKey.Values[0]); - - rel = FindRelation(rsp.Output, ":quantity"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {2L, 4L, 4L, 3L} - }, - rel.Columns - ); - Assert.Single(rel.RelKey.Values); - Assert.Equal("Int64", rel.RelKey.Values[0]); - - rel = FindRelation(rsp.Output, ":cocktail"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal( - new[] - { - new object[] {2L, 3L, 4L, 5L}, - new object[] {"martini", "sazerac", "cosmopolitan", "bellini"} - }, - rel.Columns - ); - Assert.Single(rel.RelKey.Values); - Assert.Equal("String", rel.RelKey.Values[0]); + var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample"); + Assert.Equal(rsp.Results[0].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[1].Table, new List { "martini", "sazerac", "cosmopolitan", "bellini" }); + Assert.Equal(rsp.Results[2].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[3].Table, new List { 737425L, 737457L, 737487L, 737519L }); + Assert.Equal(rsp.Results[4].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[5].Table, new List { 1250L, 1425L, 1100L, 1225L }); + Assert.Equal(rsp.Results[6].Table, new List { 2L, 3L, 4L, 5L }); + Assert.Equal(rsp.Results[7].Table, new List { 2L, 4L, 4L, 3L }); } public override async Task DisposeAsync() diff --git a/RelationalAI.Test/LoadJsonTest.cs b/RelationalAI.Test/LoadJsonTest.cs index 8a8f9be..cd2927a 100644 --- a/RelationalAI.Test/LoadJsonTest.cs +++ b/RelationalAI.Test/LoadJsonTest.cs @@ -17,7 +17,7 @@ public class LoadJsonTests : UnitTest "\"pets\":[\"dog\",\"rabbit\"]}"; [Fact] - public async Task LoadJsontTest() + public async Task LoadJsonTest() { var client = CreateClient(); @@ -25,31 +25,13 @@ public async Task LoadJsontTest() await client.CreateDatabaseAsync(Dbname, EngineName); var loadRsp = await client.LoadJsonAsync(Dbname, EngineName, "sample", Sample); - Assert.False(loadRsp.Aborted); - Assert.Empty(loadRsp.Output); + Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteV1Async(Dbname, EngineName, "def output = sample"); - - var rel = FindRelation(rsp.Output, ":name"); - Assert.NotNull(rel); - Assert.Single(rel.Columns); - Assert.Equal(new[] { new object[] { "Amira" } }, rel.Columns); - - rel = FindRelation(rsp.Output, ":age"); - Assert.NotNull(rel); - Assert.Single(rel.Columns); - Assert.Equal(new[] { new object[] { 32L } }, rel.Columns); - - rel = FindRelation(rsp.Output, ":height"); - Assert.NotNull(rel); - Assert.Single(rel.Columns); - Assert.Equal(new[] { new object[] { null } }, rel.Columns); - - rel = FindRelation(rsp.Output, ":pets"); - Assert.NotNull(rel); - Assert.Equal(2, rel.Columns.Length); - Assert.Equal(new[] { new object[] { 1L, 2L }, new object[] { "dog", "rabbit" } }, rel.Columns); + // FIXME: complete the test implementation + // when this issue https://github.com/RelationalAI/rai-sdk-csharp/issues/25 + // is fixed + //var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample"); } public override async Task DisposeAsync() diff --git a/RelationalAI/Client.cs b/RelationalAI/Client.cs index c7d39f6..62f7767 100644 --- a/RelationalAI/Client.cs +++ b/RelationalAI/Client.cs @@ -498,7 +498,7 @@ public async Task ExecuteAsync( return ReadTransactionAsyncResults(rsp as List); } - public Task LoadJsonAsync( + public Task LoadJsonAsync( string database, string engine, string relation, @@ -509,10 +509,10 @@ public Task LoadJsonAsync( { "data", data } }; var source = GenLoadJson(relation); - return ExecuteV1Async(database, engine, source, false, inputs); + return ExecuteWaitAsync(database, engine, source, false, inputs); } - public Task LoadCsvAsync( + public Task LoadCsvAsync( string database, string engine, string relation, @@ -524,7 +524,7 @@ public Task LoadCsvAsync( { { "data", data } }; - return ExecuteV1Async(database, engine, source, false, inputs); + return ExecuteWaitAsync(database, engine, source, false, inputs); } private static TransactionMode CreateMode(string source, bool overwrite) From 5dd81cc98fe36565d86aec66f561e3eb1db7b10c Mon Sep 17 00:00:00 2001 From: "helmi.nour" Date: Fri, 14 Oct 2022 13:54:48 +0100 Subject: [PATCH 2/2] fix --- RelationalAI.Test/LoadCsvTest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RelationalAI.Test/LoadCsvTest.cs b/RelationalAI.Test/LoadCsvTest.cs index 3e378af..d23fd89 100644 --- a/RelationalAI.Test/LoadCsvTest.cs +++ b/RelationalAI.Test/LoadCsvTest.cs @@ -30,7 +30,7 @@ public async Task LoadCsvTest() Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample"); + var rsp = await client.ExecuteWaitAsync(Dbname, EngineName, "def output = sample"); Assert.Equal(rsp.Results[0].Table, new List { 2L, 3L, 4L, 5L }); Assert.Equal(rsp.Results[1].Table, new List { "martini", "sazerac", "cosmopolitan", "bellini" }); Assert.Equal(rsp.Results[2].Table, new List { 2L, 3L, 4L, 5L }); @@ -60,7 +60,7 @@ public async Task LoadCsvNoHeaderTest() Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample_no_header"); + var rsp = await client.ExecuteWaitAsync(Dbname, EngineName, "def output = sample_no_header"); Assert.Equal(rsp.Results[0].Table, new List { 1L, 2L, 3L, 4L }); Assert.Equal(rsp.Results[1].Table, new List { "martini", "sazerac", "cosmopolitan", "bellini" }); Assert.Equal(rsp.Results[2].Table, new List { 1L, 2L, 3L, 4L }); @@ -91,7 +91,7 @@ public async Task LoadCsvAltSyntaxTest() Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample_alt_syntax"); + var rsp = await client.ExecuteWaitAsync(Dbname, EngineName, "def output = sample_alt_syntax"); Assert.Equal(rsp.Results[0].Table, new List { 2L, 3L, 4L, 5L }); Assert.Equal(rsp.Results[1].Table, new List { "martini", "sazerac", "cosmopolitan", "bellini" }); Assert.Equal(rsp.Results[2].Table, new List { 2L, 3L, 4L, 5L }); @@ -123,7 +123,7 @@ public async Task LoadCsvWithSchemaTest() Assert.Equal(TransactionAsyncState.Completed, loadRsp.Transaction.State); Assert.Empty(loadRsp.Problems); - var rsp = await client.ExecuteAsync(Dbname, EngineName, "def output = sample"); + var rsp = await client.ExecuteWaitAsync(Dbname, EngineName, "def output = sample"); Assert.Equal(rsp.Results[0].Table, new List { 2L, 3L, 4L, 5L }); Assert.Equal(rsp.Results[1].Table, new List { "martini", "sazerac", "cosmopolitan", "bellini" }); Assert.Equal(rsp.Results[2].Table, new List { 2L, 3L, 4L, 5L });