title: Spark: cast bytearray to bigint
body: <p>Trying to cast kafka key (binary/bytearray) to long/bigint using pyspark and spark sql results in data type mismatch: cannot cast binary to bigint</p>
  
  <p>Environment details:</p>
  
  <pre class="lang-none prettyprint-override"><code>Python 3.6.8 |Anaconda custom (64-bit)| (default, Dec 30 2018, 01:22:34)
  [GCC 7.3.0] on linux
  Welcome to
        ____              __
       / __/__  ___ _____/ /__
      _\ \/ _ \/ _ `/ __/  '_/
     /__ / .__/\_,_/_/ /_/\_\   version 2.3.0.cloudera2
        /_/
  
  Using Python version 3.6.8 (default, Dec 30 2018 01:22:34)
  SparkSession available as 'spark'.
  </code></pre>
  
  <p>Test case:</p>
  
  <pre><code>from pyspark.sql.types import StructType, StructField, BinaryType
  df1_schema = StructType([StructField("key", BinaryType())])
  df1_value = [[bytearray([0, 6, 199, 95, 77, 184, 55, 169])]]
  df1 = spark.createDataFrame(df1_value,schema=df1_schema)
  df1.printSchema()
  #root
  # |-- key: binary (nullable = true)
  
  df1.show(truncate=False)
  #+-------------------------+
  #|key                      |
  #+-------------------------+
  #|[00 06 C7 5F 4D B8 37 A9]|
  #+-------------------------+
  
  df1.selectExpr('cast(key as bigint)').show(truncate=False)
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
  <pre><code>(...)  File "/app/cloudera/parcels/SPARK2-2.3.0.cloudera2-1.cdh5.13.3.p0.316101/lib/spark2/python/lib/py4j-0.10.6-src.zip/py4j/protocol.py", line 320, in get_return_value
  py4j.protocol.Py4JJavaError: An error occurred while calling o63.selectExpr.
  : org.apache.spark.sql.AnalysisException: cannot resolve 'CAST(`key` AS BIGINT)' due to data type mismatch: cannot cast binary to bigint; line 1 pos 0;
  (...)
  pyspark.sql.utils.AnalysisException: "cannot resolve 'CAST(`key` AS BIGINT)' due to data type mismatch: cannot cast binary to bigint; line 1 pos 0;\n'Project [unresolvedalias(cast(key#0 as bigint), None)]\n+- AnalysisBarrier\n      +- LogicalRDD [key#0], false\n"
  </code></pre>
  </blockquote>
  
  <p>But my expected result would be <code>1908062000002985</code>, e.g.:</p>
  
  <pre><code>dfpd = df1.toPandas()
  int.from_bytes(dfpd['key'].values[0], byteorder='big')
  #1908062000002985
  </code></pre>