Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): add hashbytes example #10537

Merged
merged 3 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ibis/backends/sql/compilers/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def visit_Not(self, op, *, arg):
return self.if_(arg, 1, 0).eq(0)

def visit_HashBytes(self, op, *, arg, how):
if how in ("md5", "sha1"):
if how in ("md2", "md4", "md5", "sha1"):
return self.f.hashbytes(how, arg)
elif how == "sha256":
return self.f.hashbytes("sha2_256", arg)
Expand Down
4 changes: 4 additions & 0 deletions ibis/expr/operations/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ class Hash(Value):
class HashBytes(Value):
arg: Value[dt.String | dt.Binary]
how: LiteralType[
"md2",
"MD2",
"md4",
"MD4",
"md5",
"MD5",
"sha1",
Expand Down
10 changes: 8 additions & 2 deletions ibis/expr/types/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def hashbytes(
self,
how: Literal["md5", "sha1", "sha256", "sha512"] = "sha256",
) -> ir.BinaryValue:
"""Compute the binary hash value of the input.
r"""Compute the binary hash value of the input.

Parameters
----------
Expand All @@ -466,6 +466,12 @@ def hashbytes(
-------
BinaryValue
Binary expression

Examples
--------
>>> import ibis
>>> str_lit = ibis.literal("hello")
>>> result = str_lit.hashbytes("md5") # b']A@*\xbcK*v\xb9q\x9d\x91\x10\x17\xc5\x92'
"""
return ops.HashBytes(self, how).to_expr()

Expand All @@ -492,7 +498,7 @@ def hexdigest(
>>> t = ibis.memtable({"species": ["Adelie", "Chinstrap", "Gentoo"]})
>>> t.species.hexdigest()
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ HexDigest(species) ┃
┃ HexDigest(species)
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ string │
├──────────────────────────────────────────────────────────────────┤
Expand Down
Loading