Skip to content

Commit 77abb61

Browse files
committed
fix table and minor edits
1 parent b953611 commit 77abb61

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

articles/stream-analytics/stream-analytics-javascript-user-defined-functions.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,48 @@ ms.date: 03/23/2020
1717
Azure Stream Analytics supports user-defined functions written in JavaScript. With the rich set of **String**, **RegExp**, **Math**, **Array**, and **Date** methods that JavaScript provides, complex data transformations with Stream Analytics jobs become easier to create.
1818

1919
## Overview
20-
JavaScript user-defined functions support stateless, compute-only scalar functions that do not require external connectivity. The return value of a function can only be a scalar (single) value. After you add a JavaScript user-defined function to a job, you can use the function anywhere in the query, like a built-in scalar function.
20+
21+
JavaScript user-defined functions support stateless, compute-only scalar functions that don't require external connectivity. The return value of a function can only be a scalar (single) value. After you add a JavaScript user-defined function to a job, you can use the function anywhere in the query, like a built-in scalar function.
2122

2223
Here are some scenarios where you might find JavaScript user-defined functions useful:
2324
* Parsing and manipulating strings that have regular expression functions, for example, **Regexp_Replace()** and **Regexp_Extract()**
2425
* Decoding and encoding data, for example, binary-to-hex conversion
25-
* Performing mathematic computations with JavaScript **Math** functions
26-
* Performing array operations like sort, join, find, and fill
26+
* Doing mathematic computations with JavaScript **Math** functions
27+
* Doing array operations like sort, join, find, and fill
2728

28-
Here are some things that you cannot do with a JavaScript user-defined function in Stream Analytics:
29-
* Call out external REST endpoints, for example, performing reverse IP lookup or pulling reference data from an external source
29+
Here are some things that you can't do with a JavaScript user-defined function in Stream Analytics:
30+
* Call out external REST endpoints, for example, doing reverse IP lookup or pulling reference data from an external source
3031
* Perform custom event format serialization or deserialization on inputs/outputs
3132
* Create custom aggregates
3233

33-
Although functions like **Date.GetDate()** or **Math.random()** are not blocked in the functions definition, you should avoid using them. These functions **do not** return the same result every time you call them, and the Azure Stream Analytics service does not keep a journal of function invocations and returned results. If a function returns different result on the same events, repeatability is not guaranteed when a job is restarted by you or by the Stream Analytics service.
34+
Although functions like **Date.GetDate()** or **Math.random()** aren't blocked in the functions definition, you should avoid using them. These functions **don't** return the same result every time you call them, and the Azure Stream Analytics service doesn't keep a journal of function invocations and returned results. If a function returns different result on the same events, repeatability isn't guaranteed when a job is restarted by you or by the Stream Analytics service.
3435

3536
## Add a JavaScript user-defined function to your job
37+
3638
> [!NOTE]
3739
> These steps work on the Stream Analytics jobs configured to run in the cloud. If your Stream Analytics job is configured to run on Azure IoT Edge, instead use Visual Studio and [write the user-defined function using C#](stream-analytics-edge-csharp-udf.md).
3840
3941
To create a JavaScript user-defined function in your Stream Analytics job, select **Functions** under **Job Topology**. Then, select **JavaScript UDF** from the **+Add** dropdown menu.
42+
4043
![Add JavaScript UDF](./media/javascript/stream-analytics-jsudf-add.png)
4144

4245
You must then provide the following properties and select **Save**.
46+
4347
|Property|Description|
4448
|--------|-----------|
4549
|Function alias|Enter a name to invoke the function in your query.|
4650
|Output type|Type that will be returned by your JavaScript user-defined function to your Stream Analytics query.|
47-
|Function defintion|Implementation of your Javascript function that will be executed each time your UDF gets invoked from your query.|
51+
|Function definition|Implementation of your JavaScript function that will be executed each time your UDF gets invoked from your query.|
4852

4953
## Test and troubleshoot JavaScript UDFs
54+
5055
You can test and debug your JavaScript UDF logic in any browser. Debugging and testing the logic of these user-defined functions is currently not supported in the Stream Analytics portal. Once the function works as expected, you can add it to the Stream Analytics job as mentioned above and then invoke it directly from your query. You can test your query logic with JavaScript UDF using [Stream Analytics tools for Visual Studio](https://docs.microsoft.com/azure/stream-analytics/stream-analytics-tools-for-visual-studio-install).
5156

5257
JavaScript runtime errors are considered fatal, and are surfaced through the Activity log. To retrieve the log, in the Azure portal, go to your job and select **Activity log**.
5358

5459
## Call a JavaScript user-defined function in a query
55-
You can easily invoke your JavaScript function in your query using the function alias prefixed with **udf.**. Here is an example of a JavaScript UDF which converts hexadecimal values to integer being invoked in a Stream Analytics query.
60+
61+
You can easily invoke your JavaScript function in your query using the function alias prefixed with **udf**. Here is an example of a JavaScript UDF that converts hexadecimal values to integer being invoked in a Stream Analytics query.
5662

5763
```SQL
5864
SELECT
@@ -65,6 +71,7 @@ You can easily invoke your JavaScript function in your query using the function
6571
```
6672

6773
## Supported JavaScript objects
74+
6875
Azure Stream Analytics JavaScript user-defined functions support standard, built-in JavaScript objects. For a list of these objects, see [Global Objects](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects).
6976

7077
### Stream Analytics and JavaScript type conversion
@@ -93,11 +100,12 @@ Array | Array
93100
Null, Undefined | NULL
94101
Any other type (for example, a function or error) | Not supported (results in runtime error)
95102

96-
JavaScript language is case sensitive and casing of the object fields in JavaScript code must match the casing of the fields in the incoming data. Please note that jobs with compatibility level 1.0 will convert fields from SQL SELECT statement to be lowercase. Under compatibility level 1.1 and higher, fields from SELECT statement will have the same casing as specified in the SQL query.
103+
JavaScript language is case-sensitive and casing of the object fields in JavaScript code must match the casing of the fields in the incoming data. Jobs with compatibility level 1.0 will convert fields from SQL SELECT statement to be lowercase. Under compatibility level 1.1 and higher, fields from SELECT statement will have the same casing as specified in the SQL query.
97104

98105
## Other JavaScript user-defined function patterns
99106

100107
### Write nested JSON to output
108+
101109
If you have a follow-up processing step that uses a Stream Analytics job output as input, and it requires a JSON format, you can write a JSON string to output. The next example calls the **JSON.stringify()** function to pack all name/value pairs of the input, and then write them as a single string value in output.
102110

103111
**JavaScript user-defined function definition:**

0 commit comments

Comments
 (0)