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

3959 instr #2

Open
wants to merge 3 commits into
base: joey
Choose a base branch
from
Open

3959 instr #2

wants to merge 3 commits into from

Conversation

jhugomoore
Copy link

No description provided.

@jhugomoore jhugomoore changed the base branch from main to joey April 27, 2023 18:08
@jhugomoore jhugomoore force-pushed the 3959-INSTR branch 2 times, most recently from 39b2571 to aa66da6 Compare April 27, 2023 18:39
Copy link
Owner

@tanclary tanclary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!!! Left some mainly minor comments, only other suggestion would be to add some quidem tests to BigQuery.iq, wouldn't say its mandatory, just an idea. Awesome first draft!

final int from0 = from - 1; // 0-based
if (from0 > s.length() || from0 < 0) {
if (from == 0) {
throw new IllegalArgumentException("From position cannot be zero");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most exceptions thrown in this class are stored in the RESOURCES here. You could add an entry.

final int from0 = from - 1;
if (from0 > s.length() || from0 < 0) {
if (from == 0) {
throw new IllegalArgumentException("From position cannot be zero");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above, could be useful just so this doesn't have to be retyped each time.

if (from > 0) {
final int from0 = from - 1; // 0-based
if (from0 > s.length() || from0 < 0) {
return 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if from0 == s.length()? Should this also return 0 since you can't get the 1-based (n+1)th position of a string of n characters? This would mean from > s.length(). Just curious

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're so right, great call

if (from == 0) {
return 0;
}
from -= (s.length() + 2);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if this could be helpful but it seems like there's a lot of checking to determine if FROM is a valid value or not, could a helper be useful? This logic is crazy so I don't know if it would help that much or not, just a thought.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think there's definitely some simplifying that could be done, especially with all the +1s -1s and the like flying around. I'll look into it

final String query = "SELECT INSTR('A', 'ABC', 1, 1) from \"product\"";
final String expected = "SELECT INSTR('A', 'ABC', 1, 1)\n"
+ "FROM foodmart.product";
final Sql sql = fixture().withBigQuery().withLibrary(SqlLibrary.BIG_QUERY);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think you can do something like sql(query).withBigQuery().withLibrary(SqlLibrary.BIG_QUERY).ok(expected); shouldn't need to create Sql object i dont think

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also if the function is valid for other libraries, could be a good idea to test with those libraries as well

assertThat(-1, is(position("f", "abcdec", 1, 1)));
assertThat(-1, is(position("c", "abcdec", 1, 3)));
try {
int i = position("c", "abcdec", 0, 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based testing 🙏

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually made me realize those tests were wrong lol, appreciate the comment

@@ -2693,6 +2693,7 @@ BigQuery's type system uses confusingly different names for types and functions:
| b o | GREATEST(expr [, expr ]*) | Returns the greatest of the expressions
| b h s | IF(condition, value1, value2) | Returns *value1* if *condition* is TRUE, *value2* otherwise
| b | IFNULL(value1, value2) | Equivalent to `NVL(value1, value2)`
| b o | INSTR(string1, string2[, int1, int2]) | return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just reminder to update this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@Test void testLocalTimeFuncWithCurrentTime() {
testLocalTimeFunc(currentTimeString(LOCAL_TZ));
}
// @Tag("slow")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this meant to be commented out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh lol oops, commented out cause it was slow when running tests, nice catch!

@@ -6224,6 +6224,30 @@ private void testCurrentDateFunc(Pair<String, Hook.Closeable> pair) {
f.checkNull("STRPOS(x'', null)");
}

@Test void testInstrFunction() {
final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.INSTR);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should add a test that ensures the function doesnt work unless its set for bigquery, you should also test against each library the function supports, not just bigquery. good example here.

@jhugomoore jhugomoore force-pushed the 3959-INSTR branch 6 times, most recently from 8cf0c50 to 4179b7e Compare May 2, 2023 18:34
tanclary pushed a commit that referenced this pull request Nov 8, 2023
* Adds OAuth configs

* Update configs
tanclary pushed a commit that referenced this pull request Oct 24, 2024
Add release notes. In the release notes for previous releases,
change whitespace and formatting for consistency among
releases, standardize on 'Postgres' rather than 'PostgreSQL',
and move the 'Compatability' paragraph before the 'Breaking
changes' section.

Add users' aliases to .mailmap, so that the contributors list
in the release notes contains people's real name.

Fix a typo in FileReaderTest.

Release candidate #1 introduced

  [CALCITE-6616] ClassNotFoundException:
  java.util.SequencedCollection at RelBuilder$Frame init

The cause was compiling the release candidate using JDK 21,
which caused the `interface SequencedCollection`, introduced
in JDK 21, to be used in resolving methods. The fix (in
release candidate #2) is to revert to JDK 8 for the release
build (and revert the instructions in howto.md). We suspect
that building with building with JDK 11 or 17 would also work.

Revise template vote email. Fix the tag URL, add an end time
for the vote, describe how to use 'code name (role)' vote
format, sign using release manager's name.

Close apache#3979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants