You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/06/08 14:47:01 UTC

[GitHub] [arrow-datafusion] kszucs opened a new pull request #524: [Python] Expose ExecutionContext.register_csv

kszucs opened a new pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524


   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Depends on #493 
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] jorgecarleitao commented on a change in pull request #524: [Python] Expose ExecutionContext.register_csv

Posted by GitBox <gi...@apache.org>.
jorgecarleitao commented on a change in pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#discussion_r647525460



##########
File path: python/src/context.rs
##########
@@ -97,6 +99,34 @@ impl ExecutionContext {
         Ok(())
     }
 
+    #[args(
+        has_header = "true",
+        delimiter = "b\",\"",
+        schema_infer_max_records = "1000",
+        file_extension = "\".csv\""
+    )]
+    fn register_csv(
+        &mut self,
+        name: &str,
+        path: &str,
+        has_header: bool,
+        delimiter: &[u8],

Review comment:
       I agree. I only learnt that the Schema and DataType have a c data interface recently. This likely requires some refactoring on the arrow-rs, as it assumes that metadata do not require a specific in-memory alignment, and yet the c data interface makes such requirement.
   




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] kszucs commented on a change in pull request #524: [Python] Expose ExecutionContext.register_csv

Posted by GitBox <gi...@apache.org>.
kszucs commented on a change in pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#discussion_r647519310



##########
File path: python/src/context.rs
##########
@@ -97,6 +99,34 @@ impl ExecutionContext {
         Ok(())
     }
 
+    #[args(
+        has_header = "true",
+        delimiter = "b\",\"",
+        schema_infer_max_records = "1000",
+        file_extension = "\".csv\""
+    )]
+    fn register_csv(
+        &mut self,
+        name: &str,
+        path: &str,
+        has_header: bool,
+        delimiter: &[u8],

Review comment:
       Here we should have a `Schema` argument exposed as well, but I noticed that FFI hasn't been implemented for `Schema` and `DataType` objects in `arrow-rs`. We should probably expose all of the `ArrowSchema` based structs there first, then convert pyarrow objects using the C interface rather than calling out to python functions (like the datatype python bindings are currently implemented).




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] codecov-commenter commented on pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#issuecomment-858047325


   # [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/524?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#524](https://codecov.io/gh/apache/arrow-datafusion/pull/524?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7438b88) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/d5bca0e350d94a1e1063bed8a0da0cb09c6e3e1c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d5bca0e) will **decrease** coverage by `0.03%`.
   > The diff coverage is `0.00%`.
   
   > :exclamation: Current head 7438b88 differs from pull request most recent head 0412a5b. Consider uploading reports for the commit 0412a5b to get more accurate results
   [![Impacted file tree graph](https://codecov.io/gh/apache/arrow-datafusion/pull/524/graphs/tree.svg?width=650&height=150&src=pr&token=JXwWBKD3D9&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/arrow-datafusion/pull/524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #524      +/-   ##
   ==========================================
   - Coverage   76.03%   76.00%   -0.04%     
   ==========================================
     Files         157      157              
     Lines       26990    27001      +11     
   ==========================================
     Hits        20521    20521              
   - Misses       6469     6480      +11     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/arrow-datafusion/pull/524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [python/src/context.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/524/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHl0aG9uL3NyYy9jb250ZXh0LnJz) | `0.00% <0.00%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/524?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/524?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [d5bca0e...0412a5b](https://codecov.io/gh/apache/arrow-datafusion/pull/524?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] kszucs commented on a change in pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
kszucs commented on a change in pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#discussion_r683442287



##########
File path: python/src/to_rust.rs
##########
@@ -111,3 +112,11 @@ pub fn to_rust_scalar(ob: &PyAny) -> PyResult<ScalarValue> {
         }
     })
 }
+
+pub fn to_rust_schema(ob: &PyAny) -> PyResult<Schema> {

Review comment:
       Copied from https://github.com/apache/arrow-rs/blob/master/arrow-pyarrow-integration-testing/src/lib.rs#L136
   
   Eventually we could add an optional module to arrow-rs where we implement the PyO3 conversion traits for `arrow-rs <-> pyarrow` interoperability for easier downstream integration. 




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb commented on pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#issuecomment-891255488


   The test appear to be failing due to https://github.com/apache/arrow-datafusion/pull/818 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb commented on pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#issuecomment-879398069


   Cool -- I am just trying to shepherd PRs that look like they got stale


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] kszucs commented on pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
kszucs commented on pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#issuecomment-893760912


   @alamb this should be good to go, though we should revisit the FFI bindings in arrow-rs and a potential `arrow-rs <-> pyarrow` bridge implemented in arrow-rs in the future.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] kszucs commented on a change in pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
kszucs commented on a change in pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#discussion_r649494483



##########
File path: python/src/context.rs
##########
@@ -97,6 +99,34 @@ impl ExecutionContext {
         Ok(())
     }
 
+    #[args(
+        has_header = "true",
+        delimiter = "b\",\"",
+        schema_infer_max_records = "1000",
+        file_extension = "\".csv\""
+    )]
+    fn register_csv(
+        &mut self,
+        name: &str,
+        path: &str,
+        has_header: bool,
+        delimiter: &[u8],

Review comment:
       We should be able to accept pyarrow.Schema objects once https://github.com/apache/arrow-rs/pull/439 gets merged.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb merged pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
alamb merged pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524


   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb commented on a change in pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#discussion_r684441579



##########
File path: python/tests/test_sql.py
##########
@@ -33,12 +33,63 @@ def test_no_table(ctx):
         ctx.sql("SELECT a FROM b").collect()
 
 
-def test_register(ctx, tmp_path):
+def test_register_csv(ctx, tmp_path):
+    path = tmp_path / "test.csv"
+
+    table = pa.Table.from_arrays(
+        [
+            [1, 2, 3, 4],
+            ["a", "b", "c", "d"],
+            [1.1, 2.2, 3.3, 4.4],
+        ],
+        names=["int", "str", "float"],
+    )
+    pa.csv.write_csv(table, path)
+
+    ctx.register_csv("csv", path)
+    ctx.register_csv("csv1", str(path))
+    ctx.register_csv(
+        "csv2",
+        path,
+        has_header=True,
+        delimiter=",",
+        schema_infer_max_records=10,
+    )
+    alternative_schema = pa.schema(
+        [
+            ("some_int", pa.int16()),
+            ("some_bytes", pa.string()),
+            ("some_floats", pa.float32()),
+        ]
+    )
+    ctx.register_csv("csv3", path, schema=alternative_schema)
+
+    assert ctx.tables() == {"csv", "csv1", "csv2", "csv3"}
+
+    for table in ["csv", "csv1", "csv2"]:
+        result = ctx.sql(f"SELECT COUNT(int) FROM {table}").collect()
+        result = pa.Table.from_batches(result)
+        assert result.to_pydict() == {"COUNT(int)": [4]}

Review comment:
       👍 




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb commented on pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#issuecomment-866829342


   ping @jorgecarleitao 


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] kszucs commented on pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
kszucs commented on pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#issuecomment-879359345


   Since https://github.com/apache/arrow-rs/pull/439 has been merged I can expose the `schema` argument as well, though we can defer that to a follow-up PR too. 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb commented on pull request #524: Expose ExecutionContext.register_csv to the python bindings

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #524:
URL: https://github.com/apache/arrow-datafusion/pull/524#issuecomment-879357118


   @jorgecarleitao  / @kszucs  -- what is the plan for this PR?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org