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

[QUESTION] How many times should be the function create_name called when executing a query? #3900

Closed
HaoYang670 opened this issue Oct 20, 2022 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@HaoYang670
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.
Related to this function: https://github.com/apache/arrow-datafusion/blob/master/datafusion/expr/src/expr.rs#L951

To Reproduce
I add println here to check if the function is called:

/// Returns a readable name of an expression based on the input schema.
/// This function recursively transverses the expression for names such as "CAST(a > 2)".
fn create_name(e: &Expr) -> Result<String> {
    println!("create name for e");

note that the println command doesn't get the name of e to avoid recursive function calls.

Then I ran a really simple query in the datafusion-cli, and got the following result:

DataFusion CLI v13.0.0select 1;
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
create name for e
+----------+
| Int64(1) |
+----------+
| 1        |
+----------+
1 row in set. Query took 0.004 seconds.

It is a little weird to me that the function create_name is called 18 times.

I also tested by constructing the expression directly:

    #[test]
    fn my_fail_test() {
        let expr = lit(1);
        // make the test failed, so that we can see the content from `println`
        assert_eq!("UINT(2)", expr.display_name().unwrap())
    }

, and this works fine:

running 1 test
create name for e
thread 'expr::test::my_fail_test' panicked at 'assertion failed: `(left == right)`
  left: `"UINT(2)"`,
 right: `"Int32(1)"`', datafusion/expr/src/expr.rs:1255:9

Expected behavior
I guess the function create_name should only be called once for each expression.

Additional context
Add any other context about the problem here.

@HaoYang670 HaoYang670 added the help wanted Extra attention is needed label Oct 20, 2022
@comphead
Copy link
Contributor

There are couple of ways to come to create_name

  • aliasing not qualified cols, this works good, 2 calls only
  • display_name() which calls create_name and the first one gets called everywhere

@HaoYang670
Copy link
Contributor Author

Thank you, @comphead, for your explanation. It makes sense now. I'll close the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants