Kinetica   C#   API  Version 7.2.3.1
AsyncGetRecordsTests.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Threading.Tasks;
4 using Xunit;
6 using kinetica;
7 
9 {
14  [Trait("Category", "Integration")]
15  [Trait("Category", "Async")]
16  public class AsyncGetRecordsTests
17  {
18  private async Task<string> SetupTestTableAsync(TestContext ctx, int numRecords)
19  {
20  var tableName = ctx.QualifiedTable("test_table");
21 
22  // Create table using SQL
23  await ctx.Kinetica.ExecuteSqlAsync($"CREATE TABLE {tableName} (id INT NOT NULL, x DOUBLE, y DOUBLE, PRIMARY KEY (id))");
24 
25  // Insert records
26  for (int i = 0; i < numRecords; i++)
27  {
28  await ctx.Kinetica.ExecuteSqlAsync($"INSERT INTO {tableName} (id, x, y) VALUES ({i}, {i * 0.5}, {i * 1.5})");
29  }
30 
31  return tableName;
32  }
33 
34  [Fact]
35  public async Task TestGetRecordsAllAsync()
36  {
37  using var ctx = new TestContext("async_get_all");
38  var tableName = await SetupTestTableAsync(ctx, 100);
39 
40  var resp = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName}", 0, -9999);
41 
42  Assert.Equal(100, resp.total_number_of_records);
43  Assert.False(resp.has_more_records);
44  }
45 
46  [Fact]
47  public async Task TestGetRecordsPaginationAsync()
48  {
49  using var ctx = new TestContext("async_get_pagn");
50  var tableName = await SetupTestTableAsync(ctx, 100);
51 
52  // Get first page
53  var page1 = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName}", 0, 25);
54 
55  Assert.Equal(100, page1.total_number_of_records);
56  Assert.True(page1.has_more_records);
57 
58  // Get second page
59  var page2 = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName}", 25, 25);
60 
61  Assert.True(page2.has_more_records);
62 
63  // Get last page
64  var page4 = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName}", 75, 25);
65 
66  Assert.False(page4.has_more_records);
67  }
68 
69  [Fact]
70  public async Task TestGetRecordsWithFilterAsync()
71  {
72  using var ctx = new TestContext("async_get_filter");
73  var tableName = await SetupTestTableAsync(ctx, 100);
74 
75  // Filter for x < 25
76  var resp = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName} WHERE x < 25", 0, -9999);
77 
78  Assert.Equal(50, resp.total_number_of_records); // x = id * 0.5, so x < 25 means id < 50
79  }
80 
81  [Fact]
82  public async Task TestGetRecordsWithSortingAsync()
83  {
84  using var ctx = new TestContext("async_get_sort");
85  var tableName = await SetupTestTableAsync(ctx, 10);
86 
87  // Sort by x descending
88  var resp = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName} ORDER BY x DESC", 0, -9999);
89 
90  Assert.Equal(10, resp.total_number_of_records);
91  // First record should have highest x value (9 * 0.5 = 4.5)
92  Assert.True(resp.data.Count > 0);
93  }
94 
95  [Fact]
96  public async Task TestGetRecordsLimitZeroAsync()
97  {
98  using var ctx = new TestContext("async_get_limit0");
99  var tableName = await SetupTestTableAsync(ctx, 100);
100 
101  // Limit 0 should return no data but correct total count
102  var resp = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName}", 0, 0);
103 
104  Assert.Equal(100, resp.total_number_of_records);
105  Assert.Empty(resp.data);
106  }
107 
108  [Fact]
110  {
111  using var ctx = new TestContext("async_get_empty");
112  var tableName = await SetupTestTableAsync(ctx, 0);
113 
114  var resp = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName}", 0, -9999);
115 
116  Assert.Equal(0, resp.total_number_of_records);
117  Assert.Empty(resp.data);
118  Assert.False(resp.has_more_records);
119  }
120 
121  [Fact]
123  {
124  using var ctx = new TestContext("async_get_offset");
125  var tableName = await SetupTestTableAsync(ctx, 10);
126 
127  // Offset beyond table size
128  var resp = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName}", 100, 10);
129 
130  Assert.Equal(10, resp.total_number_of_records);
131  Assert.Empty(resp.data);
132  }
133  }
134 }
Test context that manages schema and cleanup for integration tests.
Definition: TestContext.cs:11
string QualifiedTable(string tableName)
Get a qualified table name (schema.table).
Definition: TestContext.cs:74