Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/dsl/binary.rs
6939 views
1
use super::*;
2
/// Specialized expressions for [`Series`] of [`DataType::String`].
3
pub struct BinaryNameSpace(pub(crate) Expr);
4
5
impl BinaryNameSpace {
6
/// Check if a binary value contains a literal binary.
7
pub fn contains_literal(self, pat: Expr) -> Expr {
8
self.0
9
.map_binary(FunctionExpr::BinaryExpr(BinaryFunction::Contains), pat)
10
}
11
12
/// Check if a binary value ends with the given sequence.
13
pub fn ends_with(self, sub: Expr) -> Expr {
14
self.0
15
.map_binary(FunctionExpr::BinaryExpr(BinaryFunction::EndsWith), sub)
16
}
17
18
/// Check if a binary value starts with the given sequence.
19
pub fn starts_with(self, sub: Expr) -> Expr {
20
self.0
21
.map_binary(FunctionExpr::BinaryExpr(BinaryFunction::StartsWith), sub)
22
}
23
24
/// Return the size (number of bytes) in each element.
25
pub fn size_bytes(self) -> Expr {
26
self.0
27
.map_unary(FunctionExpr::BinaryExpr(BinaryFunction::Size))
28
}
29
30
#[cfg(feature = "binary_encoding")]
31
pub fn hex_decode(self, strict: bool) -> Expr {
32
self.0
33
.map_unary(FunctionExpr::BinaryExpr(BinaryFunction::HexDecode(strict)))
34
}
35
36
#[cfg(feature = "binary_encoding")]
37
pub fn hex_encode(self) -> Expr {
38
self.0
39
.map_unary(FunctionExpr::BinaryExpr(BinaryFunction::HexEncode))
40
}
41
42
#[cfg(feature = "binary_encoding")]
43
pub fn base64_decode(self, strict: bool) -> Expr {
44
self.0
45
.map_unary(FunctionExpr::BinaryExpr(BinaryFunction::Base64Decode(
46
strict,
47
)))
48
}
49
50
#[cfg(feature = "binary_encoding")]
51
pub fn base64_encode(self) -> Expr {
52
self.0
53
.map_unary(FunctionExpr::BinaryExpr(BinaryFunction::Base64Encode))
54
}
55
56
#[cfg(feature = "binary_encoding")]
57
pub fn reinterpret(self, to_type: impl Into<DataTypeExpr>, is_little_endian: bool) -> Expr {
58
self.0
59
.map_unary(FunctionExpr::BinaryExpr(BinaryFunction::Reinterpret(
60
to_type.into(),
61
is_little_endian,
62
)))
63
}
64
}
65
66