Skip to content

Commit

Permalink
another unit tests for multiple cross apply and outer apply and relat…
Browse files Browse the repository at this point in the history
…ed to that fixes
  • Loading branch information
Puchaczov committed Sep 22, 2024
1 parent 3d73c87 commit 98ef8ee
Show file tree
Hide file tree
Showing 10 changed files with 560 additions and 54 deletions.
103 changes: 103 additions & 0 deletions Musoq.Evaluator.Tests/CrossApplyMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,44 @@ public void CrossApplyProperty_SplitStringToWords_ShouldPass()
Assert.AreEqual("elit.", table[7][0]);
}

[TestMethod]
public void CrossApplyProperty_MultipleSplitWords_ShouldPass()
{
const string query = "select b.Value, c.Value from #schema.first() a cross apply a.Split(a.Text, ' ') as b cross apply a.Split(a.Text, ' ') as c";

string[] words = ["Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit."];

var firstSource = new List<CrossApplyClass2>
{
new() {Text = string.Join(" ", words)},
}.ToArray();

var vm = CreateAndRunVirtualMachine(
query,
firstSource
);

var table = vm.Run();

Assert.AreEqual(2, table.Columns.Count());
Assert.AreEqual("b.Value", table.Columns.ElementAt(0).ColumnName);
Assert.AreEqual(typeof(string), table.Columns.ElementAt(0).ColumnType);
Assert.AreEqual("c.Value", table.Columns.ElementAt(1).ColumnName);
Assert.AreEqual(typeof(string), table.Columns.ElementAt(1).ColumnType);

Assert.AreEqual(64, table.Count);

for (var i = 0; i < words.Length; i++)
{
for (var j = 0; j < words.Length; j++)
{
var index = i * words.Length + j;
Assert.AreEqual(words[i], table[index][0], $"Mismatch at index {index}, column 0");
Assert.AreEqual(words[j], table[index][1], $"Mismatch at index {index}, column 1");
}
}
}

[TestMethod]
public void CrossApplyProperty_SkipAfterSplit_ShouldPass()
{
Expand Down Expand Up @@ -141,4 +179,69 @@ public void CrossApplyProperty_TakeSkipAfterSplit_ShouldPass()
Assert.AreEqual("consectetur", table[4][0]);
Assert.AreEqual("adipiscing", table[5][0]);
}

[TestMethod]
public void CrossApplyProperty_WhereCondition_ShouldPass()
{
const string query = "select b.Value from #schema.first() a cross apply a.Split(a.Text, ' ') as b where b.Value.Length > 5";

var firstSource = new List<CrossApplyClass2>
{
new() {Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."},
}.ToArray();

var vm = CreateAndRunVirtualMachine(
query,
firstSource
);

var table = vm.Run();

Assert.AreEqual(1, table.Columns.Count());
Assert.AreEqual("b.Value", table.Columns.ElementAt(0).ColumnName);
Assert.AreEqual(typeof(string), table.Columns.ElementAt(0).ColumnType);

Assert.AreEqual(2, table.Count);

Assert.AreEqual("consectetur", table[0][0]);
Assert.AreEqual("adipiscing", table[1][0]);
}

[TestMethod]
public void CrossApplyProperty_GroupBy_ShouldPass()
{
const string query = "select Length(b.Value), Count(Length(b.Value)) from #schema.first() a cross apply a.Split(a.Text, ' ') as b group by Length(b.Value)";

var firstSource = new List<CrossApplyClass2>
{
new() {Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."},
}.ToArray();

var vm = CreateAndRunVirtualMachine(
query,
firstSource
);

var table = vm.Run();

Assert.AreEqual(2, table.Columns.Count());
Assert.AreEqual("Length(b.Value)", table.Columns.ElementAt(0).ColumnName);
Assert.AreEqual(typeof(int?), table.Columns.ElementAt(0).ColumnType);
Assert.AreEqual("Count(Length(b.Value))", table.Columns.ElementAt(1).ColumnName);
Assert.AreEqual(typeof(int), table.Columns.ElementAt(1).ColumnType);

Assert.AreEqual(4, table.Count);

Assert.AreEqual(5, table[0][0]);
Assert.AreEqual(5, table[0][1]);

Assert.AreEqual(3, table[1][0]);
Assert.AreEqual(1, table[1][1]);

Assert.AreEqual(11, table[2][0]);
Assert.AreEqual(1, table[2][1]);

Assert.AreEqual(10, table[3][0]);
Assert.AreEqual(1, table[3][1]);
}
}
85 changes: 85 additions & 0 deletions Musoq.Evaluator.Tests/CrossApplySelfPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ private class CrossApplyClass4
public List<ComplexType1> Values { get; set; }
}

