tessl install tessl/maven-org-apache-flink--flink-table-api-scala_2-12@1.20.0Scala API for Apache Flink's Table/SQL ecosystem providing idiomatic Scala interfaces for table 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.
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
}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*): ExpressionUsage:
// 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"))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): ExpressionUsage:
// 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)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_! : ExpressionUsage:
// 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))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_+ : ExpressionUsage:
// 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 onlyOperator 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): ExpressionUsage:
// 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-4Ternary 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): ExpressionUsage:
// 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 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(" ")
): ExpressionUsage:
// 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"
)Operations for creating window intervals.
/**
* Creates an interval of rows for window operations
* @return Row interval expression
*/
def rows: ExpressionUsage:
// Window with row-based intervals
table.window(
Over
.partitionBy($"userId")
.orderBy($"timestamp")
.preceding(5.rows)
.following(CURRENT_ROW)
)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")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)