mtcars = spark.read.csv('../../data/mtcars.csv', inferSchema=True, header=True)
mtcars = mtcars.withColumnRenamed('_c0', 'model')
mtcars.show()

"""
Explanation: Boolean column expression
Create a column expression that will return boolean values. 
Example data
End of explanation
"""


mpg_between = mtcars.cyl.between(4,6)
mpg_between

mtcars.select(mtcars.cyl, mpg_between).show(5)

"""
Explanation: between(): true/false if the column value is between a given range
End of explanation
"""


model_contains = mtcars.model.contains('Ho')
model_contains

mtcars.select(mtcars.model, model_contains).show(5)

"""
Explanation: contains(): true/false if the column value contains a string
End of explanation
"""


model_endswith = mtcars.model.endswith('t')
model_endswith

mtcars.select(mtcars.model, model_endswith).show(6)

"""
Explanation: endswith(): true/false if the column value ends with a string
End of explanation
"""


from pyspark.sql import Row
df = spark.createDataFrame([Row(name='Tom', height=80), Row(name='Alice', height=None)])
df.show()

height_isNotNull = df.height.isNotNull()
height_isNotNull

df.select(df.height, height_isNotNull).show()

"""
Explanation: isNotNull(): true/false if the column value is not Null
End of explanation
"""


height_isNull = df.height.isNull()
height_isNull

df.select(df.height, height_isNull).show()

"""
Explanation: isNull(): true/false if the column value is Null
End of explanation
"""


carb_isin = mtcars.carb.isin([2, 3])
carb_isin

mtcars.select(mtcars.carb, carb_isin).show(10)

"""
Explanation: isin(): true/false if the column value is contained by the evaluated argument
End of explanation
"""


model_like = mtcars.model.like('Ho%')
model_like

mtcars.select(mtcars.model, model_like).show(10)

"""
Explanation: like(): true/false if the column value matches a pattern based on a SQL LIKE
End of explanation
"""


model_rlike = mtcars.model.rlike('t$')
model_rlike

mtcars.select(mtcars.model, model_rlike).show()

"""
Explanation: rlike(): true/false if the column value matches a pattern based on a SQL RLIKE (LIKE with Regex)
End of explanation
"""


model_startswith = mtcars.model.startswith('Merc')
model_startswith

mtcars.select(mtcars.model, model_startswith).show()

"""
Explanation: startswith(): true/false if the column value starts with a string
End of explanation
"""


