spooq.transformer.mapper_transformations.meters_to_cm

meters_to_cm(source_column=None, name=None, **kwargs: Any) partial[source]

Converts meters to cm and casts the result to an IntegerType.

Parameters
  • source_column (str or Column) – Input column. Can be a name, pyspark column or pyspark function

  • name (str, default -> derived from input column) – Name of the output column. (.alias(name))

Keyword Arguments
  • alt_src_cols (str, default -> no coalescing, only source_column) – Coalesce with source_column and columns from this parameter.

  • cast (T.DataType(), default -> T.IntegerType()) – Applies provided datatype on output column (.cast(cast))

Examples

>>> input_df = spark.createDataFrame([
...     Row(size_in_m=1.80),
...     Row(size_in_m=1.65),
...     Row(size_in_m=2.05)
... ])
>>>
>>> input_df.select(spq.meters_to_cm("size_in_m")).show(truncate=False)
+---------+
|180      |
|165      |
|204      |
+---------+
>>>
>>> mapping = [
...     ("original_value",  "size_in_m",  spq.as_is),
...     ("size_in_cm",      "size_in_m",  spq.meters_to_cm),
... ]
>>> output_df = Mapper(mapping).transform(input_df)
>>> output_df.show(truncate=False)
+--------------+----------+
|original_value|size_in_cm|
+--------------+----------+
|1.8           |180       |
|1.65          |165       |
|2.05          |204       |
+--------------+----------+
Returns

This method returns a suitable type depending on how it was called. This ensures compability with Spooq’s mapper transformer - with or without explicit parameters - as well as direct calls via select, withColumn, where, …

Return type

partial or Column