77#include " ../programs/local/chdb.h"
88#include " ../contrib/arrow/cpp/src/arrow/c/abi.h"
99
10+ // Global test configuration
11+ static constexpr size_t TEST_TOTAL_ROWS = 100000 ;
12+ static constexpr size_t TEST_BATCH_SIZE = 10000 ;
13+
1014// Custom ArrowArrayStream implementation data
1115struct CustomStreamData
1216{
@@ -16,7 +20,7 @@ struct CustomStreamData
1620 size_t batch_size;
1721 std::string last_error;
1822
19- CustomStreamData () : schema_sent(false ), current_row(0 ), total_rows(1000000 ), batch_size(10000 ) {}
23+ CustomStreamData () : schema_sent(false ), current_row(0 ), total_rows(TEST_TOTAL_ROWS ), batch_size(TEST_BATCH_SIZE ) {}
2024
2125 // Reset the stream to allow reading from the beginning
2226 void reset ()
@@ -344,7 +348,7 @@ static void test_assert_row_count(chdb_result* result, uint64_t expected_rows, c
344348void test_arrow_scan (chdb_connection conn)
345349{
346350 std::cout << " \n === Creating Custom ArrowArrayStream ===\n " ;
347- std::cout << " Data specification: 1,000,000 rows × 2 columns (id: int64, value: string)\n " ;
351+ std::cout << " Data specification: " << TEST_TOTAL_ROWS << " rows × 2 columns (id: int64, value: string)\n " ;
348352
349353 struct ArrowArrayStream stream;
350354 memset (&stream, 0 , sizeof (stream));
@@ -375,9 +379,9 @@ void test_arrow_scan(chdb_connection conn)
375379 result = chdb_arrow_unregister_table (conn, non_exist_table_name);
376380 test_assert_chdb_state (result, " Unregister non-existent table: " + std::string (non_exist_table_name));
377381
378- // Test 3: Count rows - should be exactly 1,000,000
382+ // Test 3: Count rows - should be exactly TEST_TOTAL_ROWS
379383 chdb_result * count_result = chdb_query (conn, " SELECT COUNT(*) as total_rows FROM arrowstream(test_arrow_table)" , " CSV" );
380- test_assert_row_count (count_result, 1000000 , " Count total rows" );
384+ test_assert_row_count (count_result, TEST_TOTAL_ROWS , " Count total rows" );
381385 chdb_destroy_query_result (count_result);
382386
383387 // Test 4: Sample first 5 rows - should contain id=0,1,2,3,4
@@ -387,31 +391,33 @@ void test_arrow_scan(chdb_connection conn)
387391 test_assert_query_result_contains (sample_result, " 4,\" value_4\" " , " First 5 rows contain fifth row" );
388392 chdb_destroy_query_result (sample_result);
389393
390- // Test 5: Sample last 5 rows - should contain id=999999,999998,999997,999996,999995
394+ // Test 5: Sample last 5 rows - should contain id=(TEST_TOTAL_ROWS-1) to (TEST_TOTAL_ROWS-5)
391395 reset_arrow_stream (&stream);
392396 chdb_result * last_result = chdb_query (conn, " SELECT * FROM arrowstream(test_arrow_table) ORDER BY id DESC LIMIT 5" , " CSV" );
393- test_assert_query_result_contains (last_result, " 999999,\" value_999999\" " , " Last 5 rows contain last row" );
394- test_assert_query_result_contains (last_result, " 999995,\" value_999995\" " , " Last 5 rows contain fifth row" );
397+ std::string last_row_expected = std::to_string (TEST_TOTAL_ROWS - 1 ) + " ,\" value_" + std::to_string (TEST_TOTAL_ROWS - 1 ) + " \" " ;
398+ std::string fifth_last_row_expected = std::to_string (TEST_TOTAL_ROWS - 5 ) + " ,\" value_" + std::to_string (TEST_TOTAL_ROWS - 5 ) + " \" " ;
399+ test_assert_query_result_contains (last_result, last_row_expected, " Last 5 rows contain last row" );
400+ test_assert_query_result_contains (last_result, fifth_last_row_expected, " Last 5 rows contain fifth row" );
395401 chdb_destroy_query_result (last_result);
396402
397403 // Test 6: Multiple table registration tests
398- // Create second ArrowArrayStream with different data (500,000 rows )
404+ // Create second ArrowArrayStream with different data (50% of TEST_TOTAL_ROWS )
399405 struct ArrowArrayStream stream2;
400406 memset (&stream2, 0 , sizeof (stream2));
401407 auto * stream_data2 = new CustomStreamData ();
402- stream_data2->total_rows = 500000 ; // Different row count
408+ stream_data2->total_rows = TEST_TOTAL_ROWS / 2 ; // 50% of main table
403409 stream_data2->current_row = 0 ;
404410 stream2.get_schema = custom_get_schema;
405411 stream2.get_next = custom_get_next;
406412 stream2.get_last_error = custom_get_last_error;
407413 stream2.release = custom_release;
408414 stream2.private_data = stream_data2;
409415
410- // Create third ArrowArrayStream with different data (100,000 rows )
416+ // Create third ArrowArrayStream with different data (10% of TEST_TOTAL_ROWS )
411417 struct ArrowArrayStream stream3;
412418 memset (&stream3, 0 , sizeof (stream3));
413419 auto * stream_data3 = new CustomStreamData ();
414- stream_data3->total_rows = 100000 ; // Different row count
420+ stream_data3->total_rows = TEST_TOTAL_ROWS / 10 ; // 10% of main table
415421 stream_data3->current_row = 0 ;
416422 stream3.get_schema = custom_get_schema;
417423 stream3.get_next = custom_get_next;
@@ -435,17 +441,17 @@ void test_arrow_scan(chdb_connection conn)
435441 // Test 6a: Verify each table has correct row counts
436442 reset_arrow_stream (&stream);
437443 chdb_result * count1_result = chdb_query (conn, " SELECT COUNT(*) FROM arrowstream(test_arrow_table)" , " CSV" );
438- test_assert_row_count (count1_result, 1000000 , " First table row count" );
444+ test_assert_row_count (count1_result, TEST_TOTAL_ROWS , " First table row count" );
439445 chdb_destroy_query_result (count1_result);
440446
441447 reset_arrow_stream (&stream2);
442448 chdb_result * count2_result = chdb_query (conn, " SELECT COUNT(*) FROM arrowstream(test_arrow_table_2)" , " CSV" );
443- test_assert_row_count (count2_result, 500000 , " Second table row count" );
449+ test_assert_row_count (count2_result, TEST_TOTAL_ROWS / 2 , " Second table row count" );
444450 chdb_destroy_query_result (count2_result);
445451
446452 reset_arrow_stream (&stream3);
447453 chdb_result * count3_result = chdb_query (conn, " SELECT COUNT(*) FROM arrowstream(test_arrow_table_3)" , " CSV" );
448- test_assert_row_count (count3_result, 100000 , " Third table row count" );
454+ test_assert_row_count (count3_result, TEST_TOTAL_ROWS / 10 , " Third table row count" );
449455 chdb_destroy_query_result (count3_result);
450456
451457 // Test 6b: Test cross-table JOIN query
@@ -609,16 +615,16 @@ static void create_arrow_array(struct ArrowArray * array, uint64_t row_count)
609615void test_arrow_array_scan (chdb_connection conn)
610616{
611617 std::cout << " \n === Testing ArrowArray Scan Functions ===\n " ;
612- std::cout << " Data specification: 1,000,000 rows × 2 columns (id: int64, value: string)\n " ;
618+ std::cout << " Data specification: " << TEST_TOTAL_ROWS << " rows × 2 columns (id: int64, value: string)\n " ;
613619
614620 // Create ArrowSchema (reuse existing function)
615621 struct ArrowSchema schema;
616622 create_schema (&schema);
617623
618- // Create ArrowArray with 1,000,000 rows
624+ // Create ArrowArray with TEST_TOTAL_ROWS rows
619625 struct ArrowArray array;
620626 memset (&array, 0 , sizeof (array));
621- create_arrow_array (&array, 1000000 );
627+ create_arrow_array (&array, TEST_TOTAL_ROWS );
622628
623629 std::cout << " ✓ ArrowArray initialization completed\n " ;
624630 std::cout << " Starting registration with chDB...\n " ;
@@ -634,7 +640,7 @@ void test_arrow_array_scan(chdb_connection conn)
634640 test_assert_chdb_state (result, " Register ArrowArray to table: " + std::string (table_name));
635641
636642 chdb_result * count_result = chdb_query (conn, " SELECT COUNT(*) as total_rows FROM arrowstream(test_arrow_array_table)" , " CSV" );
637- test_assert_row_count (count_result, 1000000 , " Count total rows" );
643+ test_assert_row_count (count_result, TEST_TOTAL_ROWS , " Count total rows" );
638644 chdb_destroy_query_result (count_result);
639645
640646 result = chdb_arrow_unregister_table (conn, table_name);
@@ -661,27 +667,29 @@ void test_arrow_array_scan(chdb_connection conn)
661667 test_assert_chdb_state (result, " Register ArrowArray for last rows query" );
662668
663669 chdb_result * last_result = chdb_query (conn, " SELECT * FROM arrowstream(test_arrow_array_table) ORDER BY id DESC LIMIT 5" , " CSV" );
664- test_assert_query_result_contains (last_result, " 999999,\" value_999999\" " , " Last 5 rows contain last row" );
665- test_assert_query_result_contains (last_result, " 999995,\" value_999995\" " , " Last 5 rows contain fifth row" );
670+ std::string last_row_expected = std::to_string (TEST_TOTAL_ROWS - 1 ) + " ,\" value_" + std::to_string (TEST_TOTAL_ROWS - 1 ) + " \" " ;
671+ std::string fifth_last_row_expected = std::to_string (TEST_TOTAL_ROWS - 5 ) + " ,\" value_" + std::to_string (TEST_TOTAL_ROWS - 5 ) + " \" " ;
672+ test_assert_query_result_contains (last_result, last_row_expected, " Last 5 rows contain last row" );
673+ test_assert_query_result_contains (last_result, fifth_last_row_expected, " Last 5 rows contain fifth row" );
666674 chdb_destroy_query_result (last_result);
667675
668676 result = chdb_arrow_unregister_table (conn, table_name);
669677 test_assert_chdb_state (result, " Unregister ArrowArray table after last rows query" );
670678
671679 // Test 5: Independent multiple table tests
672- // Create second ArrowArray with different data (500,000 rows )
680+ // Create second ArrowArray with different data (50% of TEST_TOTAL_ROWS )
673681 struct ArrowSchema schema2;
674682 create_schema (&schema2);
675683 struct ArrowArray array2;
676684 memset (&array2, 0 , sizeof (array2));
677- create_arrow_array (&array2, 500000 );
685+ create_arrow_array (&array2, TEST_TOTAL_ROWS / 2 );
678686
679- // Create third ArrowArray with different data (100,000 rows )
687+ // Create third ArrowArray with different data (10% of TEST_TOTAL_ROWS )
680688 struct ArrowSchema schema3;
681689 create_schema (&schema3);
682690 struct ArrowArray array3;
683691 memset (&array3, 0 , sizeof (array3));
684- create_arrow_array (&array3, 100000 );
692+ create_arrow_array (&array3, TEST_TOTAL_ROWS / 10 );
685693
686694 const char * table_name2 = " test_arrow_array_table_2" ;
687695 const char * table_name3 = " test_arrow_array_table_3" ;
@@ -691,23 +699,23 @@ void test_arrow_array_scan(chdb_connection conn)
691699 chdb_arrow_schema arrow_schema3 = reinterpret_cast <chdb_arrow_schema>(&schema3);
692700 chdb_arrow_array arrow_array3 = reinterpret_cast <chdb_arrow_array>(&array3);
693701
694- // Test 5a: Register -> Query -> Unregister for second table (500K rows)
702+ // Test 5a: Register -> Query -> Unregister for second table (50% rows)
695703 result = chdb_arrow_array_scan (conn, table_name2, arrow_schema2, arrow_array2);
696704 test_assert_chdb_state (result, " Register second ArrowArray to table: " + std::string (table_name2));
697705
698706 chdb_result * count2_result = chdb_query (conn, " SELECT COUNT(*) FROM arrowstream(test_arrow_array_table_2)" , " CSV" );
699- test_assert_row_count (count2_result, 500000 , " Second array table row count" );
707+ test_assert_row_count (count2_result, TEST_TOTAL_ROWS / 2 , " Second array table row count" );
700708 chdb_destroy_query_result (count2_result);
701709
702710 result = chdb_arrow_unregister_table (conn, table_name2);
703711 test_assert_chdb_state (result, " Unregister second ArrowArray table" );
704712
705- // Test 5b: Register -> Query -> Unregister for third table (100K rows)
713+ // Test 5b: Register -> Query -> Unregister for third table (10% rows)
706714 result = chdb_arrow_array_scan (conn, table_name3, arrow_schema3, arrow_array3);
707715 test_assert_chdb_state (result, " Register third ArrowArray to table: " + std::string (table_name3));
708716
709717 chdb_result * count3_result = chdb_query (conn, " SELECT COUNT(*) FROM arrowstream(test_arrow_array_table_3)" , " CSV" );
710- test_assert_row_count (count3_result, 100000 , " Third array table row count" );
718+ test_assert_row_count (count3_result, TEST_TOTAL_ROWS / 10 , " Third array table row count" );
711719 chdb_destroy_query_result (count3_result);
712720
713721 result = chdb_arrow_unregister_table (conn, table_name3);
0 commit comments