private class CrossApplyClass5
{
public string City { get; set; }

public double[] Values1 { get; set; }

public double[] Values2 { get; set; }
}

[TestMethod]
public void CrossApplyProperty_NoMatch_ShouldPass()
{
Expand Down Expand Up @@ -267,4 +276,80 @@ public void CrossApplyProperty_WithComplexList_ShouldPass()
Assert.AreEqual("Value6", table[5].Values[1]);
Assert.AreEqual(6, table[5].Values[2]);
}

[TestMethod]
public void CrossApplyProperty_MultiplePrimitiveArrays_ShouldPass()
{
const string query = "select b.Value, c.Value from #schema.first() a cross apply a.Values1 as b cross apply a.Values2 as c";

var firstSource = new List<CrossApplyClass5>
{
new() {City = "City1", Values1 = [1], Values2=[1.1]},
new() {City = "City2", Values1 = [2, 3], Values2 = [2.1, 2.2, 3.3]},
new() {City = "City3", Values1 = [4, 5, 6], Values2 = [4.1, 5.1, 6.1]}
}.ToArray();

var vm = CreateAndRunVirtualMachine(
query,
firstSource
);

var table = vm.Run();

Assert.AreEqual(2, table.Columns.Count());
Assert.AreEqual("b.Value", table.Columns.ElementAt(0).ColumnName);
Assert.AreEqual(typeof(double), table.Columns.ElementAt(0).ColumnType);
Assert.AreEqual("c.Value", table.Columns.ElementAt(1).ColumnName);
Assert.AreEqual(typeof(double), table.Columns.ElementAt(1).ColumnType);

Assert.AreEqual(16, table.Count);

Assert.AreEqual(1d, table[0].Values[0]);
Assert.AreEqual(1.1d, table[0].Values[1]);

Assert.AreEqual(2d, table[1].Values[0]);
Assert.AreEqual(2.1d, table[1].Values[1]);

Assert.AreEqual(2d, table[2].Values[0]);
Assert.AreEqual(2.2d, table[2].Values[1]);

Assert.AreEqual(2d, table[3].Values[0]);
Assert.AreEqual(3.3d, table[3].Values[1]);

Assert.AreEqual(3d, table[4].Values[0]);
Assert.AreEqual(2.1d, table[4].Values[1]);

Assert.AreEqual(3d, table[5].Values[0]);
Assert.AreEqual(2.2d, table[5].Values[1]);

Assert.AreEqual(3d, table[6].Values[0]);
Assert.AreEqual(3.3d, table[6].Values[1]);

Assert.AreEqual(4d, table[7].Values[0]);
Assert.AreEqual(4.1d, table[7].Values[1]);

Assert.AreEqual(4d, table[8].Values[0]);
Assert.AreEqual(5.1d, table[8].Values[1]);

Assert.AreEqual(4d, table[9].Values[0]);
Assert.AreEqual(6.1d, table[9].Values[1]);

Assert.AreEqual(5d, table[10].Values[0]);
Assert.AreEqual(4.1d, table[10].Values[1]);

Assert.AreEqual(5d, table[11].Values[0]);
Assert.AreEqual(5.1d, table[11].Values[1]);

Assert.AreEqual(5d, table[12].Values[0]);
Assert.AreEqual(6.1d, table[12].Values[1]);

Assert.AreEqual(6d, table[13].Values[0]);
Assert.AreEqual(4.1d, table[13].Values[1]);

Assert.AreEqual(6d, table[14].Values[0]);
Assert.AreEqual(5.1d, table[14].Values[1]);

Assert.AreEqual(6d, table[15].Values[0]);
Assert.AreEqual(6.1d, table[15].Values[1]);
}
}
103 changes: 103 additions & 0 deletions Musoq.Evaluator.Tests/OuterApplyMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,107 @@ public void OuterApplyProperty_TakeSkipAfterSplit_ShouldPass()
Assert.AreEqual("consectetur", table[4][0]);
Assert.AreEqual("adipiscing", table[5][0]);
}

