Skip to content

Expand use of sql parsing string expressions in DataFrame #1278

Description

@timsaucer

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

This is a follow on to #1273

There are a number of places where it would be convenient to pass SQL strings as expressions. For example, it would be nice to do

df.select(
    "a",
    "a - b",
    col("c"),
)

This should intuitively know that we are getting column a, followed by col("a") - col("b") followed by column 'c'.

Describe the solution you'd like

Using the sql parsing on the DataFrame make the following functions handle SQL strings. We must be very careful that we do not break things like cases where users have a column name that is not SQL parseable.

Describe alternatives you've considered

Status quo

Additional context

DataFrame functions to update:

We do not want to apply this treatment to joins because there is no easy way to know which DataFrame to perform the SQL parsing against.

Activity

  1. timsaucer commented on Oct 15, 2025

    @timsaucer
    MemberAuthor
  2. timsaucer commented on Oct 15, 2025

    @timsaucer
    MemberAuthor

    I think when we have a string we want to first check to see if it is a column name. If so, create a column expression. If not, try sql parsing.

  3. milenkovicm commented on Oct 15, 2025

    @milenkovicm
    Contributor

    Have you changed your mind about select Tim? I'm stuck next few days but may help if needed

  4. timsaucer commented on Oct 15, 2025

    @timsaucer
    MemberAuthor

    I do think we want select but it just can't be the snippet I shared before. Instead I think it needs to check if the string matches a column name first. If so, make a column expression. Otherwise try parsing. What do you think?

  5. milenkovicm commented on Oct 15, 2025

    @milenkovicm
    Contributor

    I have no strong opinion Tim, I'm split between keeping it as it is and change it

  6. milenkovicm commented on Oct 16, 2025

    @milenkovicm
    Contributor

    i hope to tick off few of them off the list this weekend

  7. milenkovicm commented on Oct 20, 2025

    @milenkovicm
    Contributor

    looking at spark it looks like we're aligned with select and selectExpr maybe we keep both as they are ?

  8. timsaucer commented on Oct 20, 2025

    @timsaucer
    MemberAuthor

    I can see how it might be preferable to some to have it split out, but I also feel like just having one select is very ergonomic. Asking for another opinion from some users I know @ntjohnson1 @MrPowers

  9. milenkovicm commented on Oct 20, 2025

    @milenkovicm
    Contributor

    if we do not have special handle for column names I would agree with you, one select may make more sense. If we have to check for column name before we parse_sql I believe it would be simpler from user perspective to leave them as they are. Anyway leats get consensus

  10. ntjohnson1 commented on Oct 20, 2025

    @ntjohnson1
    Contributor

    I definitely think a single select would be nice ergonomically.

  11. milenkovicm commented on Oct 21, 2025

    @milenkovicm
    Contributor

    aggregate may have the same issue like select as it expects column name as a string, I'll leave those two to you @timsaucer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions