-
Notifications
You must be signed in to change notification settings - Fork 102
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
MLDB-1829 jseval rows #548
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -639,7 +639,7 @@ The SQL function `jseval` allows for the inline definition of functions using Ja | |
|
||
1. A text string containing the text of the function to be evaluated. This | ||
must be a valid Javascript function, which will return with the `return` | ||
function. For example, `return x + y`. This must be a constant string, | ||
keyword. For example, `return x + y`. This must be a constant string, | ||
it cannot be an expression that is evaluated at run time. | ||
2. A text string containing the names of all of the parameters that will be | ||
passed to the function, as they are referred to within the function. For | ||
|
@@ -649,13 +649,21 @@ The SQL function `jseval` allows for the inline definition of functions using Ja | |
any SQL expressions and will be bound to the parameters passed in to the | ||
function. | ||
|
||
There are two ways that values in arguments can be represented in Javascript: | ||
simplified (the default), and a non-simplified representation that is accessed | ||
by adding a `!` character to the parameter name argument (for example, `!x,y` | ||
instead of `x,y`). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ouf. Mes soucis se froncent. Utiliser le "!" ce qui veut généralement dire "not"? Je ne dis pas que c'est mauvais, je me demande si on est certain que c'est la bonne chose à faire. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Une alternative serait un nom de fonction différent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moi aussi j'ai sourcillé en voyant le "!"... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The goal was to avoid breaking existing uses of jseval, without cluttering up the syntax. Should we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just add an optional parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The js way:
Je pense que c'est la meilleure solution jusqu'à maintenant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn't work because it is possible to pass more than one argument to jseval There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right... From the doc
Then we are back to the alternate function name. |
||
|
||
### Simplified arguments | ||
|
||
The result of the function will be the result of calling the function on the | ||
supplied arguments. This will be converted into a result as follows: | ||
|
||
- A `null` will remain a `null` | ||
- A Javascript number, string or `Date` will be converted to the equivalent | ||
MLDB number, string or timestamp; | ||
- An object (dictionary) will be converted to a row | ||
- An object (dictionary) or array will be converted to a row, with each | ||
element represented as a `[column name, value, timestamp]` tuple. | ||
|
||
In all cases, the timestamp on the output will be equal to the latest of the | ||
timestamps on the arguments passed in to the function. | ||
|
@@ -695,3 +703,16 @@ log to the console to aid debugging. Documentation for this object can be found | |
|
||
You can also take a look at the ![](%%nblink _tutorials/Executing JavaScript Code Directly in SQL Queries Using the jseval Function Tutorial) for examples of how to use the `jseval` function. | ||
|
||
### Non-simplified arguments | ||
|
||
If the first character of the argument string is `!`, then non-simplified | ||
arguments are used. These are harder to work with in Javascript, but allow | ||
for the entire set of values in MLDB to be represented, especially structured | ||
values or those with repeated columns or multiple timestamps per value. | ||
|
||
For example, the following query yields the same as `(SELECT x:1, y:2)`, | ||
in other words it doesn't mess around with the values: | ||
|
||
```sql | ||
SELECT jseval('return row;', '!row', {*}) AS * FROM (SELECT x:1, y:2)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example seems artificial. If it is, I would consider adding an example that is more realistic (e.g. the use case that forces us to add the non-simplified argument). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an artificial example, but it's also that only way to return a real structure from jseval. We can add a better use-case. |
||
``` |
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.
Consider adding a link to the description of simplified arguments.