0

When I try write Spark SQL with bit(), it result in an error.

Code

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

Error

Exception in thread "main" org.apache.spark.sql.catalyst.parser.ParseException:
extraneous input 'quantity' expecting {, ',', 'FROM', 'WHERE', GROUP', 'ORDER', 'HAVING', 'LIMIT', 'LATERAL', 'WINDOW', 'UNION', 'EXCEPT', 'INTERSECT', 'SORT', 'CLUSTER', 'DISTRIBUTE'}(line 1, pos 122)

Beryllium
  • 12,808
  • 10
  • 56
  • 86
Jai
  • 11
  • 4

1 Answers1

1

You could use a boolean expression, and use the resulting boolean value instead of a bit, so try

SELECT 
    idcustomer, 
    quantity, 
    quantity < 0 as isthisreturn 
  FROM 
    pointofsale 
  WHERE
    iddataloadmanager = 10 and quantity <> 0

then a boolean data type should appear, if you call printSchema() on the data frame.

Beryllium
  • 12,808
  • 10
  • 56
  • 86