Creating regular joins

A regular join combines the rows of two tables that have the same value in the columns of the join condition. It is the join of standard SQL. Cloudera SQL Stream Builder (SSB) supports inner joins and the outer joins LEFT, RIGHT, and FULL.

Ensure that you know how to run a job. For more information, see Running a job with generated data.

In a streaming query, a regular join keeps the rows of both inputs in the state of the job, because a new row on one side can match an old row on the other side. The state grows without a limit unless you set a state time-to-live (TTL). Use a regular join if the inputs are bounded, if the join key has few values, or if you set a TTL.

  1. In the Streaming SQL Console, click Projects in the left navigation pane, and click the name of your project.
    The project opens, with the Explorer panel on the left. To open the Streaming SQL Console, see Accessing Cloudera SQL Stream Builder.
  2. In the Explorer, open the menu of Jobs, and click New Job.
    The Create New Job window opens.
  3. Enter a Job Name, or click Generate Job Name.
  4. Click Create.
    The job opens in a new tab, with an empty SQL editor.
  5. Enter the following statements in the SQL editor:
    SET 'table.exec.state.ttl' = '1 h';
    
    CREATE TABLE orders (
      order_id INT,
      product_id INT,
      amount DOUBLE
    ) WITH (
      'connector' = 'datagen',
      'rows-per-second' = '5',
      'fields.order_id.kind' = 'sequence',
      'fields.order_id.start' = '1',
      'fields.order_id.end' = '100000',
      'fields.product_id.min' = '1',
      'fields.product_id.max' = '10'
    );
    
    CREATE TABLE products (
      product_id INT,
      price DOUBLE
    ) WITH (
      'connector' = 'datagen',
      'rows-per-second' = '5',
      'fields.product_id.kind' = 'sequence',
      'fields.product_id.start' = '1',
      'fields.product_id.end' = '10',
      'fields.price.min' = '1',
      'fields.price.max' = '100'
    );
    
    CREATE TABLE order_values (
      order_id INT,
      product_id INT,
      amount DOUBLE,
      price DOUBLE
    ) WITH (
      'connector' = 'blackhole'
    );
    
    INSERT INTO order_values
    SELECT o.order_id, o.product_id, o.amount, p.price
    FROM orders AS o
    INNER JOIN products AS p
      ON o.product_id = p.product_id;
  6. Click the Execute job icon.
    The progress of each statement is displayed on the Logs tab. When the job starts, its status icon in the Explorer turns green.
  7. When you have finished, click Stop job.

The SET statement limits how long the job keeps a row that it has not matched. A late match is lost because a row that is older than the TTL is removed from the state. Choose a value that is longer than the delay between the matching rows. For more information about the SET statement, see Other supported statements.