Introduction

Data processing is one of the critical components of enterprise integration. Even though there are various approaches to process data, query expressions are usually considered the go-to approach. Language integrated queries specify the logic in SQL-like syntax to process the data/events, and they are easy to write and understand due to the simplicity of the syntax. The Ballerina programming language provides first-class support to write queries for data processing. In this article, we will discuss the query language support in Ballerina with some examples.

As of now, language integrated queries are supported for iterator implementations such as an array, map, stream, and table. There are two kinds of integrated queries that can be written in Ballerina — query expression, which allows generating a list, table, string or XML; stream and query action, which executes a set of statements for each element of the iterator.

Query Expressions

Query expressions contain a set of clauses similar to SQL to process the data. Query expressions must start with the from clause and can perform various operations such as filter, join, sort, limit, and projection. There are various SQL like clauses to perform these operations.

Query Clauses

  • from clause - Defines an input source/iterator
  • _where_ clause - Defines a filtering condition
  • _let_ clause - Defines a variable that could be used in the subsequent clauses
  • _join_ clause - Defines an input source/iterator for joining purposes. It performs an inner or left outer equijoin.
  • _order by_ clause - Defines the sorting logic
  • _limit_ clause - Limits the number of elements passed to the next clause
  • _select_ clause - Performs the projection. Outputs a list, table, string, XML, or stream.
  • _on conflict_ clause - Allows only for a query expression that constructs a table with a key sequence to avoid duplicates

#integration #sql #data processing #ballerina #data-science

Language Integrated Queries In Ballerina
1.35 GEEK