[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-21 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16096252#comment-16096252
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user asfgit closed the pull request at:

https://github.com/apache/drill/pull/865


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting, ready-to-commit
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-14 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16087150#comment-16087150
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on the issue:

https://github.com/apache/drill/pull/865
  
+1, checked the latest changes and ran unit tests.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16086841#comment-16086841
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127383405
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16086839#comment-16086839
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127383363
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16086840#comment-16086840
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127383370
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085578#comment-16085578
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127193320
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085576#comment-16085576
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127193061
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085577#comment-16085577
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127193243
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085573#comment-16085573
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127193132
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
--- End diff --

Can be removed since we don't need it anymore. See explanation below.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085575#comment-16085575
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127193358
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085571#comment-16085571
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127193028
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085572#comment-16085572
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127192939
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-13 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085574#comment-16085574
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127193228
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-12 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16085208#comment-16085208
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127132444
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-12 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16084257#comment-16084257
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r127004765
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md5Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * sha() / sha1(): Calculates an SHA-1 160-bit checksum for 
the string, as described in RFC 3174 (Secure Hash Algorithm).
+   * (https://en.wikipedia.org/wiki/SHA-1) The value is returned as a 
string of 40 hexadecimal digits, or NULL if the argument was NULL.
+   * Note that sha() and sha1() are aliases for the same function.
+   *
+   * > select sha1( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16076936#comment-16076936
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user parthchandra commented on the issue:

https://github.com/apache/drill/pull/865
  
AES is specifically restricted. Can you check on commons-codec and see what 
it uses to implement AES support?


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting, ready-to-commit
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16075777#comment-16075777
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on the issue:

https://github.com/apache/drill/pull/865
  
Hi Parth, 
I need to look at AES, but on the page you sent it specifically said that 
all the digests (MD5, SHA) have no restrictions. 
—C 

> On Jul 5, 2017, at 16:33, Parth Chandra  wrote:
> 
> Has anyone checked the export requirements for these functions?
> https://www.apache.org/dev/crypto.html 

> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub 
, or mute the 
thread 
.
> 




> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting, ready-to-commit
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16075375#comment-16075375
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user parthchandra commented on the issue:

https://github.com/apache/drill/pull/865
  
Has anyone checked the export requirements for these functions? 
https://www.apache.org/dev/crypto.html




> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting, ready-to-commit
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread Arina Ielchiieva (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16074045#comment-16074045
 ] 

Arina Ielchiieva commented on DRILL-5634:
-

You are always welcome :) Thank you for making pull request!

> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting, ready-to-commit
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread Charles Givre (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16074044#comment-16074044
 ] 

Charles Givre commented on DRILL-5634:
--

Thanks for your help and patience!  [~arina]  (y(y)

> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting, ready-to-commit
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16074043#comment-16074043
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on the issue:

https://github.com/apache/drill/pull/865
  
+1, LGTM.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073887#comment-16073887
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125507297
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,395 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  String outputString = 
org.apache.commons.codec.digest.DigestUtils.md2Hex(input).toLowerCase();
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+  /**
+   * This function returns the MD5 digest of a given input string.
+   *  Usage is shown below:
+   *  select md5( 'testing' ) from (VALUES(1));
+   */
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
--- End diff --

Unused.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073886#comment-16073886
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125507167
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,395 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  /**
+   * This class returns the md2 digest of a given input string.
+   *  Usage is SELECT md2(  ) FROM ...
+   */
+
+  @FunctionTemplate(name = "md2", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD2Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
--- End diff --

Unused.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073774#comment-16073774
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125489210
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
+  String outputString = "";
+
+  try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+outputString = String.format("%032X", new java.math.BigInteger(1, 
thedigest));
+outputString = outputString.toLowerCase();
+
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA1Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+
+  String sha1 = 
org.apache.commons.codec.digest.DigestUtils.sha1Hex(input);
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = sha1.getBytes().length;
+  buffer.setBytes(0, sha1.getBytes());
+}
+
+  }
+
+  @FunctionTemplate(names = {"sha256", "sha2"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA256Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
   

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073768#comment-16073768
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125489004
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
+  String outputString = "";
+
+  try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+outputString = String.format("%032X", new java.math.BigInteger(1, 
thedigest));
+outputString = outputString.toLowerCase();
+
--- End diff --

Yes it can!  


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073750#comment-16073750
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125487229
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
+  String outputString = "";
+
+  try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+outputString = String.format("%032X", new java.math.BigInteger(1, 
thedigest));
+outputString = outputString.toLowerCase();
+
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA1Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+
+  String sha1 = 
org.apache.commons.codec.digest.DigestUtils.sha1Hex(input);
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = sha1.getBytes().length;
+  buffer.setBytes(0, sha1.getBytes());
+}
+
+  }
+
+  @FunctionTemplate(names = {"sha256", "sha2"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA256Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073753#comment-16073753
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125487364
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
--- End diff --

Fixed in latest version. 


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073745#comment-16073745
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user cgivre commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125486933
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
+  String outputString = "";
+
+  try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+outputString = String.format("%032X", new java.math.BigInteger(1, 
thedigest));
+outputString = outputString.toLowerCase();
+
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA1Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+
+  String sha1 = 
org.apache.commons.codec.digest.DigestUtils.sha1Hex(input);
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = sha1.getBytes().length;
+  buffer.setBytes(0, sha1.getBytes());
+}
+
+  }
+
+  @FunctionTemplate(names = {"sha256", "sha2"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA256Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073545#comment-16073545
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125456415
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
+  String outputString = "";
+
+  try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+outputString = String.format("%032X", new java.math.BigInteger(1, 
thedigest));
+outputString = outputString.toLowerCase();
+
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA1Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+
+  String sha1 = 
org.apache.commons.codec.digest.DigestUtils.sha1Hex(input);
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = sha1.getBytes().length;
+  buffer.setBytes(0, sha1.getBytes());
+}
+
+  }
+
+  @FunctionTemplate(names = {"sha256", "sha2"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA256Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
   

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073549#comment-16073549
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125453034
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
+  String outputString = "";
+
+  try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+outputString = String.format("%032X", new java.math.BigInteger(1, 
thedigest));
+outputString = outputString.toLowerCase();
+
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA1Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+
+  String sha1 = 
org.apache.commons.codec.digest.DigestUtils.sha1Hex(input);
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = sha1.getBytes().length;
+  buffer.setBytes(0, sha1.getBytes());
+}
+
+  }
+
+  @FunctionTemplate(names = {"sha256", "sha2"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA256Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
   

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073548#comment-16073548
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125448126
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
--- End diff --

1. Camel case...
2. There is no need to declare `theDigest` outside of try / catch block, 
since it's only used inside.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073547#comment-16073547
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125455477
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
+  String outputString = "";
+
+  try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+outputString = String.format("%032X", new java.math.BigInteger(1, 
thedigest));
+outputString = outputString.toLowerCase();
+
--- End diff --

In other functions you use `DigestUtils` as convert helper.
Can `String md5Hex = DigestUtils.md5Hex(input).toLowerCase()` be used here? 


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073546#comment-16073546
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125451645
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
+
+public class CryptoFunctions {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+  private CryptoFunctions() {
+  }
+
+  @FunctionTemplate(name = "md5", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class MD5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+  try {
+md = java.security.MessageDigest.getInstance("MD5");
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+  byte[] thedigest = null;
+  String outputString = "";
+
+  try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+outputString = String.format("%032X", new java.math.BigInteger(1, 
thedigest));
+outputString = outputString.toLowerCase();
+
+  } catch (Exception e) {
+logger.debug(e.getMessage());
+  }
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = outputString.getBytes().length;
+  buffer.setBytes(0, outputString.getBytes());
+}
+
+  }
+
+
+  @FunctionTemplate(names = {"sha", "sha1"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA1Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Override
+public void setup() {
+
+}
+
+@Override
+public void eval() {
+
+  String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start,
 rawInput.end, rawInput.buffer);
+
+  String sha1 = 
org.apache.commons.codec.digest.DigestUtils.sha1Hex(input);
+
+  out.buffer = buffer;
+  out.start = 0;
+  out.end = sha1.getBytes().length;
+  buffer.setBytes(0, sha1.getBytes());
+}
+
+  }
+
+  @FunctionTemplate(names = {"sha256", "sha2"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class SHA256Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder rawInput;
+
+@Output
+VarCharHolder out;
+
   

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-04 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16073544#comment-16073544
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125450075
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,315 @@
+/**
--- End diff --

Example, of correct Apache header usage - 
https://github.com/apache/drill/blob/master/exec/java-exec/src/main/java/org/apache/drill/exec/expr/BatchReference.java#L1-L16
We do have cases of when its included as Java doc but fix when encounter in 
code.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072199#comment-16072199
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125248660
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoHelperFunctions.java
 ---
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+
+public class CryptoHelperFunctions {
--- End diff --

Please add java doc describing the purpose of this class and also please 
add java doc to the methods below.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072191#comment-16072191
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125244029
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,315 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.inject.Inject;
+
+public class CryptoFunctions{
+static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+private CryptoFunctions() {}
+
+@FunctionTemplate(
+name = "md5",
+scope = FunctionTemplate.FunctionScope.SIMPLE,
+nulls = FunctionTemplate.NullHandling.NULL_IF_NULL
+)
+public static class md5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder raw_input;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+try {
+md = java.security.MessageDigest.getInstance("MD5");
+} catch( Exception e ) {
+}
+}
+
+@Override
+public void eval() {
+
+String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(raw_input.start,
 raw_input.end, raw_input.buffer);
+byte[] thedigest = null;
+String output_string = "";
+
+try {
+byte[] bytesOfMessage = input.getBytes("UTF-8");
+thedigest = md.digest(bytesOfMessage);
+output_string = String.format("%032X", new 
java.math.BigInteger(1, thedigest));
+output_string = output_string.toLowerCase();
+
+} catch( Exception e ) {
+}
--- End diff --

1. Please mind formatting.
2. If in case of error, we leave the defaults, then it's better  to at 
least log the exception.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes  

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072196#comment-16072196
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125249038
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,315 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.inject.Inject;
+
+public class CryptoFunctions{
--- End diff --

Please add java-doc to all the functions below (you have provided good 
description in Jira but its better if we'll have it in code).


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072195#comment-16072195
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125245365
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoHelperFunctions.java
 ---
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+
+public class CryptoHelperFunctions {
+
+private static SecretKeySpec secretKey;
+private static byte[] key;
+
+public static void setKey(String myKey)
+{
+MessageDigest sha = null;
+try {
+key = myKey.getBytes("UTF-8");
+sha = MessageDigest.getInstance("SHA-1");
+key = sha.digest(key);
+key = Arrays.copyOf(key, 16);
+secretKey = new SecretKeySpec(key, "AES");
+}
+catch (NoSuchAlgorithmException e) {
--- End diff --

1. Please use multi-catch.
2. Please remove e.printStackTrace() and log error instead here and in the 
code below.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072201#comment-16072201
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125246241
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCryptoFunctions.java
 ---
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.fn.impl;
+
+import org.apache.drill.BaseTestQuery;
+import org.junit.Test;
+
+public class TestCryptoFunctions extends BaseTestQuery {
+
+@Test
+public void testMD5() throws Exception {
+final String query = "select md5( 'testing' ) as md5_hash from 
(values(1))";
+testBuilder()
+.sqlQuery(query)
+.ordered()
+.baselineColumns("md5_hash")
+.baselineValues("ae2b1fca515949e5d54fb22b8ed95575")
+.go();
+}
+
+@Test
+public void testSHA1() throws Exception {
+final String query = "select sha( 'testing' ) as sha_hash from 
(values(1))";
--- End diff --

Please remove extra space here and in test below: `sha( 'testing' ) ` -> 
`sha('testing') `


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072200#comment-16072200
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125243131
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,315 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.inject.Inject;
+
+public class CryptoFunctions{
+static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+private CryptoFunctions() {}
+
+@FunctionTemplate(
+name = "md5",
+scope = FunctionTemplate.FunctionScope.SIMPLE,
+nulls = FunctionTemplate.NullHandling.NULL_IF_NULL
+)
+public static class md5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder raw_input;
--- End diff --

Please use camel case here and throughout the code.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072198#comment-16072198
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125243537
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,315 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.inject.Inject;
+
+public class CryptoFunctions{
+static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+private CryptoFunctions() {}
+
+@FunctionTemplate(
+name = "md5",
+scope = FunctionTemplate.FunctionScope.SIMPLE,
+nulls = FunctionTemplate.NullHandling.NULL_IF_NULL
+)
+public static class md5Function implements DrillSimpleFunc {
+
+@Param
+VarCharHolder raw_input;
+
+@Output
+VarCharHolder out;
+
+@Inject
+DrillBuf buffer;
+
+@Workspace
+java.security.MessageDigest md;
+
+@Override
+public void setup() {
+try {
+md = java.security.MessageDigest.getInstance("MD5");
+} catch( Exception e ) {
--- End diff --

Please use proper formatting here and throughout the code [1].

[1] https://drill.apache.org/docs/apache-drill-contribution-guidelines/


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072197#comment-16072197
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125248545
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoHelperFunctions.java
 ---
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+
+public class CryptoHelperFunctions {
+
+private static SecretKeySpec secretKey;
+private static byte[] key;
--- End diff --

In concurrent environment this code will be prone to produce incorrect 
results, since each thread may have its own key. Saving state in static 
variables is not thread-safe.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072193#comment-16072193
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125244592
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,315 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.inject.Inject;
+
+public class CryptoFunctions{
+static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(CryptoFunctions.class);
+
+private CryptoFunctions() {}
+
+@FunctionTemplate(
+name = "md5",
+scope = FunctionTemplate.FunctionScope.SIMPLE,
+nulls = FunctionTemplate.NullHandling.NULL_IF_NULL
+)
+public static class md5Function implements DrillSimpleFunc {
--- End diff --

I guess according to java naming convention class names should start with 
letter in upper case.
Please correct here and in classes below.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was 

[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16072192#comment-16072192
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

Github user arina-ielchiieva commented on a diff in the pull request:

https://github.com/apache/drill/pull/865#discussion_r125242571
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CryptoFunctions.java
 ---
@@ -0,0 +1,315 @@
+/**
--- End diff --

Please include Apache header in a form of comment. Please correct here and 
in files below.


> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
>  Labels: doc-impacting
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions

2017-07-02 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16071882#comment-16071882
 ] 

ASF GitHub Bot commented on DRILL-5634:
---

GitHub user cgivre opened a pull request:

https://github.com/apache/drill/pull/865

DRILL-5634 - Add Crypto and Hash Functions



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

$ git pull https://github.com/cgivre/drill master

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

https://github.com/apache/drill/pull/865.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 #865


commit a5accbd0d9d2defb6de488680b6c650021ae9931
Author: cgivre 
Date:   2017-07-03T03:13:02Z

Added Crypto Functions

commit 35f8002cf95a9376da3bcf930e9b0de585e6c952
Author: cgivre 
Date:   2017-07-03T03:18:39Z

Removed extraneous code




> Add Crypto and Hash Functions
> -
>
> Key: DRILL-5634
> URL: https://issues.apache.org/jira/browse/DRILL-5634
> Project: Apache Drill
>  Issue Type: New Feature
>  Components: Functions - Drill
>Affects Versions: 1.10.0
>Reporter: Charles Givre
> Fix For: 1.11.0
>
>
> This library contains a collection of cryptography-related functions for 
> Apache Drill. It generally mirrors the crypto functions in MySQL.  The 
> package includes:
> * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decryption 
> of data using the official AES (Advanced Encryption Standard) algorithm, 
> previously known as “Rijndael.”
>  `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str` and 
> returns a binary string containing the encrypted output. `AES_DECRYPT()` 
> decrypts the encrypted string `crypt_str` using the key string `key_str` and 
> returns the original cleartext string. If either function argument is NULL, 
> the function returns NULL.
> ```sql
> > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM 
> > (VALUES(1));
> +---+
> |aes|
> +---+
> | JkcBUNAn8ByKWCcVmNrKMA==  |
> +---+
>  > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted,
>  aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' 
> ),'my_secret_key') AS decrypted 
>  FROM (VALUES(1));
> +---+-+
> | encrypted |decrypted|
> +---+-+
> | JkcBUNAn8ByKWCcVmNrKMA==  | encrypted_text  |
> +---+-+
> ```
> * **`md5()`**:  Returns the md5 hash of the text. 
> (https://en.wikipedia.org/wiki/MD5)
> Usage:
> ```sql
> > select md5( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | ae2b1fca515949e5d54fb22b8ed95575  |
> +---+
> ```
> * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksum 
> for the string, as described in RFC 3174 (Secure Hash Algorithm). 
> (https://en.wikipedia.org/wiki/SHA-1)  The value is returned as a string of 
> 40 hexadecimal digits, or NULL if the argument was NULL. Note that `sha()` 
> and `sha1()` are aliases for the same function. 
> ```sql
> > select sha1( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | dc724af18fbdd4e59189f5fe768a5f8311527050  |
> +---+
> ```
> * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit checksum 
> for the string. (https://en.wikipedia.org/wiki/SHA-2)  The value is returned 
> as a string of hexadecimal digits, or NULL if the argument was NULL. Note 
> that `sha2()` and `sha256()` are aliases for the same function. 
> ```sql
> > select sha2( 'testing' ) from (VALUES(1));
> +---+
> |  EXPR$0   |
> +---+
> | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90  |
> +---+
> ```
> Additionally, there are also `sha384()` and `sha512()` functions 
> which return SHA-2 hashes with 384 and 512 bit checksums.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)