or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.apache.flink/flink-table-api-scala_2.12@1.20.x

docs

builtin-functions.mdexpression-operations.mdfunction-integration.mdimplicit-conversions.mdindex.mdjson-operations.md
tile.json

tessl/maven-org-apache-flink--flink-table-api-scala_2-12

tessl install tessl/maven-org-apache-flink--flink-table-api-scala_2-12@1.20.0

Scala API for Apache Flink's Table/SQL ecosystem providing idiomatic Scala interfaces for table operations

expression-operations.mddocs/

Expression Operations

Trait providing operator overloading and method extensions for expressions, enabling fluent Scala-style operations on table expressions. This allows using natural Scala operators and syntax for building complex table expressions.

Capabilities

Core Expression Interface

Base interface that all expression operations extend.

trait ImplicitExpressionOperations extends BaseExpressions[Expression, Expression] {
  private[flink] def expr: Expression
  def toExpr: Expression
  protected def toApiSpecificExpression(expression: Expression): Expression
}

Field Naming Operations

Methods for specifying aliases and names for expressions and fields.

/**
 * Specifies a name for an expression using Scala symbols
 * @param name Primary field name as Symbol
 * @param extraNames Additional names if expression expands to multiple fields
 * @return Expression with alias
 */
def as(name: Symbol, extraNames: Symbol*): Expression

/**
 * Specifies a name for an expression using strings (inherited from base)
 * @param name Primary field name as String
 * @param extraNames Additional names if expression expands to multiple fields  
 * @return Expression with alias
 */
def as(name: String, extraNames: String*): Expression

Usage:

// Using symbols
table.select($"amount" * 1.2 as 'amountWithTax)

// Using strings  
table.select($"firstName" + " " + $"lastName" as "fullName")

// Multiple field names for expanding expressions
table.select(call("splitName", $"fullName") as ("first", "last"))

Comparison Operators

Operators for comparing expressions with three-valued logic support.

/** Greater than comparison */
def >(other: Expression): Expression

/** Greater than or equal comparison */
def >=(other: Expression): Expression

/** Less than comparison */
def <(other: Expression): Expression

/** Less than or equal comparison */
def <=(other: Expression): Expression

/** Equality comparison */
def ===(other: Expression): Expression

/** Inequality comparison */
def !==(other: Expression): Expression

Usage:

// Numeric comparisons
table.filter($"age" > 18)
table.filter($"salary" >= 50000)
table.filter($"score" < 100)

// String comparisons
table.filter($"status" === "active")
table.filter($"category" !== "deleted")

// Chained comparisons
table.filter($"age" >= 18 && $"age" < 65)

Boolean Logic Operators

Operators for boolean operations with three-valued logic.

/** Boolean AND in three-valued logic */
def &&(other: Expression): Expression

/** Boolean OR in three-valued logic */  
def ||(other: Expression): Expression

/** Boolean NOT - inverts boolean expression, preserving NULL */
def unary_! : Expression

Usage:

// AND operations
table.filter($"active" && $"verified")
table.filter($"age" > 18 && $"country" === "US")

// OR operations  
table.filter($"priority" === "high" || $"urgent")

// NOT operations
table.filter(!$"deleted")
table.filter(!($"age" < 18))

Arithmetic Operators

Mathematical operators for numeric expressions.

/** Addition */
def +(other: Expression): Expression

/** Subtraction */
def -(other: Expression): Expression

/** Multiplication */
def *(other: Expression): Expression

/** Division */
def /(other: Expression): Expression

/** Modulus - remainder of division */
def %(other: Expression): Expression

/** Unary negation */
def unary_- : Expression

/** Unary positive (no-op) */
def unary_+ : Expression

Usage:

// Basic arithmetic
table.select(
  $"price" * $"quantity" as "total",
  $"revenue" - $"costs" as "profit",  
  $"amount" / 100 as "percentage"
)

// Complex expressions
table.select(
  ($"base" + $"bonus") * $"multiplier" as "finalAmount",
  -$"debt" as "negativeDebt"
)

// Modulus operations
table.filter($"id" % 2 === 0) // Even IDs only

Range Operations

Operator for creating ranges used in column selection.

/**
 * Creates a range from left to right for column selection
 * @param other End of range
 * @return Range expression for use with withColumns/withoutColumns
 */
def to(other: Expression): Expression

Usage:

// Column range selection
table.select(withColumns(1 to 5))        // Columns 1 through 5
table.select(withColumns($"name" to $"age")) // Column range by name
table.select(withoutColumns(2 to 4))     // Exclude columns 2-4

Conditional Operations

Ternary conditional operator for conditional expressions.

/**
 * Ternary conditional operator
 * @param ifTrue Expression to evaluate if condition is true
 * @param ifFalse Expression to evaluate if condition is false
 * @return Conditional expression
 */
def ?(ifTrue: Expression, ifFalse: Expression): Expression

Usage:

// Simple conditionals
table.select(
  $"name",
  ($"age" >= 18) ? "adult" : "minor" as "ageGroup"
)

// Nested conditionals
table.select(
  $"score" > 90 ? "A" : ($"score" > 80 ? "B" : "C") as "grade"
)

// Null handling
table.select(
  $"optional".isNull ? "N/A" : $"optional" as "displayValue"
)

String Operations

String manipulation operations available on expression level.

/**
 * Removes leading and/or trailing characters from string expression
 * @param removeLeading Whether to remove leading characters (default: true)
 * @param removeTrailing Whether to remove trailing characters (default: true)  
 * @param character Character to remove (default: " ")
 * @return Trimmed string expression
 */
def trim(
  removeLeading: Boolean = true,
  removeTrailing: Boolean = true, 
  character: Expression = valueLiteral(" ")
): Expression

Usage:

// Basic trimming (whitespace)
table.select($"name".trim() as "cleanName")

// Custom character trimming
table.select($"path".trim(character = lit("/")) as "cleanPath")

// Leading/trailing control
table.select(
  $"text".trim(removeLeading = false) as "leftPadded",
  $"text".trim(removeTrailing = false) as "rightPadded"
)

Window Operations

Operations for creating window intervals.

/**
 * Creates an interval of rows for window operations
 * @return Row interval expression
 */
def rows: Expression

Usage:

// Window with row-based intervals
table.window(
  Over
    .partitionBy($"userId")
    .orderBy($"timestamp")
    .preceding(5.rows)
    .following(CURRENT_ROW)
)

Expression Chaining

All operations return expressions that can be further chained with additional operations.

Usage:

// Complex chained expressions
val complexFilter = ($"age" >= 18) && 
                   ($"income" > 30000) && 
                   (!$"blacklisted") &&
                   ($"country" === "US" || $"country" === "CA")

val computedValue = (($"base" + $"bonus") * $"rate" / 100).round(2)

table
  .filter(complexFilter)
  .select($"name", computedValue as "finalAmount")

Type Safety

All operations maintain type safety and work with Scala's type system.

Usage:

// Type-safe operations
val numericExpr: Expression = $"amount" * 1.2  // Numeric expression
val booleanExpr: Expression = $"active" && $"verified"  // Boolean expression  
val stringExpr: Expression = $"firstName" + " " + $"lastName"  // String expression

// Compile-time safety
table.select(numericExpr, booleanExpr, stringExpr)