String Expressions¶
All string operations are valid for both scalars and columns.
strings
¶
Classes¶
StringValue (Value)
¶
Methods¶
ascii_str(self)
¶
Return the numeric ASCII code of the first character of a string.
Returns¶
IntegerValue ASCII code of the first character of the input
concat(self, other, *args)
¶
contains(self, substr)
¶
convert_base(self, from_base, to_base)
¶
endswith(self, end)
¶
find(self, substr, start=None, end=None)
¶
find_in_set(self, str_list)
¶
Find the first occurence of str_list
within a list of strings.
No string in str_list
can have a comma.
Parameters¶
str_list Sequence of strings
Examples¶
import ibis table = ibis.table([('strings', 'string')]) result = table.strings.find_in_set(['a', 'b'])
Returns¶
IntegerValue
Position of str_list
in self
. Returns -1 if self
isn't found
or if self
contains ','
.
hashbytes(self, how='sha256')
¶
ilike(self, patterns)
¶
Match patterns
against self
, case-insensitive.
This function is modeled after SQL's ILIKE
directive. Use %
as a
multiple-character wildcard or _
as a single-character wildcard.
Use re_search
or rlike
for regular expression-based matching.
Parameters¶
patterns
If pattern
is a list, then if any pattern matches the input then
the corresponding row in the output is True
.
Returns¶
BooleanValue Column indicating matches
join(self, strings)
¶
left(self, nchars)
¶
like(self, patterns)
¶
Match patterns
against self
, case-sensitive.
This function is modeled after the SQL LIKE
directive. Use %
as a
multiple-character wildcard or _
as a single-character wildcard.
Use re_search
or rlike
for regular expression-based matching.
Parameters¶
patterns
If pattern
is a list, then if any pattern matches the input then
the corresponding row in the output is True
.
Returns¶
BooleanValue Column indicating matches
lpad(self, length, pad=' ')
¶
Pad arg
by truncating on the right or padding on the left.
Parameters¶
length Length of output string pad Pad character
Examples¶
import ibis table = ibis.table([('strings', 'string')]) expr = table.strings.lpad(5, '-') expr = ibis.literal('a').lpad(5, '-') # 'a' becomes '----a' expr = ibis.literal('abcdefg').lpad(5, '-') # 'abcdefg' becomes 'abcde' # noqa: E501
Returns¶
StringValue Padded string
lstrip(self)
¶
parse_url(self, extract, key=None)
¶
Parse a URL and extract its components.
key
can be used to extract query values when extract == 'QUERY'
Parameters¶
extract Component of URL to extract key Query component to extract
Examples¶
url = "https://www.youtube.com/watch?v=kEuEcWfewf8&t=10" parse_url(url, 'QUERY', 'v') # doctest: +SKIP 'kEuEcWfewf8'
Returns¶
StringValue Extracted string value
re_extract(self, pattern, index)
¶
re_replace(self, pattern, replacement)
¶
Replace match found by regex pattern
with replacement
.
Parameters¶
pattern Regular expression string replacement Replacement string or regular expression
Examples¶
import ibis table = ibis.table([('strings', 'string')]) result = table.strings.replace('(b+)', r'<>') # 'aaabbbaa' becomes 'aaa
aaa' # noqa: E501
Returns¶
StringValue Modified string
re_search(self, pattern)
¶
repeat(self, n)
¶
replace(self, pattern, replacement)
¶
Replace each exact match of pattern
with replacement
.
Parameters¶
pattern String pattern replacement String replacement
Examples¶
import ibis table = ibis.table([('strings', 'string')]) result = table.strings.replace('aaa', 'foo') # 'aaabbbaaa' becomes 'foobbbfoo' # noqa: E501
Returns¶
StringVulae Replaced string
right(self, nchars)
¶
rlike(self, pattern)
¶
rpad(self, length, pad=' ')
¶
Pad self
by truncating or padding on the right.
Parameters¶
self String to pad length Length of output string pad Pad character
Examples¶
import ibis table = ibis.table([('string_col', 'string')]) expr = table.string_col.rpad(5, '-') expr = ibis.literal('a').rpad(5, '-') # 'a' becomes 'a----' expr = ibis.literal('abcdefg').rpad(5, '-') # 'abcdefg' becomes 'abcde' # noqa: E501
Returns¶
StringValue Padded string
rstrip(self)
¶
split(self, delimiter)
¶
startswith(self, start)
¶
strip(self)
¶
substr(self, start, length=None)
¶
to_timestamp(self, format_str, timezone=None)
¶
Parse a string and return a timestamp.
Parameters¶
format_str
Format string in strptime
format
timezone
A string indicating the timezone. For example 'America/New_York'
Examples¶
import ibis date_as_str = ibis.literal('20170206') result = date_as_str.to_timestamp('%Y%m%d')
Returns¶
TimestampValue Parsed timestamp value
translate(self, from_str, to_str)
¶
Replace from_str
characters in self
characters in to_str
.
To avoid unexpected behavior, from_str
should be shorter than
to_str
.
Parameters¶
from_str
Characters in arg
to replace
to_str
Characters to use for replacement
Examples¶
import ibis table = ibis.table([('string_col', 'string')]) expr = table.string_col.translate('a', 'b') expr = table.string_col.translate('a', 'bc')
Returns¶
StringValue Translated string