Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coalesce fails for query: `SELECT COALESCE(null, 5) #12307

Closed
mesejo opened this issue Sep 3, 2024 · 0 comments · Fixed by #12308
Closed

Coalesce fails for query: `SELECT COALESCE(null, 5) #12307

mesejo opened this issue Sep 3, 2024 · 0 comments · Fixed by #12308
Labels
bug Something isn't working

Comments

@mesejo
Copy link
Contributor

mesejo commented Sep 3, 2024

Describe the bug

This issue was first reported in datafusion-python; upon further inspection, this appears to be a bug in datafusion itself.

To Reproduce

This fails:

  async fn test_coalesce_schema() -> Result<()> {
      let ctx = SessionContext::new();

      let query = r#"SELECT COALESCE(null, 5)"#;

      let result = ctx.sql(query).await?;
      assert_logical_expr_schema_eq_physical_expr_schema(result).await?;
      Ok(())
  }

Expected behavior

The code should not fail.

Additional context

The problem seems to be in the ScalarUDFImpl for CoalesceFunc:

    fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
        Ok(arg_types[0].clone())
    }

    // If all the element in coalesce is non-null, the result is non-null
    fn is_nullable(&self, args: &[Expr], schema: &dyn ExprSchema) -> bool {
        args.iter().any(|e| e.nullable(schema).ok().unwrap_or(true))
    }

The return_type is the first one when it should be the first non-null, and is_nullable returns true if any of the args is null

@mesejo mesejo added the bug Something isn't working label Sep 3, 2024
mesejo added a commit to mesejo/arrow-datafusion that referenced this issue Sep 3, 2024
mesejo added a commit to mesejo/arrow-datafusion that referenced this issue Sep 8, 2024
mesejo added a commit to mesejo/arrow-datafusion that referenced this issue Sep 12, 2024
mesejo added a commit to mesejo/arrow-datafusion that referenced this issue Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant