当我尝试用bit()
写Spark SQL时,会导致错误。
val tpos_dfr = sqlContext.sql("SELECT idcustomer, quantity, CASE WHEN quantity < 0 THEN 1::bit(1) ELSE 0::bit(1) END as isthisreturn FROM pointofsale WHERE iddataloadmanager = 10 and quantity <> 0")
错误线程"main"出现异常{, ',', 'FROM', 'WHERE', GROUP', 'ORDER', 'HAVING', 'LIMIT', 'LATERAL', 'WINDOW', 'UNION', 'EXCEPT', 'INTERSECT', 'SORT', 'CLUSTER', 'DISTRIBUTE'}(第一行,pos 122)
val tpos_dfr = sqlContext.sql("SELECT idcustomer, quantity, CASE WHEN quantity < 0 THEN 1::bit(1) ELSE 0::bit(1) END as isthisreturn FROM pointofsale WHERE iddataloadmanager = 10 and quantity <> 0")
线程"main"出现异常{, ',', 'FROM', 'WHERE', GROUP', 'ORDER', 'HAVING', 'LIMIT', 'LATERAL', 'WINDOW', 'UNION', 'EXCEPT', 'INTERSECT', 'SORT', 'CLUSTER', 'DISTRIBUTE'}(第一行,pos 122)
您可以使用布尔表达式,并使用结果布尔值而不是位,因此请尝试
SELECT
idcustomer,
quantity,
quantity < 0 as isthisreturn
FROM
pointofsale
WHERE
iddataloadmanager = 10 and quantity <> 0
如果在数据帧上调用printSchema()
,则应该出现布尔数据类型