Substring

Supported in: Batch, Streaming

Extract substring.

Expression categories: Numeric

Declared arguments

  • Expression - no description
    Expression<String>
  • Start - The index to start substring from (inclusive). Negative numbers start from end of string. This is 1-indexed.
    Expression<Integer>
  • optional Length - The length of the substring to extract. If not provided the remainder of the string is extracted.
    Expression<Integer>

Output type: String

Examples

Example 1: Base case

Argument values:

  • Expression: string
  • Start: start
  • Length: length
stringstartlengthOutput
hello, world15hello
hello, world85world
hello, world-55world

Example 2: Base case

Description: When no length is provided, the substring runs to end of string. Argument values:

  • Expression: string
  • Start: start
  • Length: null
stringstartOutput
hello, world1hello, world
hello, world8world
hello, world-5world

Example 3: Null case

Description: In case of nulls, the output is always null. Argument values:

  • Expression: string
  • Start: start
  • Length: length
stringstartlengthOutput
null15null
hello, worldnull5null
hello, world1nullnull
nullnullnullnull

Example 4: Edge case

Description: When length is longer than remaining sub string, the output is the sub string until the end of the string. Argument values:

  • Expression: string
  • Start: start
  • Length: length
stringstartlengthOutput
hello, world-510world
hello, world120hello, world
hello, world125d
hello, world135empty string
hello, world205empty string
hello, world12-5empty string