数据库中多个列的 Presto MD5 哈希 Table
Presto MD5 Hash for multiple Columns in DB Table
经过两个小时的反复试验,我面临着让我发疯的挑战...
我需要使用 presto(实际上是使用使用 presto 引擎的 Amazon Athena)对关系 table 的至少两列进行哈希处理。
我现在的状态是这样的:
SELECT concat(lower(to_hex(md5(to_utf8(trim(column1))))),
lower(to_hex(md5(to_utf8(trim(column2)))))) AS HK
FROM table
limit 10
这个问题是,它首先对列进行散列,然后将它们连接起来最终看起来像这样,因为它连接了散列:
8f9bfe9d1345237cb3b2b205864da075ce8ae9da5b7cd6c3df2929543a9af92d
与其先连接字符串然后散列,不如这样结束:
8f9bfe9d1345237cb3b2b205864da075
对于解决此问题的任何想法,我将不胜感激。
编辑:
我得到了一个解决方案,但只是没有使用 trim() 函数,使用它查询不起作用并导致错误消息
INVALID_FUNCTION_ARGUMENT: There must be two or more concatenation arguments
当前查询:
SELECT lower(to_hex(md5(to_utf8(concat(user, email))))) AS UserMailHK FROM table limit 10
对此有什么想法吗?
感谢 Piotr,我找到了解决方案!
SELECT lower(to_hex(md5(to_utf8(concat(trim(user), trim(email)))))) AS UserMailHK FROM table limit 10
经过两个小时的反复试验,我面临着让我发疯的挑战...
我需要使用 presto(实际上是使用使用 presto 引擎的 Amazon Athena)对关系 table 的至少两列进行哈希处理。
我现在的状态是这样的:
SELECT concat(lower(to_hex(md5(to_utf8(trim(column1))))),
lower(to_hex(md5(to_utf8(trim(column2)))))) AS HK
FROM table
limit 10
这个问题是,它首先对列进行散列,然后将它们连接起来最终看起来像这样,因为它连接了散列:
8f9bfe9d1345237cb3b2b205864da075ce8ae9da5b7cd6c3df2929543a9af92d
与其先连接字符串然后散列,不如这样结束:
8f9bfe9d1345237cb3b2b205864da075
对于解决此问题的任何想法,我将不胜感激。
编辑:
我得到了一个解决方案,但只是没有使用 trim() 函数,使用它查询不起作用并导致错误消息
INVALID_FUNCTION_ARGUMENT: There must be two or more concatenation arguments
当前查询:
SELECT lower(to_hex(md5(to_utf8(concat(user, email))))) AS UserMailHK FROM table limit 10
对此有什么想法吗?
感谢 Piotr,我找到了解决方案!
SELECT lower(to_hex(md5(to_utf8(concat(trim(user), trim(email)))))) AS UserMailHK FROM table limit 10