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

Query: Translate byte array.IndexOf #19287

Open
smitpatel opened this issue Dec 12, 2019 · 6 comments · May be fixed by #34457
Open

Query: Translate byte array.IndexOf #19287

smitpatel opened this issue Dec 12, 2019 · 6 comments · May be fixed by #34457
Labels
area-query good first issue This issue should be relatively straightforward to fix. type-enhancement
Milestone

Comments

@smitpatel
Copy link
Contributor

No description provided.

@ajcvickers ajcvickers added this to the Backlog milestone Dec 13, 2019
@ajcvickers ajcvickers added the good first issue This issue should be relatively straightforward to fix. label Dec 13, 2019
@smitpatel
Copy link
Contributor Author

CharIndex over varbinary(max) returns bigint rather than int.

@ralmsdeveloper
Copy link
Contributor

ralmsdeveloper commented Jun 12, 2020

[Edited name]
I'm on vacation, and I want to get some things to do, can I start with this one, @roji / @smitpatel any observation?

@roji
Copy link
Member

roji commented Jun 12, 2020

Nothing in particular @ralmsdeveloper, just to pay close attention to specific return types (bigint/int) as @smitpatel wrote above.

@nikhil197
Copy link

nikhil197 commented Aug 15, 2024

Hi @roji / @smitpatel

I am new to the EFCore repo and have just understood some basic things about the translation (above linked PR helped with that a bit).
I would like to work on this one if it's not being worked on by any one else.

Here's my initial understanding of this issue (atleast for SqlServer):

  • Need to add a specific translator for the ByteArray for the 2 overloads of Array.IndexOf method in SqlServerByteArrayMethodTranslator
  • In case the declaring type is varbinary(max) cast the return value as int before returning

Haven't looked into sqlLite for this yet, but it should be easily portable. Before that I wanted to check if I'm on the right track for this?

@roji
Copy link
Member

roji commented Aug 17, 2024

@nikhil197 overall yes, but what are you planning to translate the method call to exactly? And why "cast the return value as int"? Note that you'll also need to add proper test coverage too.

I'd suggest on concentrating on a SQL Server implementation first, it's also OK if support is added only for SQL Server initially without SQLite (although support in both is obviously better).

@nikhil197
Copy link

nikhil197 commented Aug 17, 2024

@roji
I have tried implementing similar to what has already been done for the string.IndexOf methods. Passing values to CHARINDEX (with conversions, if needed) and then returning value - 1 (since CHARINDEX returns 1-based values).
This is the final translation for the Array.IndexOf method for byte[], with a starting position:
CAST(CHARINDEX(CAST(@__b_0 AS varbinary(max)), [s].[Banner], @__startPos_1 + 1) AS int) - 1

And casting to int is only when varbinary(max) is the underlying type of the column because as mentioned above, CHARINDEX will return bigint. So to match that to the method which returns int, I'm using a cast.

And I have tried adding tests as well. I was starting to look into the SQLite change, but I can raise the PR for the changes I have done so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query good first issue This issue should be relatively straightforward to fix. type-enhancement
Projects
None yet
5 participants