Skip to content

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).

Parameter Type
value string | number | bigint | boolean | null

Column

df.withColumn("flag", lit(true));
df.filter(col("age").gte(lit(18)));
df.withColumn("name", lit(null).cast("string"));

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.