Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class ToUInt64(Function):
def __init__(self, name, alias: str = None):
super(ToUInt64, self).__init__("toUInt64", name, alias=alias)
class ToFloat32(Function):
def __init__(self, name, alias: str = None):
super(ToFloat32, self).__init__("toFloat32", name, alias=alias)
class ToFloat64(Function):
def __init__(self, name, alias: str = None):
super(ToFloat64, self).__init__("toFloat64", name, alias=alias)
class ToDate(Function):
def __init__(self, name, alias: str = None):
super(ToDate, self).__init__("toDate", name, alias=alias)
class ToDateTime(Function):
def __init__(self, name, alias: str = None):
super(ToDateTime, self).__init__("toDateTime", name, alias=alias)
class ToUInt16(Function):
def __init__(self, name, alias: str = None):
super(ToUInt16, self).__init__("toUInt16", name, alias=alias)
class ToUInt32(Function):
def __init__(self, name, alias: str = None):
super(ToUInt32, self).__init__("toUInt32", name, alias=alias)
class ToUInt64(Function):
def __init__(self, name, alias: str = None):
super(ToUInt64, self).__init__("toUInt64", name, alias=alias)
class ToFloat32(Function):
def __init__(self, name, alias: str = None):
super(ToFloat32, self).__init__("toFloat32", name, alias=alias)
class ToFloat64(Function):
def __init__(self, name, alias: str = None):
super(ToFloat64, self).__init__("toFloat64", name, alias=alias)
class ToDate(Function):
def __init__(self, name, alias: str = None):
super(ToDate, self).__init__("toDate", name, alias=alias)
class ToDateTime(Function):
def __init__(self, name, alias: str = None):
)
class TimeDiff(Function):
def __init__(self, start_time, end_time, alias=None):
super(TimeDiff, self).__init__("TIMEDIFF", start_time, end_time, alias=alias)
class DateAdd(Function):
def __init__(self, date_part, interval, term, alias=None):
super(DateAdd, self).__init__(
"DATE_ADD", date_part, interval, term, alias=alias
)
class ToDate(Function):
def __init__(self, value, format_mask, alias=None):
super(ToDate, self).__init__("TO_DATE", value, format_mask, alias=alias)
class Timestamp(Function):
def __init__(self, term, alias=None):
super(Timestamp, self).__init__("TIMESTAMP", term, alias=alias)
class TimestampAdd(Function):
def __init__(self, date_part, interval, term, alias=None):
super(TimestampAdd, self).__init__(
"TIMESTAMPADD", date_part, interval, term, alias=alias
)
class Upper(Function):
def __init__(self, term, alias=None):
super(Upper, self).__init__("UPPER", term, alias=alias)
class Lower(Function):
def __init__(self, term, alias=None):
super(Lower, self).__init__("LOWER", term, alias=alias)
class Substring(Function):
def __init__(self, term, start, stop, alias=None):
super(Substring, self).__init__("SUBSTRING", term, start, stop, alias=alias)
class Reverse(Function):
def __init__(self, term, alias=None):
super(Reverse, self).__init__("REVERSE", term, alias=alias)
class Trim(Function):
def __init__(self, term, alias=None):
super(Trim, self).__init__("TRIM", term, alias=alias)
class SplitPart(Function):
def __init__(self, term, delimiter, index, alias=None):
super(SplitPart, self).__init__(
"SPLIT_PART", term, delimiter, index, alias=alias
)
def get_special_params_sql(self, **kwargs):
return "FROM {field}".format(field=self.field,)
# Null Functions
class IsNull(Function):
def __init__(self, term, alias=None):
super(IsNull, self).__init__("ISNULL", term, alias=alias)
class Coalesce(Function):
def __init__(self, term, *default_values, **kwargs):
super(Coalesce, self).__init__("COALESCE", term, *default_values, **kwargs)
class IfNull(Function):
def __init__(self, condition, term, **kwargs):
super(IfNull, self).__init__("IFNULL", condition, term, **kwargs)
class NVL(Function):
def __init__(self, condition, term, alias=None):
super(NVL, self).__init__("NVL", condition, term, alias=alias)
def __init__(self, *terms, **kwargs):
super(Concat, self).__init__("CONCAT", *terms, **kwargs)
class Insert(Function):
def __init__(self, term, start, stop, subterm, alias=None):
term, start, stop, subterm = [term for term in [term, start, stop, subterm]]
super(Insert, self).__init__("INSERT", term, start, stop, subterm, alias=alias)
class Length(Function):
def __init__(self, term, alias=None):
super(Length, self).__init__("LENGTH", term, alias=alias)
class Upper(Function):
def __init__(self, term, alias=None):
super(Upper, self).__init__("UPPER", term, alias=alias)
class Lower(Function):
def __init__(self, term, alias=None):
super(Lower, self).__init__("LOWER", term, alias=alias)
class Substring(Function):
def __init__(self, term, start, stop, alias=None):
super(Substring, self).__init__("SUBSTRING", term, start, stop, alias=alias)
class Reverse(Function):
def __init__(self, term, alias=None):
class Lower(Function):
def __init__(self, term, alias=None):
super(Lower, self).__init__("LOWER", term, alias=alias)
class Substring(Function):
def __init__(self, term, start, stop, alias=None):
super(Substring, self).__init__("SUBSTRING", term, start, stop, alias=alias)
class Reverse(Function):
def __init__(self, term, alias=None):
super(Reverse, self).__init__("REVERSE", term, alias=alias)
class Trim(Function):
def __init__(self, term, alias=None):
super(Trim, self).__init__("TRIM", term, alias=alias)
class SplitPart(Function):
def __init__(self, term, delimiter, index, alias=None):
super(SplitPart, self).__init__(
"SPLIT_PART", term, delimiter, index, alias=alias
)
class RegexpMatches(Function):
def __init__(self, term, pattern, modifiers=None, alias=None):
super(RegexpMatches, self).__init__(
"REGEXP_MATCHES", term, pattern, modifiers, alias=alias
)
from pypika import (
functions as fn,
terms,
)
from pypika.dialects import SnowflakeQuery
from .base import Database
try:
from snowflake import connector as snowflake
except:
pass
IGNORED_SCHEMAS = {'INFORMATION_SCHEMA'}
class Trunc(terms.Function):
"""
Wrapper for TRUNC function for truncating dates.
"""
def __init__(self, field, date_format, alias=None):
super(Trunc, self).__init__('TRUNC', field, date_format, alias=alias)
# Setting the fields here means we can access the TRUNC args by name.
self.field = field
self.date_format = date_format
self.alias = alias
class SnowflakeDatabase(Database):
"""
Snowflake client.
"""
class ToChar(Function):
def __init__(self, term, as_type, alias=None):
super(ToChar, self).__init__("TO_CHAR", term, as_type, alias=alias)
class Signed(Cast):
def __init__(self, term, alias=None):
super(Signed, self).__init__(term, SqlTypes.SIGNED, alias=alias)
class Unsigned(Cast):
def __init__(self, term, alias=None):
super(Unsigned, self).__init__(term, SqlTypes.UNSIGNED, alias=alias)
class Date(Function):
def __init__(self, term, alias=None):
super(Date, self).__init__("DATE", term, alias=alias)
class DateDiff(Function):
def __init__(self, interval, start_date, end_date, alias=None):
super(DateDiff, self).__init__(
"DATEDIFF", interval, start_date, end_date, alias=alias
)
class TimeDiff(Function):
def __init__(self, start_time, end_time, alias=None):
super(TimeDiff, self).__init__("TIMEDIFF", start_time, end_time, alias=alias)
function_sql = "{schema}.{function}".format(
schema=self.schema.get_sql(
quote_char=quote_char, dialect=dialect, **kwargs
),
function=function_sql,
)
if with_alias:
return format_alias_sql(
function_sql, self.alias, quote_char=quote_char, **kwargs
)
return function_sql
class AggregateFunction(Function):
is_aggregate = True
class AnalyticFunction(Function):
is_analytic = True
def __init__(self, name, *args, **kwargs):
super(AnalyticFunction, self).__init__(name, *args, **kwargs)
self._partition = []
self._orderbys = []
self._include_over = False
@builder
def over(self, *terms):
self._include_over = True
self._partition += terms