You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by vectorijk <gi...@git.apache.org> on 2015/12/30 15:31:51 UTC

[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

GitHub user vectorijk opened a pull request:

    https://github.com/apache/spark/pull/10527

    [SPARK-12567][SQL] Add aes_{encrypt,decrypt} UDFs

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/vectorijk/spark spark-12567

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/10527.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #10527
    
----
commit 270a72220d49219865fcd7dbc18fb922ff5d5873
Author: Kai Jiang <ji...@gmail.com>
Date:   2015-12-29T03:11:14Z

    add aes {encrypt, decrypt}

commit d9716044dbd2c4a3154293429f5e64b5a5c64d69
Author: Kai Jiang <ji...@gmail.com>
Date:   2015-12-29T23:05:57Z

    make aes_encrypt worked

commit 9edeba7d124f6a9e0ed7b7949b6fd10f26929706
Author: Kai Jiang <ji...@gmail.com>
Date:   2015-12-30T00:16:07Z

    make aes_decrypt worked

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r50942084
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -130,4 +130,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // Before testing this, installing Java Cryptography Extension (JCE)
    +    // Unlimited Strength Jurisdiction Policy Files first
    +//    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +//      Literal("12345678901234561234567890123456".getBytes))), "nYfCuJeRd5eD60yXDw7WEA==")
    --- End diff --
    
    @cloud-fan @marmbrus ping?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53568446
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,42 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java
    +   * Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If
    +   * either argument is NULL, the result will also be null. If input is invalid, key length is not
    +   * one of the permitted values or using 192/256 bits key before installing JCE, an exception will
    +   * be thrown.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    Actually we do have a mess of it. Generally we have 3 kinds of parameters: `Column`, column name string, literal. For example, `pow` takes 2 parameters, and we have 8 overloaded versions of it, which are all combinations of these 3 kinds of parameters except both literals. However, some functions like `pmod`, only have both `Column` version. Some functions like `sha2` only have `Column`, literal combination.
    
    Personly I think for something like `sha2` and this one, where one parameter will be literal 99% of the time, we should just give a `Column`, literal combination. i.e. `def aes_encrypt(input: Column, key: String)`. For something like `pow`, we only need to provide the both `Column` version, as column name string and literal are easy to parse to `Column`, by `col()` and `lit()`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-182851174
  
    LGTM except some minor comments, thanks for working on it!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186007811
  
    **[Test build #51508 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51508/consoleFull)** for PR 10527 at commit [`8e2960c`](https://github.com/apache/spark/commit/8e2960ce68676ea7cb09683b1e1556ccf2114053).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175813070
  
    **[Test build #50212 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50212/consoleFull)** for PR 10527 at commit [`9476822`](https://github.com/apache/spark/commit/94768224126acf303e9e8b6d2697388f0fec1d23).
     * This patch **fails Scala style tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52387433
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -442,3 +444,88 @@ case class PrintToStderr(child: Expression) extends UnaryExpression {
            """.stripMargin)
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +      input2.asInstanceOf[Array[Byte]].length, "AES")
    +    cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +    cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +  }
    +
    +  override def genCode(ctx: CodegenContext, ev: ExprCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            $SecretKeySpec secret = new $SecretKeySpec($key, 0, $key.length, "AES");
    +            cipher.init($Cipher.ENCRYPT_MODE, secret);
    +            ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +          } catch (java.security.GeneralSecurityException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    --- End diff --
    
    @cloud-fan re-throw exception like `Encode`/`Decode` does.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/10527


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #10527: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} UDFs

Posted by maver1ck <gi...@git.apache.org>.
Github user maver1ck commented on the issue:

    https://github.com/apache/spark/pull/10527
  
    @vectorijk Is this PR dead ?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175810046
  
    retest this please.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51682076
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    --- End diff --
    
    @cloud-fan What I have implemented was trying to follow the way `Sha2` did. 
    I think if secret key is invalid. It will return null just like the way `Sha2` did. There is no other errors should be thrown during execution.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175813083
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/50212/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53442582
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,88 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    val expr1 = AesEncrypt(Literal("ABC".getBytes), Literal("1234567890123456".getBytes))
    +    val expr2 = AesEncrypt(Literal("".getBytes), Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(Base64(expr1), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(expr2), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType)), null)
    +
    +    val expr3 = AesEncrypt(Literal("ABC".getBytes), Literal("1234567890".getBytes))
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(expr3)
    +    }
    +    intercept[java.security.InvalidKeyException] {
    +      UnsafeProjection.create(expr3::Nil).apply(null)
    +    }
    +  }
    +
    +  test("aesDecrypt") {
    +    val expr1 = AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes))
    +    val expr2 = AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(expr1, "ABC")
    +    checkEvaluation(expr2, "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +
    +    val expr3 = AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890".getBytes))
    +    val expr4 = AesDecrypt(UnBase64(Literal("y6Ss+zCsdYObpCbgfWfyNW3Twewr")),
    +      Literal("1234567890123456".getBytes))
    +    val expr5 = AesDecrypt(UnBase64(Literal("t6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes))
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(expr3)
    +    }
    +    intercept[java.security.InvalidKeyException] {
    +      UnsafeProjection.create(expr3::Nil).apply(null)
    --- End diff --
    
    done


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175924450
  
    retest this please 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177414971
  
    **[Test build #50457 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50457/consoleFull)** for PR 10527 at commit [`04a14cf`](https://github.com/apache/spark/commit/04a14cf072630fbe3619bf241ff3d10d383594a5).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53545906
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,42 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java
    +   * Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If
    +   * either argument is NULL, the result will also be null. If input is invalid, key length is not
    +   * one of the permitted values or using 192/256 bits key before installing JCE, an exception will
    +   * be thrown.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    then we should probably just take a string.
    
    the thing is we want to facilitate the most common cases, e.g. if 99% of the time people are passing in keys directly rather than relying on some other columns' values, we should just let them pass the literals.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-185644151
  
    **[Test build #51476 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51476/consoleFull)** for PR 10527 at commit [`dc76057`](https://github.com/apache/spark/commit/dc760570b594d100aeda7ce181edc8a3572a59c2).
     * This patch **fails PySpark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by davies <gi...@git.apache.org>.
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53546006
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,42 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java
    +   * Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If
    +   * either argument is NULL, the result will also be null. If input is invalid, key length is not
    +   * one of the permitted values or using 192/256 bits key before installing JCE, an exception will
    +   * be thrown.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    Some of the functions take literals, some not., In 2.0, should we clean up all the mess?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175987185
  
    **[Test build #50243 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50243/consoleFull)** for PR 10527 at commit [`9476822`](https://github.com/apache/spark/commit/94768224126acf303e9e8b6d2697388f0fec1d23).
     * This patch passes all tests.
     * This patch **does not merge cleanly**.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186180682
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/51549/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175987440
  
    Build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r48918891
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -221,3 +224,147 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         """
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    + 'y6Ss+zCYObpCbgfWfyNWTw=='"""
    +)
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: InvalidKeyException => null
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            try {
    +              if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +                cipher.init($Cipher.ENCRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +                ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +              } else {
    +                ${ev.isNull} = true;
    +              }
    +            } catch (java.security.InvalidKeyException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.IllegalBlockSizeException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.BadPaddingException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            }
    +          } catch(java.security.NoSuchAlgorithmException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          } catch(javax.crypto.NoSuchPaddingException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = """_FUNC_(input, key) - Decrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended =
    +    """> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');
    + 'ABC'"""
    +)
    +case class AesDecrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    --- End diff --
    
    no need to `with Serializable`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168963321
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52597354
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,47 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType))), null)
    +    // both are null
    +    checkEvaluation(Base64(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType))), null)
    +  }
    +
    +  test("aesDecrypt") {
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes)), "ABC")
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes)), "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +  }
    +
    --- End diff --
    
    it'll be better if we have several tests for error cases, e.g. key length is invalid, the input data can't be decrypted, etc.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186184787
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/51551/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177379953
  
    @cloud-fan Okay, addressed comments.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169680244
  
    **[Test build #48943 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48943/consoleFull)** for PR 10527 at commit [`9476822`](https://github.com/apache/spark/commit/94768224126acf303e9e8b6d2697388f0fec1d23).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169706781
  
    **[Test build #48943 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48943/consoleFull)** for PR 10527 at commit [`9476822`](https://github.com/apache/spark/commit/94768224126acf303e9e8b6d2697388f0fec1d23).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168012874
  
    **[Test build #48484 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48484/consoleFull)** for PR 10527 at commit [`9edeba7`](https://github.com/apache/spark/commit/9edeba7d124f6a9e0ed7b7949b6fd10f26929706).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186522894
  
    @davies does this implementation even make sense? decrypt always return a string, while encrypt always take in a binary? The two are not symmetric.
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168086668
  
    **[Test build #48511 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48511/consoleFull)** for PR 10527 at commit [`9edeba7`](https://github.com/apache/spark/commit/9edeba7d124f6a9e0ed7b7949b6fd10f26929706).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186029112
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169707164
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168055335
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53545904
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,42 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java
    +   * Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If
    +   * either argument is NULL, the result will also be null. If input is invalid, key length is not
    +   * one of the permitted values or using 192/256 bits key before installing JCE, an exception will
    +   * be thrown.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    I also think so. The examples is just one of those cases. Key also could be `abcdef1234567890`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by davies <gi...@git.apache.org>.
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52836274
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,40 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    +    AesEncrypt(input.expr, key.expr)
    +  }
    +
    +  /**
    +   * Decrypts input using AES and Returns the result as a string column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to decrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_decrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    I meant to test these API, not just the expressions.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175927638
  
    **[Test build #50243 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50243/consoleFull)** for PR 10527 at commit [`9476822`](https://github.com/apache/spark/commit/94768224126acf303e9e8b6d2697388f0fec1d23).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175812617
  
    **[Test build #50212 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50212/consoleFull)** for PR 10527 at commit [`9476822`](https://github.com/apache/spark/commit/94768224126acf303e9e8b6d2697388f0fec1d23).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49077091
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -221,3 +224,131 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         """
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    + 'y6Ss+zCYObpCbgfWfyNWTw=='"""
    +)
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            $SecretKeySpec secret;
    +            if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +              secret = new $SecretKeySpec($key, 0, $key.length, "AES");
    +            } else {
    +              secret = null;
    +            }
    +            cipher.init($Cipher.ENCRYPT_MODE, secret);
    +            ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +          } catch (java.security.GeneralSecurityException e) {
    +            ${ev.isNull} = true;
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = """_FUNC_(input, key) - Decrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended =
    +    """> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');
    + 'ABC'"""
    +)
    +case class AesDecrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = StringType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.DECRYPT_MODE, secretKey)
    +      UTF8String.fromBytes(
    +        cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0,
    +          input1.asInstanceOf[Array[Byte]].length))
    +    } catch {
    +      case e: GeneralSecurityException => null
    +    }
    +
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            $SecretKeySpec secret;
    +            if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +              secret = new $SecretKeySpec($key, 0, $key.length, "AES");
    +            } else {
    +              secret = null;
    +            }
    +            cipher.init($Cipher.DECRYPT_MODE, secret);
    +            ${ev.value} = UTF8String.fromBytes(cipher.doFinal($str, 0, $str.length));
    +          } catch (java.security.GeneralSecurityException e) {
    --- End diff --
    
    make codegen version more consistent with non-codegen version. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169707166
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48943/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53546023
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,42 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java
    +   * Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If
    +   * either argument is NULL, the result will also be null. If input is invalid, key length is not
    +   * one of the permitted values or using 192/256 bits key before installing JCE, an exception will
    +   * be thrown.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    What are the other examples?



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51355182
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890".getBytes))), null)
    +    // key is null
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType))), null)
    +    // both are null
    +    checkEvaluation(Base64(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType))), null)
    +  }
    +
    +  test("aesDecrypt") {
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes)), "ABC")
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes)), "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +  }
    +
    +  ignore("aesEncryptWith256bitsKey") {
    --- End diff --
    
    please add a comment to explain why we ignore it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169172817
  
    cc @cloud-fan @marmbrus @davies


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52596991
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -442,3 +444,88 @@ case class PrintToStderr(child: Expression) extends UnaryExpression {
            """.stripMargin)
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    --- End diff --
    
    pls update the doc


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177383345
  
    **[Test build #50456 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50456/consoleFull)** for PR 10527 at commit [`3a2510b`](https://github.com/apache/spark/commit/3a2510b4121cbee6343df72162dfff869ffee5dc).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186147409
  
    LGTM overall


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-182034604
  
    **[Test build #50990 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50990/consoleFull)** for PR 10527 at commit [`1de0453`](https://github.com/apache/spark/commit/1de0453ab64a94af97b1c65528762fcece198624).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169528978
  
    **[Test build #48890 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48890/consoleFull)** for PR 10527 at commit [`ed38390`](https://github.com/apache/spark/commit/ed38390da49818efeae9260b3a4ce0d53173f57b).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by davies <gi...@git.apache.org>.
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53545875
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,42 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java
    +   * Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If
    +   * either argument is NULL, the result will also be null. If input is invalid, key length is not
    +   * one of the permitted values or using 192/256 bits key before installing JCE, an exception will
    +   * be thrown.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    Key is not integer, it's binary, see examples.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168098311
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48511/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168921730
  
    **[Test build #48744 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48744/consoleFull)** for PR 10527 at commit [`27693b4`](https://github.com/apache/spark/commit/27693b4e251163754a8487d8ee523920e37518b8).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r50214041
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -130,4 +130,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // Before testing this, installing Java Cryptography Extension (JCE)
    +    // Unlimited Strength Jurisdiction Policy Files first
    +//    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +//      Literal("12345678901234561234567890123456".getBytes))), "nYfCuJeRd5eD60yXDw7WEA==")
    --- End diff --
    
    @marmbrus When Java Cryptography Extension (JCE) not installed under oracle jdk, it will return `null` and will not break other things. Plus, we don't need to worry about installing this extension under openjdk, it works fine with openjdk.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186180676
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51176492
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // Before testing this, installing Java Cryptography Extension (JCE)
    +    // Unlimited Strength Jurisdiction Policy Files first
    +//    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    --- End diff --
    
    can we move it into a new test case and ignore it? i.e.
    ```
    ignore("your test name") {
      ....
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53545860
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,42 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java
    +   * Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If
    +   * either argument is NULL, the result will also be null. If input is invalid, key length is not
    +   * one of the permitted values or using 192/256 bits key before installing JCE, an exception will
    +   * be thrown.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    key should just be an int


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49035587
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -221,3 +224,147 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         """
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    + 'y6Ss+zCYObpCbgfWfyNWTw=='"""
    +)
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: InvalidKeyException => null
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            try {
    +              if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +                cipher.init($Cipher.ENCRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +                ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +              } else {
    +                ${ev.isNull} = true;
    +              }
    +            } catch (java.security.InvalidKeyException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.IllegalBlockSizeException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.BadPaddingException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            }
    +          } catch(java.security.NoSuchAlgorithmException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          } catch(javax.crypto.NoSuchPaddingException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = """_FUNC_(input, key) - Decrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended =
    +    """> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');
    + 'ABC'"""
    +)
    +case class AesDecrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    --- End diff --
    
    done.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52837685
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,40 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    +    AesEncrypt(input.expr, key.expr)
    +  }
    +
    +  /**
    +   * Decrypts input using AES and Returns the result as a string column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to decrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_decrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    @davies Sure, I can do this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51355228
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890".getBytes))), null)
    +    // key is null
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType))), null)
    +    // both are null
    +    checkEvaluation(Base64(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType))), null)
    +  }
    +
    +  test("aesDecrypt") {
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes)), "ABC")
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes)), "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +  }
    +
    +  ignore("aesEncryptWith256bitsKey") {
    --- End diff --
    
    will do.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-182078182
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-182078190
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/50990/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186180158
  
    **[Test build #51549 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51549/consoleFull)** for PR 10527 at commit [`60b9da7`](https://github.com/apache/spark/commit/60b9da7cfe13a0825d114d5a44be61588c762aff).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186523445
  
    @vectorijk I've reverted the patch. Can you reopen the pull request and fix the return types?



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-185644283
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/51476/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175987441
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/50243/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186028961
  
    **[Test build #51508 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51508/consoleFull)** for PR 10527 at commit [`8e2960c`](https://github.com/apache/spark/commit/8e2960ce68676ea7cb09683b1e1556ccf2114053).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by marmbrus <gi...@git.apache.org>.
Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r50161066
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -130,4 +130,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // Before testing this, installing Java Cryptography Extension (JCE)
    +    // Unlimited Strength Jurisdiction Policy Files first
    +//    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +//      Literal("12345678901234561234567890123456".getBytes))), "nYfCuJeRd5eD60yXDw7WEA==")
    --- End diff --
    
    I think it might be okay, as long as the failure is clear and it doesn't break other things when its not installed.  What happens when its not installed?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r48919100
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -221,3 +224,147 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         """
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    + 'y6Ss+zCYObpCbgfWfyNWTw=='"""
    +)
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: InvalidKeyException => null
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            try {
    +              if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +                cipher.init($Cipher.ENCRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +                ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +              } else {
    +                ${ev.isNull} = true;
    +              }
    +            } catch (java.security.InvalidKeyException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.IllegalBlockSizeException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.BadPaddingException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            }
    +          } catch(java.security.NoSuchAlgorithmException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          } catch(javax.crypto.NoSuchPaddingException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = """_FUNC_(input, key) - Decrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended =
    +    """> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');
    + 'ABC'"""
    +)
    +case class AesDecrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = StringType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.DECRYPT_MODE, secretKey)
    +      UTF8String.fromBytes(
    +        cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0,
    +          input1.asInstanceOf[Array[Byte]].length))
    +    } catch {
    +      case e: InvalidKeyException => UTF8String.fromBytes(null)
    +    }
    +
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            try {
    +              if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +                cipher.init($Cipher.DECRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +                ${ev.value} = UTF8String.fromBytes(cipher.doFinal($str, 0, $str.length));
    +              } else {
    +                ${ev.isNull} = true;
    +              }
    +            } catch (java.security.InvalidKeyException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.IllegalBlockSizeException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.BadPaddingException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            }
    +          } catch(java.security.NoSuchAlgorithmException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          } catch(javax.crypto.NoSuchPaddingException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    --- End diff --
    
    why there are much more exceptions than the non-codegen version?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49036509
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -221,3 +224,147 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         """
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    + 'y6Ss+zCYObpCbgfWfyNWTw=='"""
    +)
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: InvalidKeyException => null
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            try {
    +              if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +                cipher.init($Cipher.ENCRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +                ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +              } else {
    +                ${ev.isNull} = true;
    +              }
    +            } catch (java.security.InvalidKeyException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.IllegalBlockSizeException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.BadPaddingException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            }
    +          } catch(java.security.NoSuchAlgorithmException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          } catch(javax.crypto.NoSuchPaddingException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = """_FUNC_(input, key) - Decrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended =
    +    """> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');
    + 'ABC'"""
    +)
    +case class AesDecrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = StringType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.DECRYPT_MODE, secretKey)
    +      UTF8String.fromBytes(
    +        cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0,
    +          input1.asInstanceOf[Array[Byte]].length))
    +    } catch {
    +      case e: InvalidKeyException => UTF8String.fromBytes(null)
    +    }
    +
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            try {
    +              if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +                cipher.init($Cipher.DECRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +                ${ev.value} = UTF8String.fromBytes(cipher.doFinal($str, 0, $str.length));
    +              } else {
    +                ${ev.isNull} = true;
    +              }
    +            } catch (java.security.InvalidKeyException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.IllegalBlockSizeException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.BadPaddingException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            }
    +          } catch(java.security.NoSuchAlgorithmException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          } catch(javax.crypto.NoSuchPaddingException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    --- End diff --
    
    Cause I added these catching blocks according to the error messages of executing `generated.java` when missing those exceptions catching.
    I have updated and used only one catching block with `java.security.GeneralSecurityException`. (`GeneralSecurityException` is the superclass of those `*Exception`s. )
    Is it more better?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168055338
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48484/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51175633
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,131 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    --- End diff --
    
    we should follow the style of other classes in this file, i.e. use double quotation marks and `\n`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-182851144
  
    LGTM except some minor comments, thanks for working on it!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168931880
  
    **[Test build #48748 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48748/consoleFull)** for PR 10527 at commit [`0558bf8`](https://github.com/apache/spark/commit/0558bf8b698e9de7e19625627e487bfb3f33072d).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169542537
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48890/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175932469
  
    Build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49922804
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -130,4 +130,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // Before testing this, installing Java Cryptography Extension (JCE)
    +    // Unlimited Strength Jurisdiction Policy Files first
    +//    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +//      Literal("12345678901234561234567890123456".getBytes))), "nYfCuJeRd5eD60yXDw7WEA==")
    --- End diff --
    
    I'm not sure if we can introduce a feature that may require extra installation... cc @rxin @marmbrus 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-183633038
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/51235/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52838489
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,69 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType))), null)
    +    // both are null
    +    checkEvaluation(Base64(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType))), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesEncrypt(Literal("ABC".getBytes), Literal("1234567890".getBytes)))
    +    }
    +  }
    +
    +  test("aesDecrypt") {
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes)), "ABC")
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes)), "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    --- End diff --
    
    This only tests interpreted version, we also need to test codegen version, i.e. create an unsafe projection using `AesDecrypt` and execute it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168976826
  
    Build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53442267
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,88 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    val expr1 = AesEncrypt(Literal("ABC".getBytes), Literal("1234567890123456".getBytes))
    +    val expr2 = AesEncrypt(Literal("".getBytes), Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(Base64(expr1), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(expr2), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType)), null)
    +
    +    val expr3 = AesEncrypt(Literal("ABC".getBytes), Literal("1234567890".getBytes))
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(expr3)
    +    }
    +    intercept[java.security.InvalidKeyException] {
    +      UnsafeProjection.create(expr3::Nil).apply(null)
    +    }
    +  }
    +
    +  test("aesDecrypt") {
    +    val expr1 = AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes))
    +    val expr2 = AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(expr1, "ABC")
    +    checkEvaluation(expr2, "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +
    +    val expr3 = AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890".getBytes))
    +    val expr4 = AesDecrypt(UnBase64(Literal("y6Ss+zCsdYObpCbgfWfyNW3Twewr")),
    +      Literal("1234567890123456".getBytes))
    +    val expr5 = AesDecrypt(UnBase64(Literal("t6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes))
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(expr3)
    +    }
    +    intercept[java.security.InvalidKeyException] {
    +      UnsafeProjection.create(expr3::Nil).apply(null)
    --- End diff --
    
    nit: `expr3 :: Nil`, we should add space


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-183633037
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186184562
  
    **[Test build #51551 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51551/consoleFull)** for PR 10527 at commit [`0856fb0`](https://github.com/apache/spark/commit/0856fb0cad6f19a1a1ae2411729b7ad644bd65c7).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168055286
  
    **[Test build #48484 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48484/consoleFull)** for PR 10527 at commit [`9edeba7`](https://github.com/apache/spark/commit/9edeba7d124f6a9e0ed7b7949b6fd10f26929706).
     * This patch **fails from timeout after a configured wait of \`250m\`**.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `case class AesDecrypt(left: Expression, right: Expression)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168976829
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48744/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51372548
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    --- End diff --
    
    I'd say in this case we should rethrow the exception to fail everything. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186147572
  
    **[Test build #51549 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51549/consoleFull)** for PR 10527 at commit [`60b9da7`](https://github.com/apache/spark/commit/60b9da7cfe13a0825d114d5a44be61588c762aff).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49392128
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -130,4 +130,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // Before testing this, installing Java Cryptography Extension (JCE)
    +    // Unlimited Strength Jurisdiction Policy Files first
    +//    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +//      Literal("12345678901234561234567890123456".getBytes))), "nYfCuJeRd5eD60yXDw7WEA==")
    --- End diff --
    
    why does only this test need extra installation?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168976748
  
    **[Test build #48744 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48744/consoleFull)** for PR 10527 at commit [`27693b4`](https://github.com/apache/spark/commit/27693b4e251163754a8487d8ee523920e37518b8).
     * This patch **fails from timeout after a configured wait of \`250m\`**.
     * This patch **does not merge cleanly**.
     * This patch adds the following public classes _(experimental)_:
      * `case class AesDecrypt(left: Expression, right: Expression)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53545856
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,40 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    +    AesEncrypt(input.expr, key.expr)
    +  }
    +
    +  /**
    +   * Decrypts input using AES and Returns the result as a string column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to decrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_decrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    key should just be an integer here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168098310
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-185644281
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186523636
  
    Ok, Sure. I will do.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177402811
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/50456/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52597144
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -442,3 +444,88 @@ case class PrintToStderr(child: Expression) extends UnaryExpression {
            """.stripMargin)
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +      input2.asInstanceOf[Array[Byte]].length, "AES")
    +    cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +    cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +  }
    +
    +  override def genCode(ctx: CodegenContext, ev: ExprCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            $SecretKeySpec secret = new $SecretKeySpec($key, 0, $key.length, "AES");
    +            cipher.init($Cipher.ENCRYPT_MODE, secret);
    +            ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +          } catch (java.security.GeneralSecurityException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    --- End diff --
    
    pls update the doc


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by davies <gi...@git.apache.org>.
Github user davies commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186523782
  
    I did not look into this closely, since @cloud-fan already reviewed this many rounds. sorry for the rush.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r48918992
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -221,3 +224,147 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         """
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    + 'y6Ss+zCYObpCbgfWfyNWTw=='"""
    +)
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: InvalidKeyException => null
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            try {
    +              if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +                cipher.init($Cipher.ENCRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +                ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +              } else {
    +                ${ev.isNull} = true;
    +              }
    +            } catch (java.security.InvalidKeyException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.IllegalBlockSizeException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.BadPaddingException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            }
    +          } catch(java.security.NoSuchAlgorithmException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          } catch(javax.crypto.NoSuchPaddingException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = """_FUNC_(input, key) - Decrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended =
    +    """> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');
    + 'ABC'"""
    +)
    +case class AesDecrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = StringType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.DECRYPT_MODE, secretKey)
    +      UTF8String.fromBytes(
    +        cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0,
    +          input1.asInstanceOf[Array[Byte]].length))
    +    } catch {
    +      case e: InvalidKeyException => UTF8String.fromBytes(null)
    --- End diff --
    
    can we just use `null`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53431192
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,40 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    +    AesEncrypt(input.expr, key.expr)
    +  }
    +
    +  /**
    +   * Decrypts input using AES and Returns the result as a string column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to decrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_decrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    @davies addressed this. Could you take a look again?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177415020
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53440993
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,92 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    val expr1 = AesEncrypt(Literal("ABC".getBytes), Literal("1234567890123456".getBytes))
    +    val expr2 = AesEncrypt(Literal("".getBytes), Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(Base64(expr1), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(expr2), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType)), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesEncrypt(Literal("ABC".getBytes), Literal("1234567890".getBytes)))
    +    }
    +
    +    // check codegen
    +    val instance1 = UnsafeProjection.create(Base64(expr1) :: Nil)
    +    assert(instance1.apply(null).getString(0) === "y6Ss+zCYObpCbgfWfyNWTw==")
    +
    +    val instance2 = UnsafeProjection.create(Base64(expr2) :: Nil)
    +    assert(instance2.apply(null).getString(0) === "BQGHoM3lqYcsurCRq3PlUw==")
    +  }
    +
    +  test("aesDecrypt") {
    +    val expr1 = AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes))
    +    val expr2 = AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(expr1, "ABC")
    +    checkEvaluation(expr2, "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +        Literal("1234567890".getBytes)))
    +    }
    +
    +    // input can not be decrypted
    +    intercept[javax.crypto.IllegalBlockSizeException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("y6Ss+zCsdYObpCbgfWfyNW3Twewr")),
    +        Literal("1234567890123456".getBytes)));
    +    }
    +
    +    // input can not be decrypted
    +    intercept[javax.crypto.BadPaddingException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("t6Ss+zCYObpCbgfWfyNWTw==")),
    +        Literal("1234567890123456".getBytes)));
    +    }
    +
    +    // check codegen
    +    val instance1 = UnsafeProjection.create(expr1 :: Nil)
    +    assert(instance1.apply(null).getString(0) === "ABC")
    +
    +    val instance2 = UnsafeProjection.create(expr2 :: Nil)
    +    assert(instance2.apply(null).getString(0) === "")
    --- End diff --
    
    Okay, Done that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49921561
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -130,4 +130,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // Before testing this, installing Java Cryptography Extension (JCE)
    +    // Unlimited Strength Jurisdiction Policy Files first
    +//    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +//      Literal("12345678901234561234567890123456".getBytes))), "nYfCuJeRd5eD60yXDw7WEA==")
    --- End diff --
    
    ping @cloud-fan?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186159941
  
    **[Test build #51551 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51551/consoleFull)** for PR 10527 at commit [`0856fb0`](https://github.com/apache/spark/commit/0856fb0cad6f19a1a1ae2411729b7ad644bd65c7).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by davies <gi...@git.apache.org>.
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52836278
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,40 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    +    AesEncrypt(input.expr, key.expr)
    +  }
    +
    +  /**
    +   * Decrypts input using AES and Returns the result as a string column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to decrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_decrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    Could you also add the Python API?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177415021
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/50457/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177402801
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53546060
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -442,3 +444,90 @@ case class PrintToStderr(child: Expression) extends UnaryExpression {
            """.stripMargin)
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used. 192
    + * and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdic-
    + * tion Policy Files are installed. If either argument is NULL, the result will also be null. If
    + * input is invalid, key length is not one of the permitted values or using 192/256 bits key before
    + * installing JCE, an exception will be thrown.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +      input2.asInstanceOf[Array[Byte]].length, "AES")
    +    cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +    cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +  }
    +
    +  override def genCode(ctx: CodegenContext, ev: ExprCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            $SecretKeySpec secret = new $SecretKeySpec($key, 0, $key.length, "AES");
    +            cipher.init($Cipher.ENCRYPT_MODE, secret);
    +            ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +          } catch (java.security.GeneralSecurityException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used. 192
    + * and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdic-
    + * tion Policy Files are installed. If either argument is NULL, the result will also be null. If
    + * input is invalid, key length is not one of the permitted values or using 192/256 bits key before
    + * installing JCE, an exception will be thrown.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Decrypts input using AES.",
    +  extended = "> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');\n 'ABC'")
    +case class AesDecrypt(left: Expression, right: Expression)
    --- End diff --
    
    i find it confusing to have left/right here (e.g. input, key)
    
    Let's give them a proper name, and then just `override def left: Expression = input`.
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175932477
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/50245/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49436980
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -130,4 +130,49 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // Before testing this, installing Java Cryptography Extension (JCE)
    +    // Unlimited Strength Jurisdiction Policy Files first
    +//    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +//      Literal("12345678901234561234567890123456".getBytes))), "nYfCuJeRd5eD60yXDw7WEA==")
    --- End diff --
    
    Because Oracle JRE/JDK supports AES-128 out of the box. AES-192 and AES-256 are supported if Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. In this test case, key size is 256 bits. We should install JCE not only with this test also any test with 192/256 bits key. I commented out this test by default in case this test fails.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169542246
  
    **[Test build #48890 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48890/consoleFull)** for PR 10527 at commit [`ed38390`](https://github.com/apache/spark/commit/ed38390da49818efeae9260b3a4ce0d53173f57b).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51372158
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    --- End diff --
    
    https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala#L336
    
    we wrap everything in an analysis exception during expression construction.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49035594
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -221,3 +224,147 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         """
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    + 'y6Ss+zCYObpCbgfWfyNWTw=='"""
    +)
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: InvalidKeyException => null
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            try {
    +              if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +                cipher.init($Cipher.ENCRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +                ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +              } else {
    +                ${ev.isNull} = true;
    +              }
    +            } catch (java.security.InvalidKeyException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.IllegalBlockSizeException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            } catch (javax.crypto.BadPaddingException e) {
    +              org.apache.spark.unsafe.Platform.throwException(e);
    +            }
    +          } catch(java.security.NoSuchAlgorithmException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          } catch(javax.crypto.NoSuchPaddingException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = """_FUNC_(input, key) - Decrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended =
    +    """> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');
    + 'ABC'"""
    +)
    +case class AesDecrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with Serializable with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = StringType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.DECRYPT_MODE, secretKey)
    +      UTF8String.fromBytes(
    +        cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0,
    +          input1.asInstanceOf[Array[Byte]].length))
    +    } catch {
    +      case e: InvalidKeyException => UTF8String.fromBytes(null)
    --- End diff --
    
    done.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186528815
  
    I would also just remove support for 192/256, so we don't have to explain the JCE stuff.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52554453
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -442,3 +444,88 @@ case class PrintToStderr(child: Expression) extends UnaryExpression {
            """.stripMargin)
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +      input2.asInstanceOf[Array[Byte]].length, "AES")
    +    cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +    cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +  }
    +
    +  override def genCode(ctx: CodegenContext, ev: ExprCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            $SecretKeySpec secret = new $SecretKeySpec($key, 0, $key.length, "AES");
    +            cipher.init($Cipher.ENCRYPT_MODE, secret);
    +            ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +          } catch (java.security.GeneralSecurityException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    --- End diff --
    
    If key parameter is invalid, length of key is invalid or 192/256 bits key is not supported, all of those cases will throw exception.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-183616365
  
    @cloud-fan Thanks so much for your code review! There is the update for the doc and error cases review.    :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53546094
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -442,3 +444,90 @@ case class PrintToStderr(child: Expression) extends UnaryExpression {
            """.stripMargin)
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used. 192
    + * and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdic-
    + * tion Policy Files are installed. If either argument is NULL, the result will also be null. If
    + * input is invalid, key length is not one of the permitted values or using 192/256 bits key before
    + * installing JCE, an exception will be thrown.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +      input2.asInstanceOf[Array[Byte]].length, "AES")
    +    cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +    cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +  }
    +
    +  override def genCode(ctx: CodegenContext, ev: ExprCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            $SecretKeySpec secret = new $SecretKeySpec($key, 0, $key.length, "AES");
    +            cipher.init($Cipher.ENCRYPT_MODE, secret);
    +            ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +          } catch (java.security.GeneralSecurityException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used. 192
    + * and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdic-
    + * tion Policy Files are installed. If either argument is NULL, the result will also be null. If
    + * input is invalid, key length is not one of the permitted values or using 192/256 bits key before
    + * installing JCE, an exception will be thrown.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Decrypts input using AES.",
    +  extended = "> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');\n 'ABC'")
    +case class AesDecrypt(left: Expression, right: Expression)
    --- End diff --
    
    also if the key is literal, i'd just do some input data type checking in analysis (override checkInputTypes) to make sure the key is in acceptable range.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-183632986
  
    **[Test build #51235 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51235/consoleFull)** for PR 10527 at commit [`6bc1b63`](https://github.com/apache/spark/commit/6bc1b631647a8a8052756c4649acc52783737205).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53431980
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,69 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal("1234567890123456".getBytes))), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(AesEncrypt(Literal("".getBytes),
    +      Literal("1234567890123456".getBytes))), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(Base64(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType))), null)
    +    // both are null
    +    checkEvaluation(Base64(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType))), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesEncrypt(Literal("ABC".getBytes), Literal("1234567890".getBytes)))
    +    }
    +  }
    +
    +  test("aesDecrypt") {
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes)), "ABC")
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes)), "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    --- End diff --
    
    @cloud-fan I added codegen version tests with creating unsafe projection. But I'm not very sure whether I am doing right or not. Could you take a look again?
    Meanwhile, I took look at code `ExpressionEvalHelper.scala` [`checkEvalutionWithUnsafeProjection()`](https://github.com/apache/spark/blob/master/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvalHelper.scala#L123-L149). Is that doing the same thing as you said to test codegen version?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186029116
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/51508/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51685863
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    --- End diff --
    
    @cloud-fan okay, i will try to rethrow exception as `Encode`/`Decode` does. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-185615325
  
    **[Test build #51476 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51476/consoleFull)** for PR 10527 at commit [`dc76057`](https://github.com/apache/spark/commit/dc760570b594d100aeda7ce181edc8a3572a59c2).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168963051
  
    **[Test build #48748 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48748/consoleFull)** for PR 10527 at commit [`0558bf8`](https://github.com/apache/spark/commit/0558bf8b698e9de7e19625627e487bfb3f33072d).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `case class AesEncrypt(left: Expression, right: Expression)`
      * `case class AesDecrypt(left: Expression, right: Expression)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186184785
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-183623401
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51355177
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    --- End diff --
    
    I'm not quite sure how we should deal with errors, return null or throw exception? cc @marmbrus 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-175813080
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-183623402
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/51233/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186738494
  
    Sorry missed the symmetry part, but it is symmetric underneath, except `AesDecrypt` wrap the bytes into a string at last. We should return binary directly, sorry for the rush.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52824805
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,40 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    +    AesEncrypt(input.expr, key.expr)
    +  }
    +
    +  /**
    +   * Decrypts input using AES and Returns the result as a string column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to decrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_decrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    We have test case for this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51685577
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    --- End diff --
    
    yea, you followed `Sha2`, but `Sha2` may also be wrong. In this case we think rethrow exception makes more sense, and we can also fix `Sha2` later.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-183624210
  
    **[Test build #51235 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/51235/consoleFull)** for PR 10527 at commit [`6bc1b63`](https://github.com/apache/spark/commit/6bc1b631647a8a8052756c4649acc52783737205).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168098250
  
    **[Test build #48511 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48511/consoleFull)** for PR 10527 at commit [`9edeba7`](https://github.com/apache/spark/commit/9edeba7d124f6a9e0ed7b7949b6fd10f26929706).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `case class AesDecrypt(left: Expression, right: Expression)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186523374
  
    Sorry I'm not convinced this is correct (decrypt returning string type), and there are other issues with it. I'm just going to revert the patch, since it is unlikely other things will conflict with this.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by davies <gi...@git.apache.org>.
Github user davies commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186520228
  
    LGTM, merging this into master, thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53435449
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala ---
    @@ -132,4 +132,92 @@ class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    val expr1 = AesEncrypt(Literal("ABC".getBytes), Literal("1234567890123456".getBytes))
    +    val expr2 = AesEncrypt(Literal("".getBytes), Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(Base64(expr1), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(expr2), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType)), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesEncrypt(Literal("ABC".getBytes), Literal("1234567890".getBytes)))
    +    }
    +
    +    // check codegen
    +    val instance1 = UnsafeProjection.create(Base64(expr1) :: Nil)
    +    assert(instance1.apply(null).getString(0) === "y6Ss+zCYObpCbgfWfyNWTw==")
    +
    +    val instance2 = UnsafeProjection.create(Base64(expr2) :: Nil)
    +    assert(instance2.apply(null).getString(0) === "BQGHoM3lqYcsurCRq3PlUw==")
    +  }
    +
    +  test("aesDecrypt") {
    +    val expr1 = AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes))
    +    val expr2 = AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(expr1, "ABC")
    +    checkEvaluation(expr2, "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +        Literal("1234567890".getBytes)))
    +    }
    +
    +    // input can not be decrypted
    +    intercept[javax.crypto.IllegalBlockSizeException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("y6Ss+zCsdYObpCbgfWfyNW3Twewr")),
    +        Literal("1234567890123456".getBytes)));
    +    }
    +
    +    // input can not be decrypted
    +    intercept[javax.crypto.BadPaddingException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("t6Ss+zCYObpCbgfWfyNWTw==")),
    +        Literal("1234567890123456".getBytes)));
    +    }
    +
    +    // check codegen
    +    val instance1 = UnsafeProjection.create(expr1 :: Nil)
    +    assert(instance1.apply(null).getString(0) === "ABC")
    +
    +    val instance2 = UnsafeProjection.create(expr2 :: Nil)
    +    assert(instance2.apply(null).getString(0) === "")
    --- End diff --
    
    The above 2 are not needed. Normal cases are already covered by `checkEvaluation`, we only need to test error case


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177402550
  
    **[Test build #50456 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50456/consoleFull)** for PR 10527 at commit [`3a2510b`](https://github.com/apache/spark/commit/3a2510b4121cbee6343df72162dfff869ffee5dc).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by davies <gi...@git.apache.org>.
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r52693618
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
    @@ -1931,6 +1931,40 @@ object functions extends LegacyFunctions {
         new Murmur3Hash(cols.map(_.expr))
       }
     
    +  /**
    +   * Encrypts input using AES and Returns the result as a binary column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to encrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_encrypt(input: Column, key: Column): Column = withExpr {
    +    AesEncrypt(input.expr, key.expr)
    +  }
    +
    +  /**
    +   * Decrypts input using AES and Returns the result as a string column.
    +   * Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if
    +   * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed.
    +   * If either argument is NULL or the key length is not one of the permitted values,
    +   * the result will also be null.
    +   *
    +   * @param input binary column to decrypt input
    +   * @param key binary column of 128, 192 or 256 bits key
    +   *
    +   * @group misc_funcs
    +   * @since 2.0.0
    +   */
    +  def aes_decrypt(input: Column, key: Column): Column = withExpr {
    --- End diff --
    
    Could you have a test case for this?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168082721
  
    Jenkins, retest this please.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by vectorijk <gi...@git.apache.org>.
Github user vectorijk commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-186738840
  
    Thanks so much for suggestion! I will open a new PR for update.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-169542536
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51371194
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    --- End diff --
    
    I checked some similar expressions, `Encode`/`Decode` will throw exception if its charset string parameter is invalid, `Sha2` will return null if its bit length parameter is invalid.
    
    For `AesEncrypt`, what we should do if its secret key parameter is invalid? @vectorijk are there any other errors will be thrown during execution?
    
    cc @rxin , what's the general rule for this kind of stuff?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r49043365
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -221,3 +224,127 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         """
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage =
    +    """_FUNC_(input, key) - Encrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended = """> SELECT Base64(_FUNC_('ABC', '1234567890123456'));
    + 'y6Ss+zCYObpCbgfWfyNWTw=='"""
    +)
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +              cipher.init($Cipher.ENCRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +              ${ev.value} = cipher.doFinal($str, 0, $str.length);
    +            } else {
    +              ${ev.isNull} = true;
    +            }
    +          } catch (java.security.GeneralSecurityException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    +          }
    +      """
    +    })
    +  }
    +}
    +
    +/**
    + * A function that decrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = """_FUNC_(input, key) - Decrypts input using AES. Key lengths of 128, 192 or 256 bits can
    + be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one
    + of the permitted values, the return value is NULL.""",
    +  extended =
    +    """> SELECT _FUNC_(UnBase64('y6Ss+zCYObpCbgfWfyNWTw=='),'1234567890123456');
    + 'ABC'"""
    +)
    +case class AesDecrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = StringType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.DECRYPT_MODE, secretKey)
    +      UTF8String.fromBytes(
    +        cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0,
    +          input1.asInstanceOf[Array[Byte]].length))
    +    } catch {
    +      case e: GeneralSecurityException => null
    +    }
    +
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    +    nullSafeCodeGen(ctx, ev, (str, key) => {
    +      val Cipher = "javax.crypto.Cipher"
    +      val SecretKeySpec = "javax.crypto.spec.SecretKeySpec"
    +      s"""
    +          try {
    +            $Cipher cipher = $Cipher.getInstance("AES");
    +            if ($key.length == 16 || $key.length == 24 || $key.length == 32) {
    +              cipher.init($Cipher.DECRYPT_MODE, new $SecretKeySpec($key, 0, $key.length, "AES"));
    +              ${ev.value} = UTF8String.fromBytes(cipher.doFinal($str, 0, $str.length));
    +            } else {
    +              ${ev.isNull} = true;
    +            }
    +          } catch (java.security.GeneralSecurityException e) {
    +            org.apache.spark.unsafe.Platform.throwException(e);
    --- End diff --
    
    So when exception happens, codegen version will throw it, and the interpreted version will return null?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-182076974
  
    **[Test build #50990 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50990/consoleFull)** for PR 10527 at commit [`1de0453`](https://github.com/apache/spark/commit/1de0453ab64a94af97b1c65528762fcece198624).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r51372496
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala ---
    @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression
         }
       }
     }
    +
    +/**
    + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used.
    + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength
    + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is
    + * not one of the permitted values, the return value is NULL.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(input, key) - Encrypts input using AES.",
    +  extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='")
    +case class AesEncrypt(left: Expression, right: Expression)
    +  extends BinaryExpression with ImplicitCastInputTypes {
    +
    +  override def dataType: DataType = BinaryType
    +  override def nullable: Boolean = true
    +
    +  override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
    +
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val cipher = Cipher.getInstance("AES")
    +    val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match {
    +      case 16 | 24 | 32 =>
    +        new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0,
    +          input2.asInstanceOf[Array[Byte]].length, "AES")
    +      case _ => null
    +    }
    +
    +    try {
    +      cipher.init(Cipher.ENCRYPT_MODE, secretKey)
    +      cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length)
    +    } catch {
    +      case e: GeneralSecurityException => null
    --- End diff --
    
    it's not during construction, but execution. The parameters may be non-foldable and we can only know it's valid or not during execution. BTW the encrypting process may fail and throw exception, should we silently ignore it and return null, or rethrow the exception and fail the execution?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-168963322
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48748/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12567][SQL] Add aes_{encrypt,decrypt} U...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10527#issuecomment-177399861
  
    **[Test build #50457 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50457/consoleFull)** for PR 10527 at commit [`04a14cf`](https://github.com/apache/spark/commit/04a14cf072630fbe3619bf241ff3d10d383594a5).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org