Skip to main content

Lead

Definition

The lead method allows you to add the LEAD function to the query. The LEAD function provides access to a row that follows the current row at a specified physical offset. It means that from the current row, the LEAD function can access data of the next row, the row after the next row, and so on.

Available methods

  • lead(KColumn kColumn): Receives a KColumn or a KTableColumn which will be supplied to the LEAD function.
  • lead(KColumn kColumn, int offset): Receives a KColumn or a KTableColumn and an offset which will be supplied to the LEAD function.
  • lead(KColumn kColumn, int offset, KBaseColumnCastable defaultValue): Receives a KColumn or a KTableColumn and an offset which will be supplied to the LEAD function. Additionally, receives a default value which too will be supplied to the LEAD function. Among the possible values of this default value are: KTableColumn, KColumn, Values.

To use this way, you need to import the static functions as follows:

import static com.myzlab.k.KFunction.*;

Example: lead(KColumn)

Java code:

k
.select(
APP_USER.FIRST_NAME,
lead(APP_USER.FIRST_NAME).over(wd())
)
.from(APP_USER)
.multiple();

SQL generated:

SELECT
au.first_name,
LEAD(au.first_name) OVER()
FROM app_user au

Parameters:

  • None

Example: lead(KColumn, int)

Java code:

k
.select(
APP_USER.FIRST_NAME,
lead(APP_USER.FIRST_NAME, 2).over(wd())
)
.from(APP_USER)
.multiple();

SQL generated:

SELECT
au.first_name,
LEAD(au.first_name, 2) OVER()
FROM app_user au

Parameters:

  • None

Example: lead(KColumn, int, KBaseColumnCastable)

Java code:

k
.select(
APP_USER.FIRST_NAME,
lead(APP_USER.FIRST_NAME, 2, val("No name")).over(wd())
)
.from(APP_USER)
.multiple();

SQL generated:

SELECT
au.first_name,
LEAD(au.first_name, 2, ?1) OVER()
FROM app_user au

Parameters:

  • ?1: "No name"