You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "shruti2522 (via GitHub)" <gi...@apache.org> on 2025/03/15 21:25:01 UTC

[PR] Migrate user_defined tests to insta [datafusion]

shruti2522 opened a new pull request, #15255:
URL: https://github.com/apache/datafusion/pull/15255

   ## 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.
   -->
   
   - Closes #15247 .
   
   ## 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?
   migrate tests in `datafusion/core/tests/user_defined` to insta
   
   <!--
   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 these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## 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.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #15255:
URL: https://github.com/apache/datafusion/pull/15255


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#discussion_r2000955601


##########
datafusion/core/tests/user_defined/expr_planner.rs:
##########
@@ -73,52 +73,62 @@ async fn plan_and_collect(sql: &str) -> Result<Vec<RecordBatch>> {
     ctx.sql(sql).await?.collect().await
 }
 
+fn fmt_batches(batches: &[RecordBatch]) -> String {
+    use arrow::util::pretty::pretty_format_batches;
+    match pretty_format_batches(batches) {
+        Ok(formatted) => formatted.to_string(),
+        Err(e) => format!("Error formatting record batches: {}", e),
+    }
+}

Review Comment:
   can we use `batches_to_string` for that? 



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#issuecomment-2727315704

   cc @blaginin 


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#issuecomment-2727325045

   Hey! I’m a bit worried that now to understand the test you’ll need to look into two places: open the test file and also search for the snapshot file… that’s why in the example pr (https://github.com/apache/datafusion/pull/15165) I used inline snapshots. 
   
   do you think we should use the same approach here?


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#discussion_r2000967075


##########
datafusion/core/tests/user_defined/user_defined_window_functions.rs:
##########
@@ -57,30 +57,38 @@ const BOUNDED_WINDOW_QUERY:  &str  =
      odd_counter(val) OVER (PARTITION BY x ORDER BY y ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) \
      from t ORDER BY x, y";
 
-/// Test to show the contents of the setup
+fn fmt_batches(batches: &[RecordBatch]) -> String {
+    use arrow::util::pretty::pretty_format_batches;
+    match pretty_format_batches(batches) {
+        Ok(formatted) => formatted.to_string(),
+        Err(e) => format!("Error formatting record batches: {}", e),
+    }
+}
+

Review Comment:
   i think this can be removed as well



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#discussion_r2001657619


##########
datafusion/core/tests/user_defined/user_defined_table_functions.rs:
##########
@@ -34,11 +34,19 @@ use datafusion::physical_plan::{collect, ExecutionPlan};
 use datafusion::prelude::SessionContext;
 use datafusion_catalog::Session;
 use datafusion_catalog::TableFunctionImpl;
-use datafusion_common::{assert_batches_eq, DFSchema, ScalarValue};
+use datafusion_common::{DFSchema, ScalarValue};
 use datafusion_expr::{EmptyRelation, Expr, LogicalPlan, Projection, TableType};
 
 use async_trait::async_trait;
 
+fn fmt_batches(batches: &[RecordBatch]) -> String {
+    use arrow::util::pretty::pretty_format_batches;
+    match pretty_format_batches(batches) {
+        Ok(formatted) => formatted.to_string(),
+        Err(e) => format!("Error formatting record batches: {}", e),
+    }
+}
+

Review Comment:
   This is a good call -- I took the liberty of pushing a commit to make the change.



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "shruti2522 (via GitHub)" <gi...@apache.org>.
shruti2522 commented on PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#issuecomment-2730590045

   > > I tried allow_duplicates!(), but it gets a bit tricky with async functions
   > 
   > Can you please explain more on this? I tried modifying _async_ `run_and_compare_query` and this worked for me:
   > 
   > <img alt="image" width="789" src="https://private-user-images.githubusercontent.com/19199204/423473541-0589862a-f891-453f-aa1d-e3af3a77aaa0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDIyMzg4NjYsIm5iZiI6MTc0MjIzODU2NiwicGF0aCI6Ii8xOTE5OTIwNC80MjM0NzM1NDEtMDU4OTg2MmEtZjg5MS00NTNmLWFhMWQtZTNhZjNhNzdhYWEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAzMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMzE3VDE5MDkyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU1MjMzNTBhYTRhMTgwMTg0ZWJjY2MzNGNjNmRjZDIzM2RiYTJjNDFiODVkYzNjNDgzMWRjMTZlMWU1Zjc2MTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.qkH-1A7Ps5aPDHRAlXn7vrZJ8YhkbX68oB1V4E3AxbQ">
   > > So, I used snapshot files instead because they make it much easier to run multiple tests using the same query fn, also it makes it much easier to update expected outputs in the future and eliminates the use of #[rustfmt::skip] in some places.
   > 
   > Just to give a bit of context, we had a discussion about inline / file snapshots here: [#13672 (comment)](https://github.com/apache/datafusion/pull/13672#discussion_r1894531818) and [#13672 (comment)](https://github.com/apache/datafusion/pull/13672#discussion_r1894532385).
   > 
   > To me personally, it feels like we can use snapshot files, but the snapshot itself should give enough information to understand the context. For example, in CLI, you can see [program input and tests](https://github.com/apache/datafusion/blob/87eec43856a5d8cefef24d1ff85d375d2b58d8c2/datafusion-cli/tests/snapshots/cli_format%40csv.snap#L6-L9), and the snapshot file itself doesn't contain a lot of logic. Here I'm not sure if that's the case for ALL the test fixtures? Maybe some of them can be inline?
   
   Yes, it worked. I was using` insta::allow_duplicates!` like a function call:
   ```rust
    insta::allow_duplicates!(|| {
           insta::with_settings!({
               description => description,
           }, {
               insta::assert_snapshot!(actual, @r###"
               +-------------+---------+
               | customer_id | revenue |
               +-------------+---------+
               | paul        | 300     |
               | jorge       | 200     |
               | andy        | 150     |
               +-------------+---------+
               "###);
           });
       })();
   ```
   On changing it to this it worked  
   ```rust
    insta::allow_duplicates! {
           insta::with_settings!({
               description => description,
           }, {
               insta::assert_snapshot!(actual, @r###"
               +-------------+---------+
               | customer_id | revenue |
               +-------------+---------+
               | paul        | 300     |
               | jorge       | 200     |
               | andy        | 150     |
               +-------------+---------+
           "###);
           });
       }
   ```
   Thanks a lot @blaginin and @alamb ❤️


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#issuecomment-2729413005

   > I tried allow_duplicates!(), but it gets a bit tricky with async functions
   
   Can you please explain more on this? I tried modifying _async_ `run_and_compare_query` and this worked for me: 
   
   <img width="789" alt="image" src="https://github.com/user-attachments/assets/0589862a-f891-453f-aa1d-e3af3a77aaa0" />
   
   > So, I used snapshot files instead because they make it much easier to run multiple tests using the same query fn, also it makes it much easier to update expected outputs in the future and eliminates the use of #[rustfmt::skip] in some places.
   
   Just to give a bit of context, we had a discussion about inline / file snapshots here: https://github.com/apache/datafusion/pull/13672#discussion_r1894531818 and https://github.com/apache/datafusion/pull/13672#discussion_r1894532385. 
   
   To me personally, it feels like we can use snapshot files, but the snapshot itself should give enough information to understand the context. For example, in CLI, you can see [program input and tests](https://github.com/apache/datafusion/blob/87eec43856a5d8cefef24d1ff85d375d2b58d8c2/datafusion-cli/tests/snapshots/cli_format%40csv.snap#L6-L9), and the snapshot file itself doesn't contain a lot of logic.
   
   


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#issuecomment-2734485532

   Thanks @shruti2522  and @blaginin  🙏 


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "shruti2522 (via GitHub)" <gi...@apache.org>.
shruti2522 commented on PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#issuecomment-2727447740

   > Hey! I’m a bit worried that now to understand the test you’ll need to look into two places: open the test file and also search for the snapshot file… that’s why in the example pr (#15165) I used inline snapshots.
   > 
   > do you think we should use the same approach here?
   
   Hey @blaginin, you are right about this, at first I tried implementing the inline snapshots only, but I ran into errors while running tests for `run_and_compare_query` in `user_defined/user_defined_plan.rs`, since multiple tests are using it ,only the first one works because insta doesn't allow duplicate inline snapshots by default. I tried `allow_duplicates!()`, but it gets a bit tricky with async functions. So, I used snapshot files instead because they make it much easier to run multiple tests using the same query fn, also it makes it much easier to update expected outputs in the future. Maybe we can discuss some alternative approach to implement inline snapshots 🤔


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#issuecomment-2727315961

   Thanks @shruti2522 !


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Migrate user_defined tests to insta [datafusion]

Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #15255:
URL: https://github.com/apache/datafusion/pull/15255#discussion_r2000968071


##########
datafusion/core/tests/user_defined/user_defined_table_functions.rs:
##########
@@ -34,11 +34,19 @@ use datafusion::physical_plan::{collect, ExecutionPlan};
 use datafusion::prelude::SessionContext;
 use datafusion_catalog::Session;
 use datafusion_catalog::TableFunctionImpl;
-use datafusion_common::{assert_batches_eq, DFSchema, ScalarValue};
+use datafusion_common::{DFSchema, ScalarValue};
 use datafusion_expr::{EmptyRelation, Expr, LogicalPlan, Projection, TableType};
 
 use async_trait::async_trait;
 
+fn fmt_batches(batches: &[RecordBatch]) -> String {
+    use arrow::util::pretty::pretty_format_batches;
+    match pretty_format_batches(batches) {
+        Ok(formatted) => formatted.to_string(),
+        Err(e) => format!("Error formatting record batches: {}", e),
+    }
+}
+

Review Comment:
   and this



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org