Skip to content

Commit 51976b4

Browse files
committed
[ksqlDB.RestApi.Client] - group join - query syntax integration test
1 parent 92fb035 commit 51976b4

File tree

2 files changed

+87
-15
lines changed

2 files changed

+87
-15
lines changed

Tests/ksqlDB.RestApi.Client.IntegrationTests/KSql/Linq/JoinsTests.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
using ksqlDB.Api.Client.IntegrationTests.Models;
66
using ksqlDB.Api.Client.IntegrationTests.Models.Movies;
77
using ksqlDB.RestApi.Client.KSql.Linq;
8+
using ksqlDB.RestApi.Client.KSql.Query.Context;
89
using ksqlDB.RestApi.Client.KSql.Query.Functions;
10+
using ksqlDB.RestApi.Client.KSql.RestApi.Statements;
11+
using ksqlDB.RestApi.Client.KSql.RestApi.Statements.Annotations;
912
using Microsoft.VisualStudio.TestTools.UnitTesting;
1013

1114
namespace ksqlDB.Api.Client.IntegrationTests.KSql.Linq
@@ -162,5 +165,89 @@ public async Task FullOuterJoinTest(IQbservable<Movie2> querySource)
162165

163166
actualValues[2].Title.Should().BeOneOf(MoviesProvider.Movie1.Title, MoviesProvider.Movie2.Title, null);
164167
}
168+
169+
class Order
170+
{
171+
public int OrderId { get; set; }
172+
public int PaymentId { get; set; }
173+
public int ShipmentId { get; set; }
174+
}
175+
176+
#region MultipleJoins
177+
178+
class Payment
179+
{
180+
[Key]
181+
public int Id { get; set; }
182+
}
183+
184+
record Shipment
185+
{
186+
[Key]
187+
public int? Id { get; set; }
188+
}
189+
190+
struct Foo
191+
{
192+
public int Prop { get; set; }
193+
}
194+
195+
[TestMethod]
196+
public async Task MultipleJoins_QuerySyntax()
197+
{
198+
//Arrange
199+
int expectedItemsCount = 1;
200+
201+
var entityCreationMetadata = new EntityCreationMetadata
202+
{
203+
KafkaTopic = nameof(Order) + "-TestJoin",
204+
Partitions = 1
205+
};
206+
207+
var response = await RestApiProvider.CreateStreamAsync<Order>(entityCreationMetadata, ifNotExists: true);
208+
response = await RestApiProvider.CreateTableAsync<Payment>(entityCreationMetadata with { KafkaTopic = nameof(Payment) + "-TestJoin" }, ifNotExists: true);
209+
response = await RestApiProvider.CreateTableAsync<Shipment>(entityCreationMetadata with { KafkaTopic = nameof(Shipment) + "-TestJoin" }, ifNotExists: true);
210+
211+
var ksqlDbUrl = @"http:\\localhost:8088";
212+
213+
var context = new KSqlDBContext(ksqlDbUrl);
214+
215+
var value = new Foo { Prop = 42 };
216+
217+
var query = (from o in context.CreateQueryStream<Order>()
218+
join p1 in Source.Of<Payment>() on o.PaymentId equals p1.Id
219+
join s1 in Source.Of<Shipment>() on o.ShipmentId equals s1.Id into gj
220+
from sa in gj.DefaultIfEmpty()
221+
select new
222+
{
223+
value,
224+
orderId = o.OrderId,
225+
shipmentId = sa.Id,
226+
paymentId = p1.Id,
227+
})
228+
.Take(1);
229+
230+
var order = new Order { OrderId = 1, PaymentId = 1, ShipmentId = 1 };
231+
var payment = new Payment { Id = 1 };
232+
var shipment = new Shipment { Id = 1 };
233+
234+
response = await RestApiProvider.InsertIntoAsync(order);
235+
response = await RestApiProvider.InsertIntoAsync(payment);
236+
response = await RestApiProvider.InsertIntoAsync(shipment);
237+
238+
//Act
239+
var actualValues = await CollectActualValues(query.ToAsyncEnumerable(), expectedItemsCount);
240+
241+
//Assert
242+
Assert.AreEqual(expectedItemsCount, actualValues.Count);
243+
244+
actualValues[0].orderId.Should().Be(1);
245+
actualValues[0].paymentId.Should().Be(1);
246+
var shipmentId = actualValues[0].shipmentId;
247+
if (shipmentId.HasValue)
248+
shipmentId.Should().Be(1);
249+
}
250+
251+
#endregion
165252
}
166253
}

Tests/ksqlDB.RestApi.Client.Tests/KSql/Query/Visitors/JoinVisitorTests.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,6 @@ join s1 in Source.Of<Shipment>() on o.OrderId equals s1.Id
265265
paymentId = p1.Id,
266266
};
267267

268-
var query2 = (from o in KSqlDBContext.CreateQueryStream<Order>()
269-
join p1 in Source.Of<Payment>() on o.OrderId equals p1.Id
270-
join s1 in Source.Of<Shipment>() on o.OrderId equals s1.Id into gj
271-
from sa in gj.DefaultIfEmpty()
272-
select new
273-
{
274-
value,
275-
orderId = o.OrderId,
276-
shipmentId = sa.Id,
277-
paymentId = p1.Id,
278-
})
279-
.Take(5);
280-
281-
var s = query2.ToQueryString();
282-
283268
//Act
284269
var ksql = query.ToQueryString();
285270

0 commit comments

Comments
 (0)