Warum Kafka in der Cloud mit Confluent 10x besser ist | Kostenloses E-Book erhalten

Announcing ksqlDB 0.26

Get started with Confluent, for free

Watch demo: Kafka streaming in 10 minutes

Verfasst von

We are excited to bring forward yet another ksqlDB release with ksqlDB 0.26. This time we have focused on improving your experience with aggregate functions, JOINs, and schemas. We have also improved the way we handle dereferencing when working with structs. Read below to find out in more detail about the changes and check out the changelog for a full list of updates.

Aggregate functions

Our customers make use of our built-in aggregate functions to transform columns into new values. In the ksqlDB 0.26 release, we extend MIN and MAX aggregates, two of our most heavily used functions, to natively support DATE, TIME, and TIMESTAMP types.

Users can now perform Min and Max aggregations without the need for extra casting:

CREATE STREAM assignments (department STRING, Person Struct<Name String, Age Integer>) WITH (kafka_topic='assignments', value_format='json', partitions=1);

CREATE STREAM orders (id STRING, ts TIME) WITH (kafka_topic='orders_topic', value_format='json', partitions=1)

INSERT INTO orders (id, ts) VALUES (‘order_125346’, 1651765570); INSERT INTO orders (id, ts) VALUES (‘order_125346’, 1635724801));

SELECT id, max(ts) as value FROM orders group by id;

+-------------------------------------------+--------------------------------------------------------+ |ID |VALUE | +-------------------------------------------+--------------------------------------------------------+ |order_125346 |1651765570 |

Improvements to joins

This release adds support for Stream-Stream and Table-Table RIGHT OUTER JOIN. RIGHT OUTER JOIN returns all records for the right side of the join and the matching records from the left side. If the matching records on the left side are missing, the corresponding columns will contain null values. See the example below.

Create two tables:

CREATE TABLE movies (
      title VARCHAR PRIMARY KEY,
      id INT,
      release_year INT
    ) WITH (
      KAFKA_TOPIC='movies',
      PARTITIONS=1,
      VALUE_FORMAT='JSON'
    );

CREATE TABLE lead_actor ( title VARCHAR PRIMARY KEY, actor_name VARCHAR ) WITH ( KAFKA_TOPIC='lead_actors', PARTITIONS=1, VALUE_FORMAT='JSON' );

</pre>
<p>Insert records:</p>
<pre>INSERT INTO movies (id, title, release_year) VALUES (256, 'Citizen Kane', 1941);
INSERT INTO movies (id, title, release_year) VALUES (294, 'Die Hard', 1998);
INSERT INTO MOVIES (id, title, release_year) VALUES (128, 'The Big Lebowski', 1998);


INSERT INTO lead_actor (title, actor_name) VALUES ('Citizen Kane', 'Orson Welles');
INSERT INTO lead_actor (TITLE, ACTOR_NAME) VALUES ('The Big Lebowski','Jeff Bridges');
</pre>
<p>Note that we did not insert the actor record for Die Hard to illustrate the behavior of RIGHT OUTER JOIN. Let&#8217;s run a query now:</p>
<pre>SELECT m.id, m.title, m.release_year, l.actor_name
FROM lead_actor l
RIGHT JOIN movies m
ON l.title = m.title
EMIT CHANGES
LIMIT 3;


+--------------------------+--------------------------+-------------------------------+-----------------------------------+
|ID                        |M_TITLE                   |RELEASE_YEAR                   |ACTOR_NAME                         |
+--------------------------+--------------------------+-------------------------------+-----------------------------------+
|256                       |Citizen Kane              |1941                           |Orson Welles                       |
|294                       |Die Hard                  |1998                           |null                               |
|128                       |The Big Lebowski          |1998                           |Jeff Bridges                       |
Limit Reached
Query terminated
</pre>
<p>You can find more details about the semantics of Stream-Stream and Table-Table RIGHT JOINs in the <a href="https://docs.ksqldb.io/en/latest/developer-guide/joins/join-streams-and-tables/" target="_blank" rel="noopener">joining collections</a> documentation page.</p>
<h2>Support explicit message types for Protobuf with multiple definitions</h2>
<p>Confluent Schema Registry lets one manage the schemas across an enterprise using JSON Schema, Avro, or Protobuf formats. In this release, ksqlDB’s ability to use Protobuf schemas has been enhanced.</p>
<p>A single Protobuf schema definition can define multiple schemas which can be selected individually or reference each other. Consider a Protobuf schema (schemaID = 1) with two message types defined:</p>
<pre>syntax = "proto3";

