Skip to content

Commit fb8818d

Browse files
committed
Change to Box<Reader + 'static>
1 parent 6de5c12 commit fb8818d

File tree

6 files changed

+58
-55
lines changed

6 files changed

+58
-55
lines changed

rust/core/src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub trait Connection: Optionable<Option = OptionConnection> {
164164
fn get_info(
165165
&self,
166166
codes: Option<HashSet<options::InfoCode>>,
167-
) -> Result<impl RecordBatchReader + Send + '_>;
167+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>>;
168168

169169
/// Get a hierarchical view of all catalogs, database schemas, tables, and
170170
/// columns.
@@ -272,7 +272,7 @@ pub trait Connection: Optionable<Option = OptionConnection> {
272272
table_name: Option<&str>,
273273
table_type: Option<Vec<&str>>,
274274
column_name: Option<&str>,
275-
) -> Result<impl RecordBatchReader + Send + '_>;
275+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>>;
276276

277277
/// Get the Arrow schema of a table.
278278
///
@@ -297,7 +297,7 @@ pub trait Connection: Optionable<Option = OptionConnection> {
297297
/// Field Name | Field Type
298298
/// ---------------|--------------
299299
/// table_type | utf8 not null
300-
fn get_table_types(&self) -> Result<impl RecordBatchReader + Send + '_>;
300+
fn get_table_types(&self) -> Result<Box<dyn RecordBatchReader + Send + 'static>>;
301301

302302
/// Get the names of statistics specific to this driver.
303303
///
@@ -312,7 +312,7 @@ pub trait Connection: Optionable<Option = OptionConnection> {
312312
///
313313
/// # Since
314314
/// ADBC API revision 1.1.0
315-
fn get_statistic_names(&self) -> Result<impl RecordBatchReader + Send + '_>;
315+
fn get_statistic_names(&self) -> Result<Box<dyn RecordBatchReader + Send + 'static>>;
316316

317317
/// Get statistics about the data distribution of table(s).
318318
///
@@ -378,7 +378,7 @@ pub trait Connection: Optionable<Option = OptionConnection> {
378378
db_schema: Option<&str>,
379379
table_name: Option<&str>,
380380
approximate: bool,
381-
) -> Result<impl RecordBatchReader + Send + '_>;
381+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>>;
382382

383383
/// Commit any pending transactions. Only used if autocommit is disabled.
384384
///
@@ -400,7 +400,7 @@ pub trait Connection: Optionable<Option = OptionConnection> {
400400
fn read_partition(
401401
&self,
402402
partition: impl AsRef<[u8]>,
403-
) -> Result<impl RecordBatchReader + Send + '_>;
403+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>>;
404404
}
405405

406406
/// A handle to an ADBC statement.
@@ -433,10 +433,7 @@ pub trait Statement: Optionable<Option = OptionStatement> {
433433
/// Execute a statement and get the results.
434434
///
435435
/// This invalidates any prior result sets.
436-
// TODO(alexandreyc): is the Send bound absolutely necessary? same question
437-
// for all methods that return an impl RecordBatchReader
438-
// See: https://github.com/apache/arrow-adbc/pull/1725#discussion_r1567748242
439-
fn execute(&mut self) -> Result<impl RecordBatchReader + Send + '_>;
436+
fn execute(&mut self) -> Result<Box<dyn RecordBatchReader + Send + 'static>>;
440437

441438
/// Execute a statement that doesn’t have a result set and get the number
442439
/// of affected rows.

rust/driver/datafusion/src/lib.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ impl Connection for DataFusionConnection {
742742
fn get_info(
743743
&self,
744744
codes: Option<std::collections::HashSet<adbc_core::options::InfoCode>>,
745-
) -> Result<impl RecordBatchReader + Send + '_> {
745+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
746746
let mut get_info_builder = GetInfoBuilder::new();
747747

748748
codes.unwrap().into_iter().for_each(|f| match f {
@@ -755,7 +755,7 @@ impl Connection for DataFusionConnection {
755755

756756
let batch = get_info_builder.finish()?;
757757
let reader = SingleBatchReader::new(batch);
758-
Ok(reader)
758+
Ok(Box::new(reader))
759759
}
760760

761761
fn get_objects(
@@ -766,10 +766,10 @@ impl Connection for DataFusionConnection {
766766
_table_name: Option<&str>,
767767
_table_type: Option<Vec<&str>>,
768768
_column_name: Option<&str>,
769-
) -> Result<impl RecordBatchReader + Send + '_> {
769+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
770770
let batch = GetObjectsBuilder::new().build(&self.runtime, &self.ctx, &depth)?;
771771
let reader = SingleBatchReader::new(batch);
772-
Ok(reader)
772+
Ok(Box::new(reader))
773773
}
774774

775775
fn get_table_schema(
@@ -781,11 +781,11 @@ impl Connection for DataFusionConnection {
781781
todo!()
782782
}
783783

784-
fn get_table_types(&self) -> Result<SingleBatchReader> {
784+
fn get_table_types(&self) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
785785
todo!()
786786
}
787787

788-
fn get_statistic_names(&self) -> Result<SingleBatchReader> {
788+
fn get_statistic_names(&self) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
789789
todo!()
790790
}
791791

@@ -795,7 +795,7 @@ impl Connection for DataFusionConnection {
795795
_db_schema: Option<&str>,
796796
_table_name: Option<&str>,
797797
_approximate: bool,
798-
) -> Result<SingleBatchReader> {
798+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
799799
todo!()
800800
}
801801

@@ -807,7 +807,10 @@ impl Connection for DataFusionConnection {
807807
todo!()
808808
}
809809

810-
fn read_partition(&self, _partition: impl AsRef<[u8]>) -> Result<SingleBatchReader> {
810+
fn read_partition(
811+
&self,
812+
_partition: impl AsRef<[u8]>,
813+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
811814
todo!()
812815
}
813816
}
@@ -901,7 +904,7 @@ impl Statement for DataFusionStatement {
901904
todo!()
902905
}
903906

904-
fn execute(&mut self) -> Result<impl RecordBatchReader + Send + '_> {
907+
fn execute(&mut self) -> Result<Box<dyn RecordBatchReader + Send>> {
905908
self.runtime.block_on(async {
906909
let df = if self.sql_query.is_some() {
907910
self.ctx
@@ -916,7 +919,7 @@ impl Statement for DataFusionStatement {
916919
self.ctx.execute_logical_plan(plan).await.unwrap()
917920
};
918921

919-
Ok(DataFusionReader::new(df).await)
922+
Ok(Box::new(DataFusionReader::new(df).await) as Box<dyn RecordBatchReader + Send>)
920923
})
921924
}
922925

rust/driver/dummy/src/lib.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ impl Connection for DummyConnection {
310310
Ok(())
311311
}
312312

313-
fn get_info(&self, _codes: Option<HashSet<InfoCode>>) -> Result<impl RecordBatchReader> {
313+
fn get_info(
314+
&self,
315+
_codes: Option<HashSet<InfoCode>>,
316+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
314317
let string_value_array = StringArray::from(vec!["MyVendorName"]);
315318
let bool_value_array = BooleanArray::from(vec![true]);
316319
let int64_value_array = Int64Array::from(vec![42]);
@@ -407,7 +410,7 @@ impl Connection for DummyConnection {
407410
vec![Arc::new(name_array), Arc::new(value_array)],
408411
)?;
409412
let reader = SingleBatchReader::new(batch);
410-
Ok(reader)
413+
Ok(Box::new(reader))
411414
}
412415

413416
fn get_objects(
@@ -418,7 +421,7 @@ impl Connection for DummyConnection {
418421
_table_name: Option<&str>,
419422
_table_type: Option<Vec<&str>>,
420423
_column_name: Option<&str>,
421-
) -> Result<impl RecordBatchReader + Send + '_> {
424+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
422425
let constraint_column_usage_array_inner = StructArray::from(vec![
423426
(
424427
Arc::new(Field::new("fk_catalog", DataType::Utf8, true)),
@@ -645,7 +648,7 @@ impl Connection for DummyConnection {
645648
],
646649
)?;
647650
let reader = SingleBatchReader::new(batch);
648-
Ok(reader)
651+
Ok(Box::new(reader))
649652
}
650653

651654
fn get_statistics(
@@ -654,7 +657,7 @@ impl Connection for DummyConnection {
654657
_db_schema: Option<&str>,
655658
_table_name: Option<&str>,
656659
_approximate: bool,
657-
) -> Result<impl RecordBatchReader + Send + '_> {
660+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
658661
let statistic_value_int64_array = Int64Array::from(Vec::<i64>::new());
659662
let statistic_value_uint64_array = UInt64Array::from(vec![42]);
660663
let statistic_value_float64_array = Float64Array::from(Vec::<f64>::new());
@@ -759,18 +762,18 @@ impl Connection for DummyConnection {
759762
)?;
760763

761764
let reader = SingleBatchReader::new(batch);
762-
Ok(reader)
765+
Ok(Box::new(reader))
763766
}
764767

765-
fn get_statistic_names(&self) -> Result<impl RecordBatchReader + Send + '_> {
768+
fn get_statistic_names(&self) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
766769
let name_array = StringArray::from(vec!["sum", "min", "max"]);
767770
let key_array = Int16Array::from(vec![0, 1, 2]);
768771
let batch = RecordBatch::try_new(
769772
schemas::GET_STATISTIC_NAMES_SCHEMA.clone(),
770773
vec![Arc::new(name_array), Arc::new(key_array)],
771774
)?;
772775
let reader = SingleBatchReader::new(batch);
773-
Ok(reader)
776+
Ok(Box::new(reader))
774777
}
775778

776779
fn get_table_schema(
@@ -792,20 +795,20 @@ impl Connection for DummyConnection {
792795
}
793796
}
794797

795-
fn get_table_types(&self) -> Result<impl RecordBatchReader + Send + '_> {
798+
fn get_table_types(&self) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
796799
let array = Arc::new(StringArray::from(vec!["table", "view"]));
797800
let batch = RecordBatch::try_new(schemas::GET_TABLE_TYPES_SCHEMA.clone(), vec![array])?;
798801
let reader = SingleBatchReader::new(batch);
799-
Ok(reader)
802+
Ok(Box::new(reader))
800803
}
801804

802805
fn read_partition(
803806
&self,
804807
_partition: impl AsRef<[u8]>,
805-
) -> Result<impl RecordBatchReader + Send + '_> {
808+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
806809
let batch = get_table_data();
807810
let reader = SingleBatchReader::new(batch);
808-
Ok(reader)
811+
Ok(Box::new(reader))
809812
}
810813

811814
fn rollback(&mut self) -> Result<()> {
@@ -855,11 +858,11 @@ impl Statement for DummyStatement {
855858
Ok(())
856859
}
857860

858-
fn execute(&mut self) -> Result<impl RecordBatchReader + Send + '_> {
861+
fn execute(&mut self) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
859862
maybe_panic("StatementExecuteQuery");
860863
let batch = get_table_data();
861864
let reader = SingleBatchReader::new(batch);
862-
Ok(reader)
865+
Ok(Box::new(reader))
863866
}
864867

865868
fn execute_partitions(&mut self) -> Result<PartitionedResult> {

rust/driver/snowflake/src/connection.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl adbc_core::Connection for Connection {
7777
fn get_info(
7878
&self,
7979
codes: Option<HashSet<InfoCode>>,
80-
) -> Result<impl RecordBatchReader + Send + '_> {
80+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
8181
self.0.get_info(codes)
8282
}
8383

@@ -89,7 +89,7 @@ impl adbc_core::Connection for Connection {
8989
table_name: Option<&str>,
9090
table_type: Option<Vec<&str>>,
9191
column_name: Option<&str>,
92-
) -> Result<impl RecordBatchReader + Send + '_> {
92+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
9393
self.0.get_objects(
9494
depth,
9595
catalog,
@@ -109,11 +109,11 @@ impl adbc_core::Connection for Connection {
109109
self.0.get_table_schema(catalog, db_schema, table_name)
110110
}
111111

112-
fn get_table_types(&self) -> Result<impl RecordBatchReader + Send + '_> {
112+
fn get_table_types(&self) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
113113
self.0.get_table_types()
114114
}
115115

116-
fn get_statistic_names(&self) -> Result<impl RecordBatchReader + Send + '_> {
116+
fn get_statistic_names(&self) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
117117
self.0.get_statistic_names()
118118
}
119119

@@ -123,7 +123,7 @@ impl adbc_core::Connection for Connection {
123123
db_schema: Option<&str>,
124124
table_name: Option<&str>,
125125
approximate: bool,
126-
) -> Result<impl RecordBatchReader + Send + '_> {
126+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
127127
self.0
128128
.get_statistics(catalog, db_schema, table_name, approximate)
129129
}
@@ -139,7 +139,7 @@ impl adbc_core::Connection for Connection {
139139
fn read_partition(
140140
&self,
141141
partition: impl AsRef<[u8]>,
142-
) -> Result<impl RecordBatchReader + Send + '_> {
142+
) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
143143
self.0.read_partition(partition)
144144
}
145145
}

rust/driver/snowflake/src/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl adbc_core::Statement for Statement {
6464
self.0.bind_stream(reader)
6565
}
6666

67-
fn execute(&mut self) -> Result<impl RecordBatchReader + Send> {
67+
fn execute(&mut self) -> Result<Box<dyn RecordBatchReader + Send + 'static>> {
6868
self.0.execute()
6969
}
7070

0 commit comments

Comments
 (0)