saikrishna1-bidgely commented on code in PR #4908:
URL: https://github.com/apache/arrow-datafusion/pull/4908#discussion_r1083343498
##########
datafusion/core/src/execution/context.rs:
##########
@@ -1035,6 +1037,80 @@ impl FunctionRegistry for SessionContext {
}
}
+#[async_trait]
+/// Trat implementing `read_csv`, `read_avro`, `read_json` and `read_parquet`.
+/// We implement these functions for `String`, `&str`, `Vec<&str>` and
`Vec<String>`.
+/// This way these functions can accept either a single path or a list of
paths.
+///
+/// An example of using these methods is given below.
+/// ```rust
+/// let ctx = SessionContext::default();
+/// ctx.read_csv("s3://bucket-name/key/")
+/// ctx.read_csv(vec!["s3://bucket-name/key/", "s3://bucket-name/key2/",
"s3://another-bucket-name/key/"])
+/// ```
+pub trait Reader<'a, T>: Sized {
+
+ /// Creates a [`DataFrame`] for reading a CSV data source.
+ ///
+ /// For more control such as reading multiple files, you can use
+ /// [`read_table`](Self::read_table) with a [`ListingTable`].
+ async fn read_csv(&self, table_paths: T, options: CsvReadOptions<'_>) ->
Result<DataFrame>
+ where 'a:'async_trait
+ ;
+}
+
+#[async_trait]
+impl<'a> Reader<'a, &'a str> for SessionContext {
+ async fn read_csv(&self, table_path: &'a str, options: CsvReadOptions<'_>)
-> Result<DataFrame> {
+ self.read_csv(vec![table_path], options).await
+ }
+}
+
+#[async_trait]
+impl<'a> Reader<'a, String> for SessionContext {
+ async fn read_csv(&self, table_path: String, options: CsvReadOptions<'_>)
-> Result<DataFrame> {
+ self.read_csv(vec![table_path.as_str()], options).await
+ }
+}
+
+#[async_trait]
+impl<'a> Reader<'a, Vec<&'a str>> for SessionContext {
+ async fn read_csv(&self, table_paths: Vec<&'a str>, options:
CsvReadOptions<'_>) -> Result<DataFrame> {
Review Comment:
Should we implement a trait `ReadOptions`?
```rust
trait ReadOptions {
fn to_listing_options(&self, target_partitions: usize) -> ListingOptions;
fn get_resolved_schema(&self) -> Result<SchemaRef>;
}
```
`CsvReadOptions` and other will implement this trait. This way, we can avoid
repeating this code for other methods.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]