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

ESQL: More docs #98890

Merged
merged 9 commits into from
Aug 28, 2023
Merged

ESQL: More docs #98890

merged 9 commits into from
Aug 28, 2023

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Aug 25, 2023

Adds some more typed docs to the ESQL functions.

Adds some more typed docs to the ESQL functions.
@github-actions
Copy link
Contributor

Documentation preview:

@nik9000 nik9000 marked this pull request as ready for review August 27, 2023 11:04
@nik9000 nik9000 added >docs General docs changes :Analytics/ES|QL AKA ESQL labels Aug 27, 2023
@elasticsearchmachine elasticsearchmachine added Team:Docs Meta label for docs team Team:QL (Deprecated) Meta label for query languages team labels Aug 27, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-docs (Team:Docs)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/elasticsearch-esql (:Query Languages/ES|QL)

@nik9000
Copy link
Member Author

nik9000 commented Aug 27, 2023

This also adds a few more type tests for ESQL functions as that's how you make the docs.

Copy link
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 3 to 4
arg1 | arg2... | result
boolean | boolean
boolean | boolean | boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: that is much cleaner and clearer IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

At some point we'll want this to be able to promote as part of these - like COALESCE(12, 123432153) becoming a LONG instead of an error. We'll want some way to say that with these examples - and I think something like this is right for it.

Comment on lines 3 to -4
result
integer | double
Copy link
Contributor

Choose a reason for hiding this comment

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

thought: Hm, if we still emit this table for constants like e, at all, then I wonder if it wouldn't be better to still place the result type here, i.e.
double
instead of an empty line.

Then, we could consistently add the type table to both constants and functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hadn't even looked at this table for the constant functions. I had figured we'd build the file because it didn't hurt but that we wouldn't use it. I suppose it's pretty simple to make it useful though.

@@ -222,34 +226,32 @@ public String toString() {
}

/**
* Generate positive test cases for binary functions that operate on an {@code numeric}
* Generate positive test cases for unary functions that operate on an {@code numeric}
* fields by casting them to {@link DataTypes#DOUBLE}s.
*/
public static List<TestCaseSupplier> forUnaryCastingToDouble(String name, String argName, DoubleUnaryOperator expected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

thought (highly out of scope for this PR): I wonder if e.g. refactors will be harder in the future because of the fact that AbstractFunctionTestCase has two separate responsibilities at the moment, namely

  • serving as base class for function tests, and
  • controlling how docs for functions are being auto-generated.

I imagine that we'd maybe want to separate this in the future. For instance, we could add a method to our function classes that returns the allowed type combinations + result; then AbstractFunctionTestCase could generate negative tests for any type combinations that were not marked as allowed, and a separate class could generate docs from the allowed type combinations+results.

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose this could become a problem in a few ways:

  1. We want to document type combinations we aren't testing.
  2. We want to test combinations we don't document
  3. Everything just gets gummed up together

I think 1 is fairly unlikely and generally a bad thing to want. We already have 2 and have some work arounds for it, but they aren't really "pluggable", just heuristics like "the number of arguments is the same". That seems ok for now.

3 is a bigger concern, though one I think I'd like to ignore until it actually happens.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that we want 1 and 2, and am a bit afraid of 3; I think we're already doing the right thing, I'm just wondering if we can avoid gumming up by having our functions actively declare what type combos are supported, rather than inferring the supported types implicitly from the tests; we can still ensure 1 and 2 this way, I think.

Comment on lines +29 to +40
String read = "Attribute[channel=0]";
List<TestCaseSupplier> suppliers = new ArrayList<>();
TestCaseSupplier.forUnaryInt(suppliers, "Log10IntEvaluator[val=" + read + "]", DataTypes.DOUBLE, Math::log10);
TestCaseSupplier.forUnaryLong(suppliers, "Log10LongEvaluator[val=" + read + "]", DataTypes.DOUBLE, Math::log10);
TestCaseSupplier.forUnaryUnsignedLong(
suppliers,
"Log10UnsignedLongEvaluator[val=" + read + "]",
DataTypes.DOUBLE,
ul -> Math.log10(ul.doubleValue())
);
TestCaseSupplier.forUnaryDouble(suppliers, "Log10DoubleEvaluator[val=" + read + "]", DataTypes.DOUBLE, Math::log10);
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: this is neat and it's becoming very easy to add quite comprehensive tests to any new function, I like it.

@nik9000 nik9000 added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Aug 28, 2023
@elasticsearchmachine elasticsearchmachine merged commit 4cd7f40 into elastic:main Aug 28, 2023
@nik9000 nik9000 deleted the more_examples branch August 28, 2023 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >docs General docs changes Team:Docs Meta label for docs team Team:QL (Deprecated) Meta label for query languages team v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants