@@ -6,10 +6,11 @@ use convergence::protocol_ext::DataRowBatch;
66use convergence:: server:: { self , BindOptions } ;
77use convergence:: sqlparser:: ast:: Statement ;
88use convergence_arrow:: table:: { record_batch_to_rows, schema_to_field_desc} ;
9- use datafusion:: arrow:: array:: { ArrayRef , Date32Array , Float32Array , Int32Array , StringArray , StringViewArray , TimestampSecondArray } ;
9+ use datafusion:: arrow:: array:: { ArrayRef , Date32Array , Decimal128Array , Float32Array , Int32Array , StringArray , StringViewArray , TimestampSecondArray } ;
1010use datafusion:: arrow:: datatypes:: { DataType , Field , Schema , TimeUnit } ;
1111use datafusion:: arrow:: record_batch:: RecordBatch ;
1212use std:: sync:: Arc ;
13+ use rust_decimal:: Decimal ;
1314use tokio_postgres:: { connect, NoTls } ;
1415
1516struct ArrowPortal {
@@ -31,6 +32,7 @@ impl ArrowEngine {
3132 fn new ( ) -> Self {
3233 let int_col = Arc :: new ( Int32Array :: from ( vec ! [ 1 , 2 , 3 ] ) ) as ArrayRef ;
3334 let float_col = Arc :: new ( Float32Array :: from ( vec ! [ 1.5 , 2.5 , 3.5 ] ) ) as ArrayRef ;
35+ let decimal_col = Arc :: new ( Decimal128Array :: from ( vec ! [ 11 , 22 , 33 ] ) . with_precision_and_scale ( 2 , 0 ) . unwrap ( ) ) as ArrayRef ;
3436 let string_col = Arc :: new ( StringArray :: from ( vec ! [ "a" , "b" , "c" ] ) ) as ArrayRef ;
3537 let string_view_col = Arc :: new ( StringViewArray :: from ( vec ! [ "aa" , "bb" , "cc" ] ) ) as ArrayRef ;
3638 let ts_col = Arc :: new ( TimestampSecondArray :: from ( vec ! [ 1577836800 , 1580515200 , 1583020800 ] ) ) as ArrayRef ;
@@ -39,14 +41,15 @@ impl ArrowEngine {
3941 let schema = Schema :: new ( vec ! [
4042 Field :: new( "int_col" , DataType :: Int32 , true ) ,
4143 Field :: new( "float_col" , DataType :: Float32 , true ) ,
44+ Field :: new( "decimal_col" , DataType :: Decimal128 ( 2 , 0 ) , true ) ,
4245 Field :: new( "string_col" , DataType :: Utf8 , true ) ,
4346 Field :: new( "string_view_col" , DataType :: Utf8View , true ) ,
4447 Field :: new( "ts_col" , DataType :: Timestamp ( TimeUnit :: Second , None ) , true ) ,
4548 Field :: new( "date_col" , DataType :: Date32 , true ) ,
4649 ] ) ;
4750
4851 Self {
49- batch : RecordBatch :: try_new ( Arc :: new ( schema) , vec ! [ int_col, float_col, string_col, string_view_col, ts_col, date_col] )
52+ batch : RecordBatch :: try_new ( Arc :: new ( schema) , vec ! [ int_col, float_col, decimal_col , string_col, string_view_col, ts_col, date_col] )
5053 . expect ( "failed to create batch" ) ,
5154 }
5255 }
@@ -91,8 +94,8 @@ async fn basic_data_types() {
9194 let rows = client. query ( "select 1" , & [ ] ) . await . unwrap ( ) ;
9295 let get_row = |idx : usize | {
9396 let row = & rows[ idx] ;
94- let cols: ( i32 , f32 , & str , & str , NaiveDateTime , NaiveDate ) =
95- ( row. get ( 0 ) , row. get ( 1 ) , row. get ( 2 ) , row. get ( 3 ) , row. get ( 4 ) , row. get ( 5 ) ) ;
97+ let cols: ( i32 , f32 , Decimal , & str , & str , NaiveDateTime , NaiveDate ) =
98+ ( row. get ( 0 ) , row. get ( 1 ) , row. get ( 2 ) , row. get ( 3 ) , row. get ( 4 ) , row. get ( 5 ) , row . get ( 6 ) ) ;
9699 cols
97100 } ;
98101
@@ -101,6 +104,7 @@ async fn basic_data_types() {
101104 (
102105 1 ,
103106 1.5 ,
107+ Decimal :: from( 11 ) ,
104108 "a" ,
105109 "aa" ,
106110 NaiveDate :: from_ymd_opt( 2020 , 1 , 1 )
@@ -115,6 +119,7 @@ async fn basic_data_types() {
115119 (
116120 2 ,
117121 2.5 ,
122+ Decimal :: from( 22 ) ,
118123 "b" ,
119124 "bb" ,
120125 NaiveDate :: from_ymd_opt( 2020 , 2 , 1 )
@@ -129,6 +134,7 @@ async fn basic_data_types() {
129134 (
130135 3 ,
131136 3.5 ,
137+ Decimal :: from( 33 ) ,
132138 "c" ,
133139 "cc" ,
134140 NaiveDate :: from_ymd_opt( 2020 , 3 , 1 )
0 commit comments