Skip to content

Move ESQL's LOCATE test cases to cases#107271

Merged
nik9000 merged 2 commits intoelastic:mainfrom
nik9000:locate_sig
Apr 9, 2024
Merged

Move ESQL's LOCATE test cases to cases#107271
nik9000 merged 2 commits intoelastic:mainfrom
nik9000:locate_sig

Conversation

@nik9000
Copy link
Copy Markdown
Member

@nik9000 nik9000 commented Apr 9, 2024

This moves the test cases declared in the tests for ESQL's LOCATE function to test cases which will cause #106782 to properly generate all of the available signatures. It also buys us all of testing for incorrect parameter combinations.

This moves the test cases declared in the tests for ESQL's LOCATE
function to test cases which will cause elastic#106782 to properly generate all
of the available signatures. It also buys us all of testing for
incorrect parameter combinations.
@nik9000 nik9000 added >test Issues or PRs that are addressing/adding tests :Analytics/ES|QL AKA ESQL v8.14.0 labels Apr 9, 2024
@nik9000 nik9000 requested review from ChrisHegarty and tteofili April 9, 2024 13:57
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Apr 9, 2024
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

Copy link
Copy Markdown
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

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

LGTM

* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Locate}.
* This class is generated. Do not edit it.
*/
public final class LocateNoStartEvaluator implements EvalOperator.ExpressionEvaluator {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm... yes I noticed this one too locally. Thanks for committing.

}

return start == null ? TypeResolution.TYPE_RESOLVED : isInteger(start, sourceText(), THIRD);
return start == null ? TypeResolution.TYPE_RESOLVED : isType(start, dt -> dt == DataTypes.INTEGER, sourceText(), THIRD, "integer");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was incorrectly letting through longs. The rest of the class didn't work if you passed longs here so I figured I'd fix it this way. The other option is to keep this and cast the long parameters down to integers when we receive them. Fine either way, but long is very very large an index into an array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good catch @nik9000, either solution is fine by me.

Map.entry(Set.of(DataTypes.LONG, DataTypes.INTEGER, DataTypes.UNSIGNED_LONG, DataTypes.DOUBLE, DataTypes.NULL), "numeric"),
Map.entry(Set.of(DataTypes.KEYWORD, DataTypes.TEXT, DataTypes.VERSION, DataTypes.NULL), "string or version"),
Map.entry(Set.of(DataTypes.KEYWORD, DataTypes.TEXT, DataTypes.NULL), "string"),
Map.entry(Set.of(DataTypes.KEYWORD, DataTypes.TEXT), "string"),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't believe we need these. Dropping them.

}

static String nameFromTypes(List<DataType> types) {
public static String nameFromTypes(List<DataType> types) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I steal this to name a few things.

str -> randomRealisticUnicodeOfCodepointLength(2),
() -> between(0, 3),
(str, substr, start) -> 1 + str.indexOf(substr, start)
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This random unicode tests will cover some of the cases below, but pretty rarely.

assert "🐱".getBytes(StandardCharsets.UTF_8).length == 4 && "🐶".getBytes(StandardCharsets.UTF_8).length == 4;
suppliers.add(supplier("🐱Meow!🐶Woof!", "🐱Meow!🐶Woof!", null, 1));
suppliers.add(supplier("🐱Meow!🐶Woof!", "Meow!🐶Woof!", 0, 2));
suppliers.add(supplier("🐱Meow!🐶Woof!", "eow!🐶Woof!", 0, 3));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All of your tests live here now. It's weird, but it's how the rest of the function tests work. And it works pretty well.

@nik9000 nik9000 merged commit 8852566 into elastic:main Apr 9, 2024
@nik9000
Copy link
Copy Markdown
Member Author

nik9000 commented Apr 9, 2024

Thanks @tteofili !

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

Labels

:Analytics/ES|QL AKA ESQL Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) >test Issues or PRs that are addressing/adding tests v8.14.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants