Works for me
print(s"Spark ${spark.version}")
val df = spark.createDataFrame(Seq(( 2, 9), ( 1, 5),( 1, 1),( 1, 2),( 2, 8)))
.toDF("y", "x")
df.createOrReplaceTempView("test")
spark.sql("select CASE WHEN y = 2 THEN 'A' ELSE 'B' END AS flag, x from test").show
Returns
Spark 2.0.0
df: org.apache.spark.sql.DataFrame = [y: int, x: int]
+----+---+
|flag| x|
+----+---+
| A| 9|
| B| 5|
| B| 1|
| B| 2|
| A| 8|
+----+---+