[TestMethod]
public void OuterApplyProperty_WhereCondition_ShouldPass()
{
const string query = "select b.Value from #schema.first() a outer apply a.Split(a.Text, ' ') as b where b.Value.Length > 5";

var firstSource = new List<OuterApplyClass2>
{
new() {Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."},
}.ToArray();

var vm = CreateAndRunVirtualMachine(
query,
firstSource
);

var table = vm.Run();

Assert.AreEqual(1, table.Columns.Count());
Assert.AreEqual("b.Value", table.Columns.ElementAt(0).ColumnName);
Assert.AreEqual(typeof(string), table.Columns.ElementAt(0).ColumnType);

Assert.AreEqual(2, table.Count);

Assert.AreEqual("consectetur", table[0][0]);
Assert.AreEqual("adipiscing", table[1][0]);
}

[TestMethod]
public void OuterApplyProperty_GroupBy_ShouldPass()
{
const string query = "select Length(b.Value), Count(Length(b.Value)) from #schema.first() a outer apply a.Split(a.Text, ' ') as b group by Length(b.Value)";

var firstSource = new List<OuterApplyClass2>
{
new() {Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."},
}.ToArray();

var vm = CreateAndRunVirtualMachine(
query,
firstSource
);

var table = vm.Run();

Assert.AreEqual(2, table.Columns.Count());
Assert.AreEqual("Length(b.Value)", table.Columns.ElementAt(0).ColumnName);
Assert.AreEqual(typeof(int?), table.Columns.ElementAt(0).ColumnType);
Assert.AreEqual("Count(Length(b.Value))", table.Columns.ElementAt(1).ColumnName);
Assert.AreEqual(typeof(int), table.Columns.ElementAt(1).ColumnType);

Assert.AreEqual(4, table.Count);

Assert.AreEqual(5, table[0][0]);
Assert.AreEqual(5, table[0][1]);

Assert.AreEqual(3, table[1][0]);
Assert.AreEqual(1, table[1][1]);

Assert.AreEqual(11, table[2][0]);
Assert.AreEqual(1, table[2][1]);

Assert.AreEqual(10, table[3][0]);
Assert.AreEqual(1, table[3][1]);
}

[TestMethod]
public void OuterApplyProperty_MultipleSplitWords_ShouldPass()
{
const string query = "select b.Value, c.Value from #schema.first() a outer apply a.Split(a.Text, ' ') as b outer apply a.Split(a.Text, ' ') as c";

string[] words = ["Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit."];

var firstSource = new List<OuterApplyClass2>
{
new() {Text = string.Join(" ", words)},
}.ToArray();

var vm = CreateAndRunVirtualMachine(
query,
firstSource
);

var table = vm.Run();

Assert.AreEqual(2, table.Columns.Count());
Assert.AreEqual("b.Value", table.Columns.ElementAt(0).ColumnName);
Assert.AreEqual(typeof(string), table.Columns.ElementAt(0).ColumnType);
Assert.AreEqual("c.Value", table.Columns.ElementAt(1).ColumnName);
Assert.AreEqual(typeof(string), table.Columns.ElementAt(1).ColumnType);

Assert.AreEqual(64, table.Count);

for (var i = 0; i < words.Length; i++)
{
for (var j = 0; j < words.Length; j++)
{
var index = i * words.Length + j;
Assert.AreEqual(words[i], table[index][0], $"Mismatch at index {index}, column 0");
Assert.AreEqual(words[j], table[index][1], $"Mismatch at index {index}, column 1");
}
}
}
}
Loading

0 comments on commit 98ef8ee

Please sign in to comment.