@@ -33,56 +33,59 @@ public void RegisterTableFunctionWithOneParameter()
3333 }
3434
3535 [ Fact ]
36- public void RegisterTableFunctionWithOneParameterTwoColumns ( )
36+ public void RegisterTableFunctionWithTwoParameterTwoColumns ( )
3737 {
38- var count = 3000 ;
38+ var count = 50 ;
3939
40- Connection . RegisterTableFunction < int > ( "demo2" , ( parameters ) =>
40+ Connection . RegisterTableFunction < short , string > ( "demo2" , ( parameters ) =>
4141 {
42- var value = parameters [ 0 ] . GetValue < int > ( ) ;
42+ var start = parameters [ 0 ] . GetValue < short > ( ) ;
43+ var prefix = parameters [ 1 ] . GetValue < string > ( ) ;
4344
4445 return new TableFunction ( new List < ColumnInfo > ( )
4546 {
4647 new ColumnInfo ( "foo" , typeof ( int ) ) ,
4748 new ColumnInfo ( "bar" , typeof ( string ) ) ,
48- } , Enumerable . Range ( 0 , value ) ) ;
49+ } , Enumerable . Range ( start , count ) . Select ( index => KeyValuePair . Create ( index , prefix + index ) ) ) ;
4950 } , ( item , writers , rowIndex ) =>
5051 {
51- writers [ 0 ] . WriteValue ( ( int ) item , rowIndex ) ;
52- writers [ 1 ] . WriteValue ( $ "string{ item } ", rowIndex ) ;
52+ var pair = ( KeyValuePair < int , string > ) item ;
53+ writers [ 0 ] . WriteValue ( pair . Key , rowIndex ) ;
54+ writers [ 1 ] . WriteValue ( pair . Value , rowIndex ) ;
5355 } ) ;
5456
55- var data = Connection . Query < ( int , string ) > ( $ "SELECT * FROM demo2({ count } );") . ToList ( ) ;
57+ var data = Connection . Query < ( int , string ) > ( $ "SELECT * FROM demo2(30::SmallInt, 'DuckDB' );") . ToList ( ) ;
5658
57- data . Select ( tuple => tuple . Item1 ) . Should ( ) . BeEquivalentTo ( Enumerable . Range ( 0 , count ) ) ;
58- data . Select ( tuple => tuple . Item2 ) . Should ( ) . BeEquivalentTo ( Enumerable . Range ( 0 , count ) . Select ( i => $ "string { i } ") ) ;
59+ data . Select ( tuple => tuple . Item1 ) . Should ( ) . BeEquivalentTo ( Enumerable . Range ( 30 , count ) ) ;
60+ data . Select ( tuple => tuple . Item2 ) . Should ( ) . BeEquivalentTo ( Enumerable . Range ( 30 , count ) . Select ( i => $ "DuckDB { i } ") ) ;
5961 }
6062
6163 [ Fact ]
62- public void RegisterTableFunctionWithTwoParameterTwoColumns ( )
64+ public void RegisterTableFunctionWithThreeParameters ( )
6365 {
64- var count = 50 ;
66+ var count = 30 ;
67+ var startDate = new DateTime ( 2024 , 11 , 6 ) ;
68+ var minutesParam = 10 ;
69+ var secondsParam = 2.5 ;
6570
66- Connection . RegisterTableFunction < short , string > ( "demo3" , ( parameters ) =>
71+ Connection . RegisterTableFunction < DateTime , long , double > ( "demo3" , ( parameters ) =>
6772 {
68- var start = parameters [ 0 ] . GetValue < short > ( ) ;
69- var prefix = parameters [ 1 ] . GetValue < string > ( ) ;
73+ var date = parameters [ 0 ] . GetValue < DateTime > ( ) ;
74+ var minutes = parameters [ 1 ] . GetValue < long > ( ) ;
75+ var seconds = parameters [ 2 ] . GetValue < double > ( ) ;
7076
7177 return new TableFunction ( new List < ColumnInfo > ( )
7278 {
73- new ColumnInfo ( "foo" , typeof ( int ) ) ,
74- new ColumnInfo ( "bar" , typeof ( string ) ) ,
75- } , Enumerable . Range ( start , count ) . Select ( index => KeyValuePair . Create ( index , prefix + index ) ) ) ;
79+ new ColumnInfo ( "foo" , typeof ( DateTime ) ) ,
80+ } , Enumerable . Range ( 0 , count ) . Select ( i => date . AddDays ( i ) . AddMinutes ( minutes ) . AddSeconds ( seconds ) ) ) ;
7681 } , ( item , writers , rowIndex ) =>
7782 {
78- var pair = ( KeyValuePair < int , string > ) item ;
79- writers [ 0 ] . WriteValue ( pair . Key , rowIndex ) ;
80- writers [ 1 ] . WriteValue ( pair . Value , rowIndex ) ;
83+ writers [ 0 ] . WriteValue ( ( DateTime ) item , rowIndex ) ;
8184 } ) ;
8285
83- var data = Connection . Query < ( int , string ) > ( $ "SELECT * FROM demo3(30::SmallInt, 'DuckDB' );") . ToList ( ) ;
86+ var data = Connection . Query < DateTime > ( $ "SELECT * FROM demo3('2024-11-06'::TIMESTAMP, 10, 2.5 );") . ToList ( ) ;
8487
85- data . Select ( tuple => tuple . Item1 ) . Should ( ) . BeEquivalentTo ( Enumerable . Range ( 30 , count ) ) ;
86- data . Select ( tuple => tuple . Item2 ) . Should ( ) . BeEquivalentTo ( Enumerable . Range ( 30 , count ) . Select ( i => $ "DuckDB { i } " ) ) ;
88+ var dateTimes = Enumerable . Range ( 0 , count ) . Select ( i => startDate . AddDays ( i ) . AddMinutes ( minutesParam ) . AddSeconds ( secondsParam ) ) ;
89+ data . Select ( dateTime => dateTime ) . Should ( ) . BeEquivalentTo ( dateTimes ) ;
8790 }
8891}
0 commit comments