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 2022/04/24 17:42:26 UTC

[GitHub] [arrow-datafusion] WinkerDu opened a new pull request, #2329: move sql tests from `context.rs` to corresponding test files in `tests/sql`

WinkerDu opened a new pull request, #2329:
URL: https://github.com/apache/arrow-datafusion/pull/2329

   # 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 #2328 .
   
    # 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.  
   -->
   `datafusion/core/src/execution/context.rs` has many unmanaged test cases.
   We can move them to corresponding test files in `datafustion/core/tests/sql` for better code structure.
   
   # 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.
   -->
   move sql tests from `context.rs` to corresponding test files in `tests/sql`
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   No.
   <!--
   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@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2329: move sql tests from `context.rs` to corresponding test files in `tests/sql`

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2329:
URL: https://github.com/apache/arrow-datafusion/pull/2329#discussion_r857473769


##########
datafusion/core/tests/sql/functions.rs:
##########
@@ -357,3 +357,240 @@ async fn coalesce_mul_with_default_value() -> Result<()> {
     assert_batches_eq!(expected, &actual);
     Ok(())
 }
+
+#[tokio::test]
+async fn count_basic() -> Result<()> {

Review Comment:
   (I am working on 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@arrow.apache.org

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


[GitHub] [arrow-datafusion] WinkerDu commented on pull request #2329: move sql tests from `context.rs` to corresponding test files in `tests/sql`

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on PR #2329:
URL: https://github.com/apache/arrow-datafusion/pull/2329#issuecomment-1108307731

   Thank you ❤️  @andygrove, I think there is nothing special between test cases in `context.rs` and those in `tests/sql` since they  both use `SessionContext`, maybe it's ok to move.
   
   @alamb @yjshen @xudong963  PTAL, thank you.


-- 
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 diff in pull request #2329: move sql tests from `context.rs` to corresponding test files in `tests/sql`

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2329:
URL: https://github.com/apache/arrow-datafusion/pull/2329#discussion_r857477874


##########
datafusion/core/tests/sql/functions.rs:
##########
@@ -357,3 +357,240 @@ async fn coalesce_mul_with_default_value() -> Result<()> {
     assert_batches_eq!(expected, &actual);
     Ok(())
 }
+
+#[tokio::test]
+async fn count_basic() -> Result<()> {

Review Comment:
   https://github.com/apache/arrow-datafusion/pull/2333#



-- 
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 diff in pull request #2329: move sql tests from `context.rs` to corresponding test files in `tests/sql`

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2329:
URL: https://github.com/apache/arrow-datafusion/pull/2329#discussion_r857467165


##########
datafusion/core/tests/sql/functions.rs:
##########
@@ -357,3 +357,240 @@ async fn coalesce_mul_with_default_value() -> Result<()> {
     assert_batches_eq!(expected, &actual);
     Ok(())
 }
+
+#[tokio::test]
+async fn count_basic() -> Result<()> {

Review Comment:
   As `COUNT` and `AVG` are aggregate functions, these tests probably belong in aggregates.rs or something similar -- we can move them as a follow on PR



##########
datafusion/core/src/execution/context.rs:
##########
@@ -1663,783 +1655,48 @@ mod tests {
     }
 
     #[tokio::test]
-    async fn create_variable_expr() -> Result<()> {
-        let tmp_dir = TempDir::new()?;
-        let partition_count = 4;
-        let mut ctx = create_ctx(&tmp_dir, partition_count).await?;
-
-        let variable_provider = test::variable::SystemVar::new();
-        ctx.register_variable(VarType::System, Arc::new(variable_provider));
-        let variable_provider = test::variable::UserDefinedVar::new();
-        ctx.register_variable(VarType::UserDefined, Arc::new(variable_provider));
-
-        let provider = test::create_table_dual();
-        ctx.register_table("dual", provider)?;
-
-        let results =
-            plan_and_collect(&ctx, "SELECT @@version, @name, @integer + 1 FROM dual")
-                .await?;
-
-        let expected = vec![
-            "+----------------------+------------------------+------------------------+",
-            "| @@version            | @name                  | @integer Plus Int64(1) |",
-            "+----------------------+------------------------+------------------------+",
-            "| system-var-@@version | user-defined-var-@name | 42                     |",
-            "+----------------------+------------------------+------------------------+",
-        ];
-        assert_batches_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn register_deregister() -> Result<()> {
-        let tmp_dir = TempDir::new()?;
-        let partition_count = 4;
-        let ctx = create_ctx(&tmp_dir, partition_count).await?;
-
-        let provider = test::create_table_dual();
-        ctx.register_table("dual", provider)?;
-
-        assert!(ctx.deregister_table("dual")?.is_some());
-        assert!(ctx.deregister_table("dual")?.is_none());
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn left_join_using() -> Result<()> {
-        let results = execute(
-            "SELECT t1.c1, t2.c2 FROM test t1 JOIN test t2 USING (c2) ORDER BY t2.c2",
-            1,
-        )
-        .await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+----+----+",
-            "| c1 | c2 |",
-            "+----+----+",
-            "| 0  | 1  |",
-            "| 0  | 2  |",
-            "| 0  | 3  |",
-            "| 0  | 4  |",
-            "| 0  | 5  |",
-            "| 0  | 6  |",
-            "| 0  | 7  |",
-            "| 0  | 8  |",
-            "| 0  | 9  |",
-            "| 0  | 10 |",
-            "+----+----+",
-        ];
-
-        assert_batches_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn left_join_using_join_key_projection() -> Result<()> {
-        let results = execute(
-            "SELECT t1.c1, t1.c2, t2.c2 FROM test t1 JOIN test t2 USING (c2) ORDER BY t2.c2",
-            1,
-        )
-            .await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+----+----+----+",
-            "| c1 | c2 | c2 |",
-            "+----+----+----+",
-            "| 0  | 1  | 1  |",
-            "| 0  | 2  | 2  |",
-            "| 0  | 3  | 3  |",
-            "| 0  | 4  | 4  |",
-            "| 0  | 5  | 5  |",
-            "| 0  | 6  | 6  |",
-            "| 0  | 7  | 7  |",
-            "| 0  | 8  | 8  |",
-            "| 0  | 9  | 9  |",
-            "| 0  | 10 | 10 |",
-            "+----+----+----+",
-        ];
-
-        assert_batches_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn left_join() -> Result<()> {
-        let results = execute(
-            "SELECT t1.c1, t1.c2, t2.c2 FROM test t1 JOIN test t2 ON t1.c2 = t2.c2 ORDER BY t1.c2",
-            1,
-        )
-            .await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+----+----+----+",
-            "| c1 | c2 | c2 |",
-            "+----+----+----+",
-            "| 0  | 1  | 1  |",
-            "| 0  | 2  | 2  |",
-            "| 0  | 3  | 3  |",
-            "| 0  | 4  | 4  |",
-            "| 0  | 5  | 5  |",
-            "| 0  | 6  | 6  |",
-            "| 0  | 7  | 7  |",
-            "| 0  | 8  | 8  |",
-            "| 0  | 9  | 9  |",
-            "| 0  | 10 | 10 |",
-            "+----+----+----+",
-        ];
-
-        assert_batches_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn window() -> Result<()> {
-        let results = execute(
-            "SELECT \
-            c1, \
-            c2, \
-            SUM(c2) OVER (), \
-            COUNT(c2) OVER (), \
-            MAX(c2) OVER (), \
-            MIN(c2) OVER (), \
-            AVG(c2) OVER () \
-            FROM test \
-            ORDER BY c1, c2 \
-            LIMIT 5",
-            4,
-        )
-        .await?;
-        // result in one batch, although e.g. having 2 batches do not change
-        // result semantics, having a len=1 assertion upfront keeps surprises
-        // at bay
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+----+----+--------------+----------------+--------------+--------------+--------------+",
-            "| c1 | c2 | SUM(test.c2) | COUNT(test.c2) | MAX(test.c2) | MIN(test.c2) | AVG(test.c2) |",
-            "+----+----+--------------+----------------+--------------+--------------+--------------+",
-            "| 0  | 1  | 220          | 40             | 10           | 1            | 5.5          |",
-            "| 0  | 2  | 220          | 40             | 10           | 1            | 5.5          |",
-            "| 0  | 3  | 220          | 40             | 10           | 1            | 5.5          |",
-            "| 0  | 4  | 220          | 40             | 10           | 1            | 5.5          |",
-            "| 0  | 5  | 220          | 40             | 10           | 1            | 5.5          |",
-            "+----+----+--------------+----------------+--------------+--------------+--------------+",
-        ];
-
-        // window function shall respect ordering
-        assert_batches_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn window_order_by() -> Result<()> {
-        let results = execute(
-            "SELECT \
-            c1, \
-            c2, \
-            ROW_NUMBER() OVER (ORDER BY c1, c2), \
-            FIRST_VALUE(c2) OVER (ORDER BY c1, c2), \
-            LAST_VALUE(c2) OVER (ORDER BY c1, c2), \
-            NTH_VALUE(c2, 2) OVER (ORDER BY c1, c2), \
-            SUM(c2) OVER (ORDER BY c1, c2), \
-            COUNT(c2) OVER (ORDER BY c1, c2), \
-            MAX(c2) OVER (ORDER BY c1, c2), \
-            MIN(c2) OVER (ORDER BY c1, c2), \
-            AVG(c2) OVER (ORDER BY c1, c2) \
-            FROM test \
-            ORDER BY c1, c2 \
-            LIMIT 5",
-            4,
-        )
-        .await?;
-        // result in one batch, although e.g. having 2 batches do not change
-        // result semantics, having a len=1 assertion upfront keeps surprises
-        // at bay
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+----+----+--------------+----------------------+---------------------+-----------------------------+--------------+----------------+--------------+--------------+--------------+",
-            "| c1 | c2 | ROW_NUMBER() | FIRST_VALUE(test.c2) | LAST_VALUE(test.c2) | NTH_VALUE(test.c2,Int64(2)) | SUM(test.c2) | COUNT(test.c2) | MAX(test.c2) | MIN(test.c2) | AVG(test.c2) |",
-            "+----+----+--------------+----------------------+---------------------+-----------------------------+--------------+----------------+--------------+--------------+--------------+",
-            "| 0  | 1  | 1            | 1                    | 1                   |                             | 1            | 1              | 1            | 1            | 1            |",
-            "| 0  | 2  | 2            | 1                    | 2                   | 2                           | 3            | 2              | 2            | 1            | 1.5          |",
-            "| 0  | 3  | 3            | 1                    | 3                   | 2                           | 6            | 3              | 3            | 1            | 2            |",
-            "| 0  | 4  | 4            | 1                    | 4                   | 2                           | 10           | 4              | 4            | 1            | 2.5          |",
-            "| 0  | 5  | 5            | 1                    | 5                   | 2                           | 15           | 5              | 5            | 1            | 3            |",
-            "+----+----+--------------+----------------------+---------------------+-----------------------------+--------------+----------------+--------------+--------------+--------------+",
-        ];
-
-        // window function shall respect ordering
-        assert_batches_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn window_partition_by() -> Result<()> {
-        let results = execute(
-            "SELECT \
-            c1, \
-            c2, \
-            SUM(c2) OVER (PARTITION BY c2), \
-            COUNT(c2) OVER (PARTITION BY c2), \
-            MAX(c2) OVER (PARTITION BY c2), \
-            MIN(c2) OVER (PARTITION BY c2), \
-            AVG(c2) OVER (PARTITION BY c2) \
-            FROM test \
-            ORDER BY c1, c2 \
-            LIMIT 5",
-            4,
-        )
-        .await?;
-
-        let expected = vec![
-            "+----+----+--------------+----------------+--------------+--------------+--------------+",
-            "| c1 | c2 | SUM(test.c2) | COUNT(test.c2) | MAX(test.c2) | MIN(test.c2) | AVG(test.c2) |",
-            "+----+----+--------------+----------------+--------------+--------------+--------------+",
-            "| 0  | 1  | 4            | 4              | 1            | 1            | 1            |",
-            "| 0  | 2  | 8            | 4              | 2            | 2            | 2            |",
-            "| 0  | 3  | 12           | 4              | 3            | 3            | 3            |",
-            "| 0  | 4  | 16           | 4              | 4            | 4            | 4            |",
-            "| 0  | 5  | 20           | 4              | 5            | 5            | 5            |",
-            "+----+----+--------------+----------------+--------------+--------------+--------------+",
-        ];
-
-        // window function shall respect ordering
-        assert_batches_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn window_partition_by_order_by() -> Result<()> {
-        let results = execute(
-            "SELECT \
-            c1, \
-            c2, \
-            ROW_NUMBER() OVER (PARTITION BY c2 ORDER BY c1), \
-            FIRST_VALUE(c2 + c1) OVER (PARTITION BY c2 ORDER BY c1), \
-            LAST_VALUE(c2 + c1) OVER (PARTITION BY c2 ORDER BY c1), \
-            NTH_VALUE(c2 + c1, 1) OVER (PARTITION BY c2 ORDER BY c1), \
-            SUM(c2) OVER (PARTITION BY c2 ORDER BY c1), \
-            COUNT(c2) OVER (PARTITION BY c2 ORDER BY c1), \
-            MAX(c2) OVER (PARTITION BY c2 ORDER BY c1), \
-            MIN(c2) OVER (PARTITION BY c2 ORDER BY c1), \
-            AVG(c2) OVER (PARTITION BY c2 ORDER BY c1) \
-            FROM test \
-            ORDER BY c1, c2 \
-            LIMIT 5",
-            4,
-        )
-        .await?;
-
-        let expected = vec![
-            "+----+----+--------------+--------------------------------+-------------------------------+---------------------------------------+--------------+----------------+--------------+--------------+--------------+",
-            "| c1 | c2 | ROW_NUMBER() | FIRST_VALUE(test.c2 + test.c1) | LAST_VALUE(test.c2 + test.c1) | NTH_VALUE(test.c2 + test.c1,Int64(1)) | SUM(test.c2) | COUNT(test.c2) | MAX(test.c2) | MIN(test.c2) | AVG(test.c2) |",
-            "+----+----+--------------+--------------------------------+-------------------------------+---------------------------------------+--------------+----------------+--------------+--------------+--------------+",
-            "| 0  | 1  | 1            | 1                              | 1                             | 1                                     | 1            | 1              | 1            | 1            | 1            |",
-            "| 0  | 2  | 1            | 2                              | 2                             | 2                                     | 2            | 1              | 2            | 2            | 2            |",
-            "| 0  | 3  | 1            | 3                              | 3                             | 3                                     | 3            | 1              | 3            | 3            | 3            |",
-            "| 0  | 4  | 1            | 4                              | 4                             | 4                                     | 4            | 1              | 4            | 4            | 4            |",
-            "| 0  | 5  | 1            | 5                              | 5                             | 5                                     | 5            | 1              | 5            | 5            | 5            |",
-            "+----+----+--------------+--------------------------------+-------------------------------+---------------------------------------+--------------+----------------+--------------+--------------+--------------+",
-        ];
-
-        // window function shall respect ordering
-        assert_batches_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_decimal_min() -> Result<()> {
-        let ctx = SessionContext::new();
-        // the data type of c1 is decimal(10,3)
-        ctx.register_table("d_table", test::table_with_decimal())
-            .unwrap();
-        let result = plan_and_collect(&ctx, "select min(c1) from d_table")
-            .await
-            .unwrap();
-        let expected = vec![
-            "+-----------------+",
-            "| MIN(d_table.c1) |",
-            "+-----------------+",
-            "| -100.009        |",
-            "+-----------------+",
-        ];
-        assert_eq!(
-            &DataType::Decimal(10, 3),
-            result[0].schema().field(0).data_type()
-        );
-        assert_batches_sorted_eq!(expected, &result);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_decimal_max() -> Result<()> {
-        let ctx = SessionContext::new();
-        // the data type of c1 is decimal(10,3)
-        ctx.register_table("d_table", test::table_with_decimal())
-            .unwrap();
-
-        let result = plan_and_collect(&ctx, "select max(c1) from d_table")
-            .await
-            .unwrap();
-        let expected = vec![
-            "+-----------------+",
-            "| MAX(d_table.c1) |",
-            "+-----------------+",
-            "| 110.009         |",
-            "+-----------------+",
-        ];
-        assert_eq!(
-            &DataType::Decimal(10, 3),
-            result[0].schema().field(0).data_type()
-        );
-        assert_batches_sorted_eq!(expected, &result);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_decimal_sum() -> Result<()> {
-        let ctx = SessionContext::new();
-        // the data type of c1 is decimal(10,3)
-        ctx.register_table("d_table", test::table_with_decimal())
-            .unwrap();
-        let result = plan_and_collect(&ctx, "select sum(c1) from d_table")
-            .await
-            .unwrap();
-        let expected = vec![
-            "+-----------------+",
-            "| SUM(d_table.c1) |",
-            "+-----------------+",
-            "| 100.000         |",
-            "+-----------------+",
-        ];
-        assert_eq!(
-            &DataType::Decimal(20, 3),
-            result[0].schema().field(0).data_type()
-        );
-        assert_batches_sorted_eq!(expected, &result);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_decimal_avg() -> Result<()> {
-        let ctx = SessionContext::new();
-        // the data type of c1 is decimal(10,3)
-        ctx.register_table("d_table", test::table_with_decimal())
-            .unwrap();
-        let result = plan_and_collect(&ctx, "select avg(c1) from d_table")
-            .await
-            .unwrap();
-        let expected = vec![
-            "+-----------------+",
-            "| AVG(d_table.c1) |",
-            "+-----------------+",
-            "| 5.0000000       |",
-            "+-----------------+",
-        ];
-        assert_eq!(
-            &DataType::Decimal(14, 7),
-            result[0].schema().field(0).data_type()
-        );
-        assert_batches_sorted_eq!(expected, &result);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate() -> Result<()> {
-        let results = execute("SELECT SUM(c1), SUM(c2) FROM test", 4).await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+--------------+--------------+",
-            "| SUM(test.c1) | SUM(test.c2) |",
-            "+--------------+--------------+",
-            "| 60           | 220          |",
-            "+--------------+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_empty() -> Result<()> {
-        // The predicate on this query purposely generates no results
-        let results = execute("SELECT SUM(c1), SUM(c2) FROM test where c1 > 100000", 4)
-            .await
-            .unwrap();
-
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+--------------+--------------+",
-            "| SUM(test.c1) | SUM(test.c2) |",
-            "+--------------+--------------+",
-            "|              |              |",
-            "+--------------+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_avg() -> Result<()> {
-        let results = execute("SELECT AVG(c1), AVG(c2) FROM test", 4).await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+--------------+--------------+",
-            "| AVG(test.c1) | AVG(test.c2) |",
-            "+--------------+--------------+",
-            "| 1.5          | 5.5          |",
-            "+--------------+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_max() -> Result<()> {
-        let results = execute("SELECT MAX(c1), MAX(c2) FROM test", 4).await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+--------------+--------------+",
-            "| MAX(test.c1) | MAX(test.c2) |",
-            "+--------------+--------------+",
-            "| 3            | 10           |",
-            "+--------------+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_min() -> Result<()> {
-        let results = execute("SELECT MIN(c1), MIN(c2) FROM test", 4).await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+--------------+--------------+",
-            "| MIN(test.c1) | MIN(test.c2) |",
-            "+--------------+--------------+",
-            "| 0            | 1            |",
-            "+--------------+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_grouped() -> Result<()> {
-        let results = execute("SELECT c1, SUM(c2) FROM test GROUP BY c1", 4).await?;
-
-        let expected = vec![
-            "+----+--------------+",
-            "| c1 | SUM(test.c2) |",
-            "+----+--------------+",
-            "| 0  | 55           |",
-            "| 1  | 55           |",
-            "| 2  | 55           |",
-            "| 3  | 55           |",
-            "+----+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_grouped_avg() -> Result<()> {
-        let results = execute("SELECT c1, AVG(c2) FROM test GROUP BY c1", 4).await?;
-
-        let expected = vec![
-            "+----+--------------+",
-            "| c1 | AVG(test.c2) |",
-            "+----+--------------+",
-            "| 0  | 5.5          |",
-            "| 1  | 5.5          |",
-            "| 2  | 5.5          |",
-            "| 3  | 5.5          |",
-            "+----+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn boolean_literal() -> Result<()> {
-        let results =
-            execute("SELECT c1, c3 FROM test WHERE c1 > 2 AND c3 = true", 4).await?;
-
-        let expected = vec![
-            "+----+------+",
-            "| c1 | c3   |",
-            "+----+------+",
-            "| 3  | true |",
-            "| 3  | true |",
-            "| 3  | true |",
-            "| 3  | true |",
-            "| 3  | true |",
-            "+----+------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_grouped_empty() -> Result<()> {
-        let results =
-            execute("SELECT c1, AVG(c2) FROM test WHERE c1 = 123 GROUP BY c1", 4).await?;
-
-        let expected = vec![
-            "+----+--------------+",
-            "| c1 | AVG(test.c2) |",
-            "+----+--------------+",
-            "+----+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_grouped_max() -> Result<()> {
-        let results = execute("SELECT c1, MAX(c2) FROM test GROUP BY c1", 4).await?;
-
-        let expected = vec![
-            "+----+--------------+",
-            "| c1 | MAX(test.c2) |",
-            "+----+--------------+",
-            "| 0  | 10           |",
-            "| 1  | 10           |",
-            "| 2  | 10           |",
-            "| 3  | 10           |",
-            "+----+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_grouped_min() -> Result<()> {
-        let results = execute("SELECT c1, MIN(c2) FROM test GROUP BY c1", 4).await?;
-
-        let expected = vec![
-            "+----+--------------+",
-            "| c1 | MIN(test.c2) |",
-            "+----+--------------+",
-            "| 0  | 1            |",
-            "| 1  | 1            |",
-            "| 2  | 1            |",
-            "| 3  | 1            |",
-            "+----+--------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn aggregate_avg_add() -> Result<()> {
-        let results = execute(
-            "SELECT AVG(c1), AVG(c1) + 1, AVG(c1) + 2, 1 + AVG(c1) FROM test",
-            4,
-        )
-        .await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+--------------+----------------------------+----------------------------+----------------------------+",
-            "| AVG(test.c1) | AVG(test.c1) Plus Int64(1) | AVG(test.c1) Plus Int64(2) | Int64(1) Plus AVG(test.c1) |",
-            "+--------------+----------------------------+----------------------------+----------------------------+",
-            "| 1.5          | 2.5                        | 3.5                        | 2.5                        |",
-            "+--------------+----------------------------+----------------------------+----------------------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn join_partitioned() -> Result<()> {
-        // self join on partition id (workaround for duplicate column name)
-        let results = execute(
-            "SELECT 1 FROM test JOIN (SELECT c1 AS id1 FROM test) AS a ON c1=id1",
-            4,
-        )
-        .await?;
-
-        assert_eq!(
-            results.iter().map(|b| b.num_rows()).sum::<usize>(),
-            4 * 10 * 10
-        );
-
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn count_basic() -> Result<()> {
-        let results = execute("SELECT COUNT(c1), COUNT(c2) FROM test", 1).await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+----------------+----------------+",
-            "| COUNT(test.c1) | COUNT(test.c2) |",
-            "+----------------+----------------+",
-            "| 10             | 10             |",
-            "+----------------+----------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn count_partitioned() -> Result<()> {
-        let results = execute("SELECT COUNT(c1), COUNT(c2) FROM test", 4).await?;
-        assert_eq!(results.len(), 1);
-
-        let expected = vec![
-            "+----------------+----------------+",
-            "| COUNT(test.c1) | COUNT(test.c2) |",
-            "+----------------+----------------+",
-            "| 40             | 40             |",
-            "+----------------+----------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn count_aggregated() -> Result<()> {
-        let results = execute("SELECT c1, COUNT(c2) FROM test GROUP BY c1", 4).await?;
-
-        let expected = vec![
-            "+----+----------------+",
-            "| c1 | COUNT(test.c2) |",
-            "+----+----------------+",
-            "| 0  | 10             |",
-            "| 1  | 10             |",
-            "| 2  | 10             |",
-            "| 3  | 10             |",
-            "+----+----------------+",
-        ];
-        assert_batches_sorted_eq!(expected, &results);
-        Ok(())
-    }
-
-    #[tokio::test]
-    async fn group_by_date_trunc() -> Result<()> {
-        let tmp_dir = TempDir::new()?;
-        let ctx = SessionContext::new();
-        let schema = Arc::new(Schema::new(vec![
-            Field::new("c2", DataType::UInt64, false),
-            Field::new(
-                "t1",
-                DataType::Timestamp(TimeUnit::Microsecond, None),
-                false,
-            ),
-        ]));
-
-        // generate a partitioned file
-        for partition in 0..4 {
-            let filename = format!("partition-{}.{}", partition, "csv");
-            let file_path = tmp_dir.path().join(&filename);
-            let mut file = File::create(file_path)?;
+    async fn create_variable_expr() -> Result<()> {
+        let tmp_dir = TempDir::new()?;
+        let partition_count = 4;
+        let mut ctx = create_ctx(&tmp_dir, partition_count).await?;
 
-            // generate some data
-            for i in 0..10 {
-                let data = format!("{},2020-12-{}T00:00:00.000Z\n", i, i + 10);
-                file.write_all(data.as_bytes())?;
-            }
-        }
+        let variable_provider = test::variable::SystemVar::new();
+        ctx.register_variable(VarType::System, Arc::new(variable_provider));
+        let variable_provider = test::variable::UserDefinedVar::new();
+        ctx.register_variable(VarType::UserDefined, Arc::new(variable_provider));
 
-        ctx.register_csv(
-            "test",
-            tmp_dir.path().to_str().unwrap(),
-            CsvReadOptions::new().schema(&schema).has_header(false),
-        )
-        .await?;
+        let provider = test::create_table_dual();
+        ctx.register_table("dual", provider)?;
 
-        let results = plan_and_collect(
-            &ctx,
-            "SELECT date_trunc('week', t1) as week, SUM(c2) FROM test GROUP BY date_trunc('week', t1)",
-        ).await?;
+        let results =
+            plan_and_collect(&ctx, "SELECT @@version, @name, @integer + 1 FROM dual")
+                .await?;
 
         let expected = vec![
-            "+---------------------+--------------+",
-            "| week                | SUM(test.c2) |",
-            "+---------------------+--------------+",
-            "| 2020-12-07 00:00:00 | 24           |",
-            "| 2020-12-14 00:00:00 | 156          |",
-            "+---------------------+--------------+",
+            "+----------------------+------------------------+------------------------+",
+            "| @@version            | @name                  | @integer Plus Int64(1) |",
+            "+----------------------+------------------------+------------------------+",
+            "| system-var-@@version | user-defined-var-@name | 42                     |",
+            "+----------------------+------------------------+------------------------+",
         ];
-        assert_batches_sorted_eq!(expected, &results);
+        assert_batches_eq!(expected, &results);
 
         Ok(())
     }
 
     #[tokio::test]
-    async fn group_by_largeutf8() {
-        {
-            let ctx = SessionContext::new();
-
-            // input data looks like:
-            // A, 1
-            // B, 2
-            // A, 2
-            // A, 4
-            // C, 1
-            // A, 1
-
-            let str_array: LargeStringArray = vec!["A", "B", "A", "A", "C", "A"]
-                .into_iter()
-                .map(Some)
-                .collect();
-            let str_array = Arc::new(str_array);
-
-            let val_array: Int64Array = vec![1, 2, 2, 4, 1, 1].into();
-            let val_array = Arc::new(val_array);
-
-            let schema = Arc::new(Schema::new(vec![
-                Field::new("str", str_array.data_type().clone(), false),
-                Field::new("val", val_array.data_type().clone(), false),
-            ]));
-
-            let batch =
-                RecordBatch::try_new(schema.clone(), vec![str_array, val_array]).unwrap();
+    async fn register_deregister() -> Result<()> {

Review Comment:
   👍  for keeping the variable tests (and others that are related to `SessionContext` in the same file



-- 
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 merged pull request #2329: move sql tests from `context.rs` to corresponding test files in `tests/sql`

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


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