Skip to content

ESQL: define the tables parameter #2706

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

Merged
merged 11 commits into from
Jul 19, 2024
Merged

ESQL: define the tables parameter #2706

merged 11 commits into from
Jul 19, 2024

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Jul 10, 2024

Adds support for the tables parameter and documents the profile option.

@nik9000
Copy link
Member Author

nik9000 commented Jul 10, 2024

I'm not sure what's up with the failure here. It looks like it doesn't like:

    tables?: Dictionary<
      string,
      Dictionary<string, SingleKeyDictionary<TableValuesType, any>>
    >

The SingleKeyDictionary<TableValuesType, any> doesn't feel quite right, but I'm not sure how tightly you need it here. That could be: {"long": [long|[long]]}/{"int": [int|[int]]}/{"keyword": [string|[string]]}/{"double": [double|[double]]}. But I don't know how to write that.

@flobernd
Copy link
Member

flobernd commented Jul 11, 2024

I would model it like this:

// the naming should probably get improved
export type TableValuesData = long | int | string | double
export type TableValuesDataPayload = TableValuesData | TableValuesData[]
tables?: Dictionary<
   string,
   Dictionary<string, SingleKeyDictionary<TableValuesType, TableValuesDataPayload[]>>
>

Btw: any is invalid in the specification (note the failed validation). Instead, the UserDefinedValue might be used.

@nik9000
Copy link
Member Author

nik9000 commented Jul 11, 2024

Btw: any is invalid in the specification (note the failed validation). Instead, the UserDefinedValue might be used.

Gotcha. I'll do it like you said without any. That's just better and not hard.

@nik9000
Copy link
Member Author

nik9000 commented Jul 11, 2024

@flobernd have a look now!

Copy link
Contributor

Following you can find the validation results for the APIs you have changed.

API Status Request Response
esql.async_query_get 🟠 Missing type Missing type
esql.async_query 🟠 Missing type Missing type
esql.query 🔴 233/233 12/233

You can validate these APIs yourself by using the make validate target.

@nik9000
Copy link
Member Author

nik9000 commented Jul 11, 2024

esql.query

Hey! I was testing that with make validate api=esql.query type=request branch=main locally. That does seem better. Though the response is defined as an ArrayBuffer so I think that should be skipped.

Copy link
Contributor

Following you can find the validation results for the APIs you have changed.

API Status Request Response
esql.async_query_get 🟠 Missing type Missing type
esql.async_query 🟠 Missing type Missing type
esql.query 🔴 233/233 12/233

You can validate these APIs yourself by using the make validate target.

Comment on lines 22 to 37
export interface TableValuesInteger {
integer: TableValuesIntegerValue[]
}
type TableValuesIntegerValue = integer | integer[]
export interface TableValuesKeyword {
keyword: TableValuesKeywordValue[]
}
type TableValuesKeywordValue = string | string[]
export interface TableValuesLong {
long: TableValuesLongValue[]
}
type TableValuesLongValue = long | long[]
export interface TableValuesDouble {
double: TableValuesLongDouble[]
}
type TableValuesLongDouble = double | double[]
Copy link
Member

@flobernd flobernd Jul 16, 2024

Choose a reason for hiding this comment

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

Since these types are mutually exclusive, we should consider modelling them as a container like:

/** @variants container */
export interface TableValues
{
  integer?: integer | integer[]
  keyword?: string | string[]
  long?: long | long[]
  double?: double | double[]
}

Copy link
Member

Choose a reason for hiding this comment

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

Would that work with your code-generators @Anaethelion @l-trotta ?

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 did it this way because you can't specify more than one key in the object. Is that what @container does?

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: for it to be a proper container all the fields should be optional.

To explain further the @container was designed primarily for query in search where the fields you set defines the type of query you use. Thus each QueryContainer can only have one field populated. link to modeling guide

I think it fits the intent.

Copy link
Member

Choose a reason for hiding this comment

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

@nik9000

