The StreamSQL Editor is provided to assist customers who are migrating projects from earlier StreamBase releases that supported the StreamSQL language. In current StreamBase releases, you can edit StreamSQL but cannot run it in Studio.
To open the StreamSQL Editor, you can:
Double-click an existing StreamSQL file with
.ssqlextension in the Project Explorer.
Click> > > to create a new file.
When the StreamSQL Editor opens, you can begin typing in it just as you would with any text editor. The following screen shows the editor after a line of code is entered. Note that the line is the beginning of a StreamSQL statement, and it includes a deliberate syntax error:
Notice the following editor features in the example:
- Line number
Labels each line in the left yellow column.
- Typecheck error icons
The typecheck icon on the left means that a typecheck error is detected in that line. And in some cases, the error's approximate location in the code (in the example, the word
wrong) is underlined with a wavy red line. If you hover over either of these red typecheck error indicators, StreamBase displays a tooltip containing an error message.
Typecheck errors appear as soon as you start entering code, and any time errors are detected. They remain until all the errors in the module are corrected. The error message in the example (expecting stream) can help you supply the missing StreamSQL keyword. Indeed, the StreamSQL editor's language-awareness is exhibited in several features that can help you write StreamSQL. The following editing helpers are available in the Edit menu (and by using keyboard shortcuts shown in the menu) when you are editing StreamSQL module:
- Content Assistance
Displays a list of StreamSQL keywords and StreamBase functions that you can insert at the cursor. Note that the items in the list may vary depending on your context. Also, StreamSQL cannot help you choose among valid items: that depends on your module's functionality.
For example, in the preceding example, if we delete the word
wrongand the space after
CREATE INPUT, and then press Ctrl+Space, the following pick list appears:
In this example, the pick list is small, indicating that only the keywords shown (and no functions) can be entered at the cursor location. Here the choice is not difficult, but in a different context the Content Assist list may show many more choices of keywords and functions.
In the next screen, we have created an input stream, and entered the name of its first schema field, ITEM_NAME. Now we want to declare the field's data type, which we can do using a simple function. Perhaps we know the function we want, but want to check its exact name or its usage. We have pressed Ctrl+Space to display the Content Assist list, then scrolled down the list and selected the
string()function. A secondary window is displayed, with a description of the function:
Notice that the list provides symbols to distinguish the two types of StreamBase functions:
- Simple functions
Can be used in any StreamBase expression. Note that Heartbeat, Metronome, and Union statements do not use expressions. Simple functions are evaluated over one set of arguments, and return a single result.
strlen()is an example of a simple function.
- Aggregate functions
Are evaluated over groups of arguments (such as the values in tuples being processed in a window) and return a single result.
avg(), which calculates an average value for tuples in an Aggregate window, is an example of an aggregate function
In the next screen, we have finished entering the schema for the first input stream, and then defined two output streams. Now when we press Ctrl+Shift+Space, the top of the Content Assist list provides the names of the streams, and in the secondary window, their schema fields. This makes it easy to insert these names and valued anywhere you need to reference them:
- Parameter Hints
Displays a list of arguments to a function. In this example, we have entered the abs function name, moved the cursor between its open and close parentheses, and pressed Ctrl+Shift+Space. In this case, we could select either a double or an int data type:
- Word Completion
Completes a word you have begun to enter, if possible. The editor attempts to complete StreamSQL keywords and StreamBase functions. It may also recall the names of components (such as streams and fields) that already exist in your module, or that you have used in other modules during the current session . Note that if the editor makes an incorrect completion, you can always correct it.