kdb Visual Studio Code extensionThe kdb Visual Studio Code extension provides developers with an extensive set of features that enables them to create and edit q files, connect to multiple kdb processes, and execute queries. This extension can be used with kdb Insights Enterprise when using a shared kdb process. ContentsThis guide provides information on the following:
Benefits of kdb VS Code ExtensionWith the kdb VS Code extension you can:
Getting StartedTo get started you must do the following: Installing kdb VS Code ExtensionThis section assumes you have already installed VS Code. Install the kdb VS Code extension by clicking Install on this page.
Once the kdb VS Code extension is installed KX appears in the Activity Bar on the left-hand side and when it is selected the following views are displayed in the primary sidebar: Note Customized authentication has been implemented for the kdb VS Code extension, allowing you to add custom logic when authenticating with kdb. Refer to customized authentication for details on how to set this up. Installing qAfter you install kdb VS Code extension, if q is not already installed the extension provides a seamless integration with q, by displaying a notification with an option to download, register and install kdb Insights Personal Edition. For details on the other versions available see here.
Once registered you will receive an email with you license details. The base64 encoded license string can be found in the welcome email received after registration, under the download link for the license file. With your license details to hand, you can link this to VS Code by either choosing Paste license string or Select license file from your PC. The latter method is recommended for new users. The To finish, a prompt is offered with an opt-in to receive a newsletter. Using q outside of VS CodeIf you want to use q outside of VS Code, set a If q is installed at Versions availableThere are commercial and non-commercial editions available. We recommend you start with the kdb+ Personal Edition or kdb Insights Personal Edition. The following table lists the editions with links to downloads and the functionality they support.
After registering for your chosen version, you will receive an email with a link to download an installation file and a ConnectionsThe kdb VS Code extension allows you to have multiple connections open at once, enabling development and testing across different q and kdb Insights Enterprise connections using both q and Python. To add connections:
Bundled qWhen you select Bundled q as the connection type and set the following properties:
If you close the extension, the connection to the child q process also closes. My qWhen you select My q as the connection type, identify the remote location of a running process. The hostname and port are required along with any authentication information. Set the following properties:
If you close the extension, the connection also closes. Insights ConnectionWhen you select Insights connection as the connection type, the kdb VS Code extension uses a shared kdb process. You must have kdb Insights Enterprise Personal Edition running before using connections of this type. Set the following properties:
Set the following from the Advanced properties if necessary:
Note For kdb Insights Enterprise Free Trial instances the realm is configured as
If you close the extension, the connection also closes. MetaWhen connected Insights connections can be expanded to show the details returned by the getMeta API call, which provides information on the database schemas and all the analytics available. To see the results of the getMeta call click on the 'meta' node under the connection. A json representation of the details returned by the call are displayed with "[Connection Name] - meta" as title of the tab. The 'meta' node contains a child node for each of the child sections in the json. To see a json representation of a specific section click on the child node. The json representation of this section returned by the call is displayed with "[Connection Name] - [CHILD SECTION]" as title of the tab. You can refresh the meta data view at any time by choosing Refresh meta data from the right-click menu of an Insights connection. Edit ConnectionsTo edit an existing connection, right-click the connection you wish to edit and select the Edit connection option.
Edit Bundle q connectionWhen editing a Bundled q connection, you can edit the following properties:
Edit My q connectionWhen editing a My q connection, you can edit the following properties:
Edit Insights connectionWhen editing a Insights connection, you can edit the following properties:
Import/Export Connection ConfigurationThe Import/Export Connection config allows you to import and export connections in JSON format from the VSCode IDE without having to create them manually. To import a connection:
To connect to the database, select the newly imported connection from the list of available connections and initiate the connection to the database. You can run a simple query or command to verify the connection is successful. Note: If the imported connection has the same name as an existing connection, you will see a notification in the bottom right corner prompting you to either duplicate, overwrite, or cancel the import. To export a connection:
To verify the export is successful navigate to the saved location and open the configuration file to check its contents. Important to note! When exporting a connection configuration, the password and username are not included in the export file. Upon importing the connection, you are prompted to enter the login details to re-establish the connection. This was introduced as a best practice as exporting credentials introduces significant security risks. Connection LabelsConnection Labels allow you to categorize and organize your connections by assigning them distinct names and colors, making it easier to manage and locate specific connections within the application. Connections are organized in alphabetical order, with connections first sorted by type, then by label within each type, and finally, if there are multiple connections under a label, those are also listed alphabetically. Create New LabelTo create a Label, start by editing or creating a connection. At the bottom of the form, you'll see a Create New Label button. A dialog opens where you can enter a Label name and choose a Label color. Create the Label by clicking Create or cancel the process by clicking Cancel.
Add Label to a connectionTo add a Label to a connection, start by editing or creating a connection. At the bottom of the form, you'll see a Label Name dropdown to select a Label, select the Label and click in Edit or Create Connection.
Rename LabelRight-click the label at Connection Tree and select Rename label. A prompt is displayed at the top of the screen where you can edit the name of the Label. Edit Label ColorRight-click the label at Connection Tree and select Edit label color. A prompt is displayed at the top of the screen where you can edit the color of the Label. Delete LabelRight-click the label at Connection Tree and select Delete label.
kdb language serverA kdb language server is bundled with the kdb VS Code extension. It offers various common features to aid in the development of kdb code, including: Syntax highlightingThe extension provides keyword syntax highlighting, comments and linting help. Linting can be enabled by checking Enable linting for q and quke files in extension settings. Semantic highlighting is provided for local variables: Code navigationWhile developing q scripts you can:
Code Completion
Rename Symbol
Execute codeLeaning on VS Code's extensive integrations with SCMs, all code is typically stored and loaded into a VS Code workspace. From there, the kdb VS Code extension allows you execute code against both kdb processes, and kdb Insights Enterprise endpoints. kdb process executing q and Python codeFor any file with a .q or .py extension there are additional options available from the right-click menu for executing code:
When executing Python code against kdb+ connections, note the following:
Insights query executionkdb Insights Enterprise offers enhanced connectivity and enterprise level API endpoints, providing additional means to query data and interact with kdb Insights Enterprise that are not available with standard kdb processes. You must have an instance of kdb Insights Enterprise running, and have created a connection within the kdb VS Code extension. Similarly, you can execute arbitrary code against kdb Insights Enterprise. The code is executed on a user-specific scratchpad process within the kdb Insights Enterprise deploy. The scratchpad is instantiated upon the first request to execute code when connected to a kdb Insights Enterprise connection. It remains active until timed out or until you log out. Concurrent code execution and queryingWithin each tier, multiple processes are available to handle queries, ensuring that queries can be run simultaneously across these processes. For example, if the RDB tier has three processes (process 0, process 1, process 2), and the specific replica is not being targeted the queries are directed to whichever process is available, allowing multiple users to execute their queries in parallel. As soon as a process becomes available, it handles the next incoming query, ensuring efficient resource utilization and minimal delays. kdb VSCode allows users to execute code on a specific Data Access Process (DAP). That allows you to target specific replicas within the RDB, IDB, and HDB tiers when executing queries. To select a replica for query execution, simply choose the desired tier (RDB, IDB, HDB) and then select the specific replica from the list of available options, such as When connecting to a kdb Insights server version 1.14.2 or higher, you can see detailed information about the available replicas for each database (RDB, IDB, HDB). This allows you to choose a specific replica for your query. The list includes specific targeting of replicas and looks similar to the example below:
If you are connecting to an older kdb Insights version (1.14.1 or lower), replica information is not available. However, you can still run queries on a general group of databases (RDB, IDB, HDB), but don’t have the option to target a specific replica. This ensures that the feature works even if you are using older versions of Insights. Data sourcesKX data source files allow you to build queries within VS Code, associate them with a connection and run them against the kdb Insights Enterprise API endpoints. These are workspace specific files that have the following features:
The data source screen helps you to build a query, based on the available API on your instance of kdb Insights Enterprise, parameterize it and return the data results to the output or kdb results window. To create a data source and run it against a specific connection:
In addition to API queries, if the query environment is enabled on the deployed instance of kdb Insights Enterprise, qSQL and SQL queries can be used within a data source with the appropriate parameterization. If qSQL or SQL is required and issues occur trying to run these queries contact a kdb Insights Enterprise administrator for assistance. API queriesThe getData API provides a method of querying a table using a defined set of parameters. These parameters can be configured through the getData form available in the VSCode extension. Refer to the QSQL queriesThe This function runs an QSQL query.
Note: Along with the query itself, you must also specify the target database and you can choose to specify the database tier and specific data access process if required. Refer to the QSQL documentation for more details. Warning! Starting with kdb Insights Enterprise version 1.13, QSQL queries and populating QSQL only work if the Query Environment (QE) is enabled. Ensure you have enabled QEs to use QSQL; they are disabled by default in kdb Insights Enterprise from version 1.13 onwards. Refer to Query Environments for more details. SQL queriesThe This function runs an SQL query.
You can run SQL files against any kdb Insights Enterprise connections and select to populate the Scratchpad if you wish. Refer to the SQL documentation for more details. UDA queriesUser-Defined Analytics (UDAs), also known as custom APIs, are essential for developers to leverage the capabilities of kdb when using Insights Enterprise. These UDAs are deployed to Insights through the Data Access Processes (DAPs) and Aggregators (Aggs). UDAs can be called directly within the VSCode extension through the UDA tab in a data source. This provides a form-based approach to populating the UDA parameters. UDAs can also be called within the Insights Enterprise web interface using Pipelines, Queries, and Views. When interacting with UDAs, parameter fields are shown for configuration. Note the following:
You can add new parameters by clicking Add Parameter. Both optional and distinguished parameters can be added as needed. Important! A UDA cannot be queried if one or more parameters are invalid. If you attempt to run a UDA with invalid parameters, an error occurs and a pop-up message appears to alert you to the issue. In some cases, you can successfully query UDAs without any parameters, as seen in the screenshot below. However, you can still modify the parameter list to add parameters by clicking Add parameter or deleting parameters using the recycle bin icon. For more information on User-Defined Analytics, refer to the UDAs documentation. Run and populate scratchpadRunning and populating scratchpad are two actions used to execute q code, allowing you to run queries and perform operations on your kdb Insights Enterprise database but they differ in how and where the output is stored and accessed. The QSQL API is designed to run queries against a specific Insights database and tier. However, sometimes you might need to run more flexible or freeform queries against a wider set of data. For this purpose each Insights Enterprise user is assigned a 'scratchpad' q process. This scratchpad is separate from the dedicated query processes, allowing you to run freeform code without impacting the overall system. You can populate variables in your scratchpad with the results from your queries, and then perform freeform manipulations on those variables. After you configure a data source in the VSCode extension you have two options for executing it:
For more details on populating scratchpad, refer to the populate scratchpad section below. Populate scratchpadYou can use a data source to populate a scratchpad process running in a kdb Insights Enterprise instance with a dataset. This allows you to then execute q or python code against the data stored in that variable in the scratchpad. This facilitates the generation of complex APIs and pipelines within VS Code and kdb Insights Enterprise. To do this:
Reset scratchpadThe Reset Scratchpad option in kdb VS Code allows you to delete all the data from a connected instance and restart your development from scratch. There are several ways to reset the scratchpad:
Workbooks and source fileskdb Insights Enterprise supports two modes of interactive code development in Visual Studio Code: Workbooks and Source Files. Both enable you to write and execute q and Python code against running kdb+ processes, but they offer different workflows and behaviors. WorkbooksWorkbooks provide a convenient way to prototype and execute q and Python code. q Workbooks can execute against scratchpad or any available DAP in kdb Insights, while Python Workbooks are limited to scratchpad only. Key features of Workbooks:
To create a Workbook, either create a Create a Workbook using the WORKBOOKS panel and run code against a specific connection, as follows:
When you save a workbook file, the code and the connection details are stored. The workbook icon is green if it is associated with a connection and grey if there is no association. You can also change the connection associated with a workbook at any time by clicking on the connection from above the first line of code in the workbook file. Source filesRegular You can run code on either the scratchpad or directly on DAP processes — such as RDB or HDB — without needing to copy/paste or switch between special file types. Key differences:
Key features of standard source files:
This eliminates the need to copy code from files into the qSQL Data Source tab or Workbooks for testing against DAPs. For selecting connections and endpoints for unassociated files, consider the following:
For associated files, take into account the following:
KX Notebooks in Visual Studio CodeKX Notebooks provide an interactive environment within VS Code that allows you to compose and execute Q, Python, and Markdown code blocks in a single notebook, making development and testing more straightforward. You can easily create, edit, and share KX Notebooks, allowing for better collaboration. Create a notebookTo create a new notebook, open the Command Palette ( From this view, you can add either Markdown or Code blocks to the notebook by clicking the toolbar buttons. In KX Notebooks, you can select a target and a variable name to populate the Scratchpad. When you select a connection, clicking on the Scratchpad tab displays a list where you can change between the Scratchpad and one of the database tiers (RDB, IDB, or HDB) or a specific database process on one of the tiers. Next to the Scratchpad tab, there is a language option. To change the language of the code block, click on the language labels and select language from the Command Palette. You can select between q, Python, Markdown, or MS SQL. When selecting a variable, the default option is (none). You can click on (none) and enter a variable name, such as Execute code blocksCode blocks are executed using the active KX connection, and the results are displayed inline next to the code block. The execution state is preserved across code blocks, similar to Jupyter notebooks, allowing for progressive data analysis. You can run SQL queries on a tier and populate the Scratchpad with the SQL results. This functionality connects to the Q SQL endpoint and imports the data into the Scratchpad as a variable. KX Notebooks detect GGPlot2 outputs. If the execution generates a plot, it is displayed inline for both q and PyKX. Sample notebooks are available on Developer Wiki. Query HistoryThe Query History view in the primary sidebar captures each query execution and enables you to re-run any of the queries listed. Initially the query history view is empty but once you run a query it is captured and displayed in the window - with a separate row displayed for every execution. All information is stored in memory and not persisted upon application exit. Rows consists of the following:
Right-clicking on a history row brings up a menu with the option to Rerun query. View resultsAll query executions happen remotely from the kdb VS Code extension either against a running q process or against your user-specific scratchpad process in kdb Insights Enterprise. The results, successful or otherwise, are returned to VS Code in one of the following windows:
AxLibrariesThe following features of AxLibraries are integrated and can be used within the extension:
Note: To use those features, you should install AxLibraries following the installation instructions. Grammar of GraphicsGrammar of Graphics (GG) is a scripted visualization library for kdb+. GGPlot2 in VSCode allows you to create detailed and informative visualizations, helping you understand the underlying patterns and trends in your data more clearly without having to switch to RStudio. For more information refer to the GGPlot documentation. To use GGPlot2 in VSCode:
You can make changes to the script before exporting the plot. Re-running the script updates to reflect the changes. Note: When executing GG script commands, select the REPLREPL stands for Read-Eval-Print Loop, which is an interactive programming environment used in many languages. REPLs are particularly useful for interactive development, debugging, and testing because users can write and run code snippets in real-time, seeing immediate feedback. REPL can be started from the command prompt by searching >repl. Important! Before running code in the REPL interactive terminal, ensure that your Q Home Directory is correctly configured in VSCode. This setting is required to set up the q runtime environment for the interactive terminal. To configure the Q Home Directory, go to VSCode Settings > Extension > kdb and enter the path for the To execute a q file in REPL:
The results are shown in the terminal and you can continue to work either in your q file or directly in the terminal. Refer to the REPL shortcuts table for information on the keyboard shortcuts you can use. LogsAny error or info is posted at OUTPUT in kdb tab The format is:
SettingsTo update kdb VS Code settings, search for kdb from Preferences > Settings, or right-click the settings icon in kdb VS Code marketplace panel and choose Extension Settings.
RefactoringBy default, refactorings like renaming are applied to all files in the workspace. You can preview the changes before applying them and select specific files to apply the refactoring by pressing the ctrl or command key before executing the action. If you only need to apply the refactorings to the currently opened files, you can select Window instead of Workspace for the refactoring option: kdb Insights Enterprise Connections for Explorer
Servers
Double Click SelectionThe following setting changes double click behavior to select the whole identifier including dots:
Auto focus output on entryThis setting automatically focuses the output console when running a query without an active results tab or receive log entry. This means that, when the setting is enabled, executing a query shows the q console in the output window even if the q console is not open in the output window. You can disable this option at any time in Settings if you do not want to auto-focus. Help and feedbackA Help and Feedback view is displayed in the primary sidebar of the kdb VS Code extension. This includes links to:
User feedback notificationYou may also see a prompt inside VS Code inviting you to provide feedback. This system notification appears after a few uses of the extension and helps us improve your experience. You can dismiss it or opt out permanently if preferred. If you choose to opt out permanently but wish to revert this, open VS Code settings, search for survey, and check the Hide Survey option, as shown below. ShortcutsFor Windows
For MacOS
Data and telemetryThe KX kdb Extension for Visual Studio Code collects usage data and sends it to KX to help improve our products and services. Read our privacy statement to learn more. This extension respects the telemetry.enableTelemetry setting which you can learn more about at https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting. |