-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ESQL: Add ser/deser to functions tests #122498
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
ESQL: Add ser/deser to functions tests #122498
Conversation
| Expression newRight = newChildren.get(1); | ||
|
|
||
| return left.equals(newLeft) && right.equals(newRight) ? this : replaceChildren(newLeft, newRight); | ||
| return replaceChildren(newLeft, newRight); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what to think about this, I may try to do... something around it, as the test code currently needs replaceChildren() to actually replace them even if only the Source changed.
This is the only ESQL expression I found doing this, so I need to check if this was made for some specific reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do a expression.replaceChildren(dummies).replaceChildren(new). A bit weird, but it is what it is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally replaced with that, and restored the original code here
| } | ||
|
|
||
| /** | ||
| * @deprecated Sources created by this can't be correctly deserialized. For use in tests only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if deprecated is the way, but this is used only in tests, and can't be serialized. So I preferred to make it explicit that this is dangerous
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
nik9000
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea.
| } | ||
|
|
||
| private Expression randomSerializeDeserialize(Expression expression) { | ||
| if (false && randomBoolean()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false && maybe a leftover
| */ | ||
| protected final Expression buildFieldExpression(TestCaseSupplier.TestCase testCase) { | ||
| return build(testCase.getSource(), testCase.getDataAsFields()); | ||
| return randomSerializeDeserialize(build(testCase.getSource(), testCase.getDataAsFields())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see! So you are asserting that everything works the same after a round trip of serialization/deserialization. That sounds nice.
| implements | ||
| Supplier<TestCaseSupplier.TestCase> { | ||
|
|
||
| public static final Source TEST_SOURCE = new Source(new Location(1, 0), "source"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it'd be better to randomize this in the places we call it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually probably not - we want it to be consistent in the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to autogenerate it, so we can also deserialize the fields with a real source, with real names, and remove synthetic Sources from tests if possible.
There's some minor problems I have to handle first to do that, so I'll try in another PR
| new TestCaseSupplier.TypedData(null, DataType.KEYWORD, "order").forceLiteral() | ||
| ), | ||
| "third argument of [] cannot be null, received [order]" | ||
| "third argument of [source] cannot be null, received [order]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if source should be TOP or something. source feels sort of surprising here even though it's easy to make it the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could call functionName() to get the function I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's currently a static Source. Making it dynamic is possible, but requires also changing the Configuration.
As commented in other thread here, I'll try that later, but it requires some extra refactor, and I feel like it's better in a separate PR.
I thoguht about changing that "source" to something more localizable like "$source$" or even "function()". But at this point, I'm not sure it adds much
| Supplier<TestCaseSupplier.TestCase> { | ||
|
|
||
| public static final Source TEST_SOURCE = new Source(new Location(1, 0), "source"); | ||
| public static final Configuration TEST_CONFIGURATION = EsqlTestUtils.configuration(TEST_SOURCE.text()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning - these are very slow to randomly generate. What you are doing is fine here - but a while back I had some tests that generated a random configuration in a loop - and, like 1000 or them took some time. Anyway, you shouldn't have a problem with this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least with what we have here, I didn't see a notable difference in times. I'll consider if I try to generate a realistic source, as the config query would have to change per-test. Something to check if I open that other PR
|
|
||
| @Override | ||
| protected Expression serializeDeserializeExpression(Expression expression) { | ||
| // TODO: This aggregation doesn't serialize the Source, and must be fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really nice to open an issue about it and reference it here from the todo.
This way we could track its progress and know if todos are resolved or accidentally left after the feature was implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! That's the issue I was tracking actually, so I should have had one to begin with :hehe:
| Configuration differentConfig; | ||
| do { | ||
| differentConfig = randomConfiguration(); | ||
| } while (config.equals(differentConfig)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: This could be simplified with Configuration differentConfig = randomValueOtherThan(config, () -> randomConfiguration());
# Why and what? First part of elastic#122588 Some functions don't serialize their Source. This sometimes makes them emit wrong warnings, with -1:-1 line and without the correct source text. This PR pretends to integrate ser/deserialization before executing some (randomly chosen) functions, as well as using a non-empty Source to build them. _Note:_ It's different from the SerializationTests: Here we check that, whether serialized or not, the functionality is identical
# Why and what? First part of elastic#122588 Some functions don't serialize their Source. This sometimes makes them emit wrong warnings, with -1:-1 line and without the correct source text. This PR pretends to integrate ser/deserialization before executing some (randomly chosen) functions, as well as using a non-empty Source to build them. _Note:_ It's different from the SerializationTests: Here we check that, whether serialized or not, the functionality is identical
# Why and what? First part of #122588 Some functions don't serialize their Source. This sometimes makes them emit wrong warnings, with -1:-1 line and without the correct source text. This PR pretends to integrate ser/deserialization before executing some (randomly chosen) functions, as well as using a non-empty Source to build them. _Note:_ It's different from the SerializationTests: Here we check that, whether serialized or not, the functionality is identical
Why and what?
First part of #122588
Some functions don't serialize their Source. This sometimes makes them emit wrong warnings, with -1:-1 line and without the correct source text.
This PR pretends to integrate ser/deserialization before executing some (randomly chosen) functions, as well as using a non-empty Source to build them.
Note: It's different from the SerializationTests: Here we check that, whether serialized or not, the functionality is identical
To-Do