Swan Lake Preview 3

Overview of Ballerina Swan Lake Preview 3

This release is the third preview version of Ballerina Swan Lake. This release includes a new set of language features along with improvements and bug fixes to the compiler, runtime, standard libraries, and developer tooling.

You can use the update tool to update to Ballerina Swan Lake Preview 3 as follows.

For existing users:

If you are already using jBallerina, you can directly update your distribution to the Swan Lake channel using the Ballerina update tool. To do this, first, execute the command below to get the update tool updated to its latest version.

ballerina update

Next, execute the command below to update to Swan Lake Preview 3.

ballerina dist pull slp3

However, if you are using a jBallerina version below 1.1.0, install via the installers.

For new users:

If you have not installed jBallerina, then download the installers to install.

Highlights

  • Support for defining external object method bodies
  • Order by clause for sorting
  • Inner/Nested query expressions
  • Support for executing stored procedures in the SQL connector
  • Azure Functions support

What's new in Ballerina Swan Lake Preview 3

Language

The language implementation is based on Ballerina Language Specifications Draft 2020-06-18.

External object method bodies

This release introduces support for defining object methods with external function bodies.

The Java method to which the getFullName() method is bound:

Order by clause for sorting

This release introduces the order by clause support for sorting in query expression/action. An order-by clause is executed by constructing a list of entries.

Inner/Nested query expressions

This release introduces the support to write inner/nested query expression/action.

Standard library

SQL connectors

Stored procedures can now be executed through SQL connectors (JDBC & MySQL).

Module organization

The ballerina/nats library was moved to Ballerina Central. Previously, this module was packed in the Ballerina distribution. With this change, this library can now be released independently.

Developer tools

Language server
Introducing AI-based Data Mapping code action

Two record types can now be mapped automatically using the Data Mapping code action. Once a possible record mapping instance is identified, it suggests a mapping based on an AI algorithm. A mapping function will be generated automatically and added to the workspace to perform the record mapping.

The following is a sample in which the code action to generate a mapping function will appear when attempting to assign a mapping value to a variable of a type that is not directly assignable.

By choosing the Generate mapping functioncode action, the following function will be added to the workspace.

Furthermore, the line with the error would be replaced with a function call as shown below.

For more information, see Code Actions.

Test framework
Support single test execution

A single test function or a set of functions can now be executed using the --tests flag as follows.

API change in assertEquals and assertNotEquals functions

Deep value equality is supported only for anydata-typed values according to the language specification. The assertEquals function has been changed to accept only anydata-typed values to reflect this behavior.

Introduction of the assertExactEquals and assertNotExactEquals functions

The assertExactEquals function compares two values to assert whether they refer to the same entity (i.e., they are exactly equal).

Introduction of the @test:BeforeGroups and @test:AfterGroups functions

These two new annotations can now be used when writing tests with the Ballerina test framework.

Introduction of the alwaysRun field to the @test:AfterSuite annotation

You can now specify alwaysRun : true|false in the @AfterSuite annotation, which enables running the @AfterSuite even if the @BeforeSuite function fails during the test execution. The default value is false.

Code to Cloud

Azure Functions support

Ballerina now supports writing serverless functions using the Azure Functions framework.

For more information, see Azure Functions.