jiayuasu commented on code in PR #1034:
URL: https://github.com/apache/sedona-db/pull/1034#discussion_r3556791945


##########
python/sedonadb/src/context.rs:
##########
@@ -165,6 +166,46 @@ impl InternalContext {
         Ok(InternalDataFrame::new(df, self.runtime.clone()))
     }
 
+    pub fn read_csv<'py>(
+        &self,
+        py: Python<'py>,
+        table_paths: Vec<String>,
+        has_header: bool,
+        delimiter: &str,
+    ) -> Result<InternalDataFrame, PySedonaError> {

Review Comment:
   Done in 79f62d7. Moved the implementation to `SedonaContext::read_csv` in 
rust/sedona, mirroring `read_parquet`: it registers the object store via 
`ensure_object_store_registered_with_options` before reading, so 
`s3://`/`gs://` paths with `aws.*`/`gcs.*` options now work (the previous 
version called DataFusion's context directly and skipped that). Options cross 
the PyO3 boundary as `HashMap<String, PyAny>`, shared with read_parquet via a 
`stringify_options` helper — so they unify with the future R path and auto-flow 
through `read()`. I kept it a dedicated `read_csv`/`read_json` for now rather 
than the generic `file_format_factory` resolution; happy to do that extraction 
as a follow-up if you'd like.



##########
python/sedonadb/src/context.rs:
##########
@@ -165,6 +166,46 @@ impl InternalContext {
         Ok(InternalDataFrame::new(df, self.runtime.clone()))
     }
 
+    pub fn read_csv<'py>(
+        &self,
+        py: Python<'py>,
+        table_paths: Vec<String>,
+        has_header: bool,
+        delimiter: &str,
+    ) -> Result<InternalDataFrame, PySedonaError> {
+        let bytes = delimiter.as_bytes();
+        if bytes.len() != 1 {
+            return Err(PySedonaError::SedonaPython(format!(
+                "delimiter must be a single byte, got {delimiter:?}"
+            )));
+        }
+        let options = CsvReadOptions::new()
+            .has_header(has_header)
+            .delimiter(bytes[0]);
+        let df = wait_for_future(
+            py,
+            &self.runtime,
+            self.inner.ctx.read_csv(table_paths, options),
+        )??;
+        Ok(InternalDataFrame::new(df, self.runtime.clone()))
+    }
+
+    pub fn read_json<'py>(
+        &self,
+        py: Python<'py>,
+        table_paths: Vec<String>,
+    ) -> Result<InternalDataFrame, PySedonaError> {
+        // DataFusion reads newline-delimited JSON (one object per line).

Review Comment:
   Same treatment — `SedonaContext::read_json` in rust/sedona registers the 
object store and takes the options map.



##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -289,6 +289,71 @@ def read_parquet(
             partitioning=partitioning,
         )
 
+    def read_csv(
+        self,
+        table_paths: Union[str, Path, Iterable[str]],
+        *,
+        has_header: bool = True,
+        delimiter: str = ",",
+    ) -> DataFrame:

Review Comment:
   Agreed — dropped the top-level `sd.read_csv`/`sd.read_json`. The entry 
points are now the generic `sd.read(...)` (guesses `.csv`/`.json` by extension) 
and the namespace `sd.read.csv` / `sd.read.json` for format-specific options.



##########
python/sedonadb/tests/io/test_read_csv_json.py:
##########
@@ -0,0 +1,105 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pandas as pd
+import pandas.testing as pdt
+import pytest
+
+
+def _write(path, text):
+    path.write_text(text)
+    return str(path)

Review Comment:
   Switched the tests (and the read.csv/read.json doctests) to `with 
tempfile.TemporaryDirectory() as td` to match the rest of the suite.



-- 
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]

Reply via email to