message ProductKey {
  int32 P_ID = 1;
}

message ProductInfo {
  string P_NAME = 1;
  double P_PRICE = 2;
}
</pre>
<p>When creating a stream or table with this schema, one can control which message type is used by referencing names directly with <strong>key_schema_full_name</strong> and <strong>value_schema_full_name</strong>:</p>
<pre>ksql&gt; CREATE STREAM products WITH (
KAFKA_TOPIC='products', 
FORMAT='protobuf', 
KEY_SCHEMA_ID='1',
VALUE_SCHEMA_ID='1',
KEY_SCHEMA_FULL_NAME='ProductKey',
VALUE_SCHEMA_FULL_NAME='ProductInfo'
);

 Message        
----------------
 Stream created 
----------------

ksql&gt; DESCRIBE products;

Name             	: PRODUCTS
 Field   | Type              	 
----------------------------------
 P_ID	 | INTEGER      	(key)
 P_NAME  | VARCHAR(STRING)   	 
 P_PRICE | DOUBLE            	 
---------------------------------
</pre>
<p>ksqlDB infers the key and value schema for this stream based on the explicitly-identified Protobuf message types. Accordingly, INSERTs are also validated against the specified message types.</p>
<pre>ksql&gt; INSERT INTO products(p_id, p_name, p_price) VALUES(1, 'rice', 2.99);

ksql&gt; SELECT * FROM products;
+---------------------------+----------------------------+---------------------------+
|P_ID                       |P_NAME                      |P_PRICE                    |
+---------------------------+----------------------------+---------------------------+
|1                          |rice                        |2.99                       |
Query Completed
</pre>
<h2>Handling null dereferencing inside functions</h2>
<p>Following up on the null-handling improvement in 0.25.1, this release has a bug fix for handling dereferencing null structs in 0.26. As a concrete example, consider the following query:</p>
<pre>
SELECT IFNULL(requirements-&gt;education-&gt;degree, 'n/a') as required_edu_degree 
FROM stream;
EMIT CHANGES;
</pre>
<p>Previously if <code>requirements</code>, or <code>education</code> were null, then an exception could be thrown and cause the function to return a null value. With the fix, the dereference <code>requirements-&gt;education-&gt;degree</code> would return null, and then <code>ifnull</code> function can act on it appropriately and return <code>n/a</code>.</p>
<h2 id="get-started"><a id="get-started"></a>Get started with ksqlDB</h2>
<p>Again, thank you for using ksqlDB. Please do not hesitate to contact us with more feedback or comments! For more details about the changes, please refer to the <a href="https://github.com/confluentinc/ksql/blob/master/CHANGELOG.md" target="_blank" rel="noopener">changelog</a>. Get started with ksqlDB today, via the <a href="https://ksqldb.io/quickstart.html?_ga=2.174341729.2139333191.1646062668-363840567.1611349348&amp;_gac=1.57636568.1645650703.Cj0KCQiA09eQBhCxARIsAAYRiyl3n58eA-cZajIwBav341gGvGxmqoFuBIi2e4b2_pFm3wGErjrjPesaAgjdEALw_wcB" target="_blank" rel="noopener">standalone distribution</a> or with <a href="https://www.confluent.io/confluent-cloud/">Confluent</a>, and <a href="https://forum.confluent.io/c/ksqldb/11?_ga=2.181681764.2139333191.1646062668-363840567.1611349348&amp;_gac=1.61755742.1645650703.Cj0KCQiA09eQBhCxARIsAAYRiyl3n58eA-cZajIwBav341gGvGxmqoFuBIi2e4b2_pFm3wGErjrjPesaAgjdEALw_wcB" target="_blank" rel="noopener">join the community</a> to ask questions and find new resources.</p>
<p style="text-align: center;"><a class="download_blue rounded_button" style="color: #fff; text-align: center;" href="https://ksqldb.io/quickstart.html?_ga=2.174341729.2139333191.1646062668-363840567.1611349348&amp;_gac=1.57636568.1645650703.Cj0KCQiA09eQBhCxARIsAAYRiyl3n58eA-cZajIwBav341gGvGxmqoFuBIi2e4b2_pFm3wGErjrjPesaAgjdEALw_wcB">Get Started</a></p>
  • Tom Nguyen is an engineer on the ksqlDB team at Confluent. He joined in 2021 after previously building event systems in e-commerce, AI, and banking.

Get started with Confluent, for free

Watch demo: Kafka streaming in 10 minutes

Ist dieser Blog-Beitrag interessant? Jetzt teilen