|
1 | | --- Tests error handling and integration with larger SQL queries. |
| 1 | +-- integration & error handling demo |
2 | 2 | .echo on |
3 | | -LOAD infera; |
4 | | - |
5 | | --- ============================================================================= |
6 | | --- Test 1: Error Handling for Non-existent Models |
7 | | --- ============================================================================= |
8 | | -SELECT '--- Testing Error Handling ---'; |
9 | | - |
10 | | --- Check info for a model that is not loaded. |
11 | | -SELECT infera_get_model_info('nonexistent_model'); |
12 | | - |
13 | | --- Try to unload a model that is not loaded. |
14 | | -SELECT infera_unload_model('nonexistent_model'); |
15 | | - |
16 | | - |
17 | | --- ============================================================================= |
18 | | --- Test 2: Batch Processing and Aggregation |
19 | | --- ============================================================================= |
20 | | -SELECT '--- Testing Batch Processing and Aggregation ---'; |
21 | | - |
22 | | --- Load a model to use for batch tests. |
23 | | -SELECT infera_load_model('linear', 'test/models/linear.onnx'); |
24 | | - |
25 | | --- Create a table with sample feature data, casting to FLOAT. |
26 | | -CREATE OR REPLACE TABLE features AS |
27 | | -SELECT |
28 | | - row_number() OVER () as id, |
29 | | - (random() * 10)::FLOAT as f1, |
30 | | - (random() * 10)::FLOAT as f2, |
31 | | - (random() * 10)::FLOAT as f3 |
32 | | -FROM generate_series(1, 100); |
33 | | - |
34 | | --- Run prediction on a single row from the table to test integration. |
35 | | --- This will now pass because the batch size is 1. |
36 | | -SELECT |
37 | | - id, |
38 | | - f1, f2, f3, |
39 | | - infera_predict('linear', f1, f2, f3) as prediction |
40 | | -FROM features |
41 | | -WHERE id = 1; |
42 | | - |
43 | | --- Use the prediction function on a single row for an aggregate query. |
44 | | -SELECT |
45 | | - AVG(infera_predict('linear', f1, f2, f3)) as avg_prediction, |
46 | | - COUNT(*) as total_rows |
47 | | -FROM features |
48 | | -WHERE id = 1; |
49 | | - |
50 | | - |
51 | | --- ============================================================================= |
52 | | --- Test 3: NULL Value Handling |
53 | | --- ============================================================================= |
54 | | -SELECT '--- Testing NULL Value Handling ---'; |
55 | | - |
56 | | --- The current implementation should throw an error when a feature is NULL. |
57 | | --- This test verifies that behavior. |
58 | | -CREATE OR REPLACE TABLE features_with_nulls AS |
59 | | -SELECT 1 as id, 1.0::FLOAT as f1, 2.0::FLOAT as f2, NULL::FLOAT as f3; |
60 | | - |
61 | | -SELECT infera_predict('linear', f1, f2, f3) FROM features_with_nulls; |
62 | | - |
63 | | - |
64 | | --- ============================================================================= |
65 | | --- Cleanup |
66 | | --- ============================================================================= |
67 | | -SELECT '--- Cleaning Up ---'; |
68 | | -DROP TABLE features; |
69 | | -DROP TABLE features_with_nulls; |
70 | | -SELECT infera_unload_model('linear'); |
| 3 | +load infera; |
| 4 | + |
| 5 | +-- section 1: missing model behavior |
| 6 | +select '## missing model behavior'; |
| 7 | +select infera_get_model_info('nonexistent_model') as missing_model_info; -- returns JSON with error |
| 8 | +select infera_unload_model('nonexistent_model') as unload_missing; -- idempotent true |
| 9 | + |
| 10 | +-- section 2: batch style predictions (deterministic) |
| 11 | +select '## batch predictions'; |
| 12 | +select infera_load_model('linear', 'test/models/linear.onnx') as loaded_linear; |
| 13 | +-- deterministic feature set (3 rows) |
| 14 | +create or replace table features as |
| 15 | +values |
| 16 | + (1, 1.0::float, 2.0::float, 3.0::float), |
| 17 | + (2, 0.5::float, 1.0::float, 1.5::float), |
| 18 | + (3, -1.0::float, 0.0::float, 2.0::float) |
| 19 | + ; |
| 20 | +-- compute predictions row-wise |
| 21 | +select column0 as id, column1 as f1, column2 as f2, column3 as f3, |
| 22 | + infera_predict('linear', column1, column2, column3) as prediction |
| 23 | +from features |
| 24 | +order by 1; |
| 25 | +-- aggregate over the small batch |
| 26 | +select avg(infera_predict('linear', column1, column2, column3)) as avg_prediction, |
| 27 | + count(*) as n |
| 28 | +from features; |
| 29 | + |
| 30 | +-- section 3: null feature error |
| 31 | +select '## null feature error'; |
| 32 | +create or replace table features_with_nulls as values (1, 1.0::float, 2.0::float, null::float); |
| 33 | +-- this will raise an error if executed directly; kept commented for demonstration |
| 34 | +-- select infera_predict('linear', column1, column2, column3) from features_with_nulls; |
| 35 | + |
| 36 | +-- instead, show detection: |
| 37 | +select column0 as id, |
| 38 | + (column3 is null) as has_null_feature |
| 39 | +from features_with_nulls; |
| 40 | + |
| 41 | +-- section 4: cleanup |
| 42 | +select '## cleanup'; |
| 43 | +drop table features; |
| 44 | +drop table features_with_nulls; |
| 45 | +select infera_unload_model('linear') as unloaded_linear; |
71 | 46 |
|
72 | 47 | .echo off |
0 commit comments