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

substr_index doesn't behave correctly with a negative delimiter position #9472

Closed
sanderson opened this issue Mar 5, 2024 · 1 comment · Fixed by #9475
Closed

substr_index doesn't behave correctly with a negative delimiter position #9472

sanderson opened this issue Mar 5, 2024 · 1 comment · Fixed by #9475
Assignees
Labels
bug Something isn't working

Comments

@sanderson
Copy link
Contributor

sanderson commented Mar 5, 2024

Describe the bug

The substr_index function only returns the expected response for the first row in a table and an incorrect result for all subsequent rows when using a negative delimiter count. It seems to use the position of the specified delimiter in the first row to process all subsequent rows. It also includes the delimiter in the returned substring, when I don't believe that it should.

To Reproduce

Run the following query:

SELECT
  url,
  substr_index(url, '.', 1) AS subdomain,
  substr_index(url, '.', -1) AS tld
FROM
  (values ('docs.apache.com'),
          ('community.influxdata.com'),
          ('arrow.apache.org')
  ) data(url)
url subdomain tld
docs.influxdata.com docs .com
community.influxdata.com community xdata.com
arrow.apache.org arrow e.org

Expected behavior

I would expect the above query to return the following:

url subdomain tld
docs.influxdata.com docs com
community.influxdata.com community com
arrow.apache.org arrow org

Additional context

I tested this in InfluxDB v3's implementation of DataFusion, but I believe these changes were just pulled from upstream.

@sanderson sanderson added the bug Something isn't working label Mar 5, 2024
@jonahgao
Copy link
Member

jonahgao commented Mar 6, 2024

take

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.

2 participants