I did it this way because you can't specify more than one key in the object. Is that what @container does?

Yes, the keys inside the container are mutually exclusive. I updated the above code with the missing optional ? modifier.

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 updated the above code

I don't see a push. I'm willing to make the update myself if you'd like. Just getting out from other stuff.

Copy link
Member

Choose a reason for hiding this comment

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

Oh sorry, I meant the code with the container example in the above comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool. I've pushed some updates.

profile?: boolean
/**
* The ES|QL query API accepts an ES|QL query string in the query parameter, runs it, and returns the results.
*/
query: string
/**
* Tables to use with the LOOKUP operation.
Copy link
Member

Choose a reason for hiding this comment

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

We should probably document the dictionary keys a little bit more in detail. I assume the outer key is the table name and the inner one the column name?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Following you can find the validation results for the APIs you have changed.

API Status Request Response
esql.async_query_get 🟠 Missing type Missing type
esql.async_query 🟠 Missing type Missing type
esql.query 🔴 233/233 12/233

You can validate these APIs yourself by using the make validate target.

Copy link
Member Author

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I've pushed another update based on suggestions.

profile?: boolean
/**
* The ES|QL query API accepts an ES|QL query string in the query parameter, runs it, and returns the results.
*/
query: string
/**
* Tables to use with the LOOKUP operation.
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Following you can find the validation results for the APIs you have changed.

API Status Request Response
esql.async_query_get 🟠 Missing type Missing type
esql.async_query 🟠 Missing type Missing type
esql.query 🔴 233/233 12/233

You can validate these APIs yourself by using the make validate target.

import { double, integer, long } from '@_types/Numeric'

/** @variants container */
export interface TableValues {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export interface TableValues {
export interface TableValueContainer {

Just a naming suggestion to be consistent with the existing specification, LGTM otherwise!

Copy link
Member

Choose a reason for hiding this comment

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

(or TableValuesContainer - not sure if singular or plural makes more sense here)

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 think plural does. I'll make the change.

* Tables to use with the LOOKUP operation. The top level key is the table
* name and the next level key is the column name.
*/
tables?: Dictionary<string, Dictionary<string, TableValues>>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tables?: Dictionary<string, Dictionary<string, TableValues>>
tables?: Dictionary<string, Dictionary<string, TableValueContainer>>

Copy link
Contributor

Following you can find the validation results for the APIs you have changed.

API Status Request Response
esql.async_query_get 🟠 Missing type Missing type
esql.async_query 🟠 Missing type Missing type
esql.query 🔴 233/233 12/233

You can validate these APIs yourself by using the make validate target.

Copy link
Contributor

Following you can find the validation results for the APIs you have changed.

API Status Request Response
esql.async_query_get 🟠 Missing type Missing type
esql.async_query 🟠 Missing type Missing type
esql.query 🔴 233/233 12/233

You can validate these APIs yourself by using the make validate target.

@nik9000 nik9000 enabled auto-merge (squash) July 18, 2024 14:49
@nik9000 nik9000 requested a review from flobernd July 18, 2024 14:49
@nik9000
Copy link
Member Author

nik9000 commented Jul 18, 2024

Renamed. I've marked this auto-merge because I think that's what we want. I think I'm waiting on a final review.

Copy link
Contributor

Following you can find the validation results for the APIs you have changed.

API Status Request Response
esql.async_query_get 🟠 Missing type Missing type
esql.async_query 🟠 Missing type Missing type
esql.query 🔴 233/233 12/233

You can validate these APIs yourself by using the make validate target.

Copy link
Member

@flobernd flobernd left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the effort 🙂

@nik9000 nik9000 merged commit a003a41 into main Jul 19, 2024
6 checks passed
@nik9000 nik9000 deleted the define_tables branch July 19, 2024 10:02
@nik9000
Copy link
Member Author

nik9000 commented Jul 19, 2024

Thanks for the feedback folks!

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

Successfully merging this pull request may close these issues.

3 participants