lit
function lit(value): Column;Defined in: column.ts:424
Wrap a JavaScript value as a literal column expression. lit(null) produces
a NullType null literal that can be re-typed with .cast(...). Passing
undefined throws InvalidInputError (JS undefined has no Spark analog).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
string | number | bigint | boolean | null |
Returns
Section titled “Returns”Example
Section titled “Example”df.withColumn("flag", lit(true));df.filter(col("age").gte(lit(18)));df.withColumn("name", lit(null).cast("string"));Remarks
Section titled “Remarks”Integer precision. JavaScript number is IEEE-754 float64. Integer
values above Number.MAX_SAFE_INTEGER (2^53 - 1) lose precision. Pass
bigint literals when you need LongType semantics on the server.