chore: 添加虚拟环境到仓库
- 添加 backend_service/venv 虚拟环境 - 包含所有Python依赖包 - 注意:虚拟环境约393MB,包含12655个文件
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import abc
|
||||
|
||||
from pypika.terms import (
|
||||
Field,
|
||||
Function,
|
||||
Term,
|
||||
)
|
||||
from pypika.utils import format_alias_sql
|
||||
|
||||
|
||||
class Array(Term):
|
||||
def __init__(self, values: list, converter_cls=None, converter_options: dict = None, alias: str = None):
|
||||
super().__init__(alias)
|
||||
self._values = values
|
||||
self._converter_cls = converter_cls
|
||||
self._converter_options = converter_options or dict()
|
||||
|
||||
def get_sql(self):
|
||||
if self._converter_cls:
|
||||
converted = []
|
||||
for value in self._values:
|
||||
converter = self._converter_cls(value, **self._converter_options)
|
||||
converted.append(converter.get_sql())
|
||||
sql = "".join(["[", ",".join(converted), "]"])
|
||||
|
||||
else:
|
||||
sql = str(self._values)
|
||||
|
||||
return format_alias_sql(sql, self.alias)
|
||||
|
||||
|
||||
class HasAny(Function):
|
||||
def __init__(
|
||||
self,
|
||||
left_array: Array or Field,
|
||||
right_array: Array or Field,
|
||||
alias: str = None,
|
||||
schema: str = None,
|
||||
):
|
||||
self._left_array = left_array
|
||||
self._right_array = right_array
|
||||
self.alias = alias
|
||||
self.schema = schema
|
||||
self.args = ()
|
||||
self.name = "hasAny"
|
||||
|
||||
def get_sql(self, with_alias=False, with_namespace=False, quote_char=None, dialect=None, **kwargs):
|
||||
left = self._left_array.get_sql()
|
||||
right = self._right_array.get_sql()
|
||||
sql = "{name}({left},{right})".format(
|
||||
name=self.name,
|
||||
left='"%s"' % left if isinstance(self._left_array, Field) else left,
|
||||
right='"%s"' % right if isinstance(self._right_array, Field) else right,
|
||||
)
|
||||
return format_alias_sql(sql, self.alias, **kwargs)
|
||||
|
||||
|
||||
class _AbstractArrayFunction(Function, metaclass=abc.ABCMeta):
|
||||
def __init__(self, array: Array or Field, alias: str = None, schema: str = None):
|
||||
self.schema = schema
|
||||
self.alias = alias
|
||||
self.name = self.clickhouse_function()
|
||||
self._array = array
|
||||
|
||||
def get_sql(self, with_namespace=False, quote_char=None, dialect=None, **kwargs):
|
||||
array = self._array.get_sql()
|
||||
sql = "{name}({array})".format(
|
||||
name=self.name,
|
||||
array='"%s"' % array if isinstance(self._array, Field) else array,
|
||||
)
|
||||
return format_alias_sql(sql, self.alias, **kwargs)
|
||||
|
||||
@classmethod
|
||||
@abc.abstractmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
pass
|
||||
|
||||
|
||||
class NotEmpty(_AbstractArrayFunction):
|
||||
@classmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
return "notEmpty"
|
||||
|
||||
|
||||
class Empty(_AbstractArrayFunction):
|
||||
@classmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
return "empty"
|
||||
|
||||
|
||||
class Length(_AbstractArrayFunction):
|
||||
@classmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
return "length"
|
||||
@@ -0,0 +1,11 @@
|
||||
from pypika.terms import Function
|
||||
|
||||
|
||||
class If(Function):
|
||||
def __init__(self, *conditions, **kwargs):
|
||||
super().__init__("if", *conditions, **kwargs)
|
||||
|
||||
|
||||
class MultiIf(Function):
|
||||
def __init__(self, *conditions, **kwargs):
|
||||
super().__init__("multiIf", *conditions, **kwargs)
|
||||
@@ -0,0 +1,22 @@
|
||||
from pypika import CustomFunction
|
||||
|
||||
_add_subtract_args = ["name", "interval"]
|
||||
|
||||
ToYYYYMM = CustomFunction("toYYYYMM")
|
||||
AddYears = CustomFunction("addYears", _add_subtract_args)
|
||||
AddMonths = CustomFunction("addMonths", _add_subtract_args)
|
||||
AddWeeks = CustomFunction("addWeeks", _add_subtract_args)
|
||||
AddDays = CustomFunction("addDays", _add_subtract_args)
|
||||
AddHours = CustomFunction("addHours", _add_subtract_args)
|
||||
AddMinutes = CustomFunction("addMinutes", _add_subtract_args)
|
||||
AddSeconds = CustomFunction("addSeconds", _add_subtract_args)
|
||||
AddQuarters = CustomFunction("addQuarters", _add_subtract_args)
|
||||
SubtractYears = CustomFunction("subtractYears", _add_subtract_args)
|
||||
SubtractMonths = CustomFunction("subtractMonths", _add_subtract_args)
|
||||
SubtractWeeks = CustomFunction("subtractWeeks", _add_subtract_args)
|
||||
SubtractDays = CustomFunction("subtractDays", _add_subtract_args)
|
||||
SubtractHours = CustomFunction("subtractHours", _add_subtract_args)
|
||||
SubtractMinutes = CustomFunction("subtractMinutes", _add_subtract_args)
|
||||
SubtractSeconds = CustomFunction("subtractSeconds", _add_subtract_args)
|
||||
SubtractQuarters = CustomFunction("subtractQuarters", _add_subtract_args)
|
||||
FormatDateTime = CustomFunction("formatDateTime", ["name", "dt_format"])
|
||||
@@ -0,0 +1,6 @@
|
||||
from pypika.terms import Function
|
||||
|
||||
|
||||
class IfNull(Function):
|
||||
def __init__(self, term, alt, **kwargs):
|
||||
super().__init__("ifNull", term, alt, **kwargs)
|
||||
@@ -0,0 +1,88 @@
|
||||
import abc
|
||||
|
||||
from pypika.terms import Function
|
||||
from pypika.utils import format_alias_sql
|
||||
|
||||
|
||||
class _AbstractSearchString(Function, metaclass=abc.ABCMeta):
|
||||
def __init__(self, name, pattern: str, alias: str = None):
|
||||
super(_AbstractSearchString, self).__init__(self.clickhouse_function(), name, alias=alias)
|
||||
|
||||
self._pattern = pattern
|
||||
|
||||
@classmethod
|
||||
@abc.abstractmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
pass
|
||||
|
||||
def get_sql(self, with_alias=False, with_namespace=False, quote_char=None, dialect=None, **kwargs):
|
||||
args = []
|
||||
for p in self.args:
|
||||
if hasattr(p, "get_sql"):
|
||||
args.append('toString("{arg}")'.format(arg=p.get_sql(with_alias=False, **kwargs)))
|
||||
else:
|
||||
args.append(str(p))
|
||||
|
||||
sql = "{name}({args},'{pattern}')".format(
|
||||
name=self.name,
|
||||
args=",".join(args),
|
||||
pattern=self._pattern,
|
||||
)
|
||||
return format_alias_sql(sql, self.alias, **kwargs)
|
||||
|
||||
|
||||
class Match(_AbstractSearchString):
|
||||
@classmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
return "match"
|
||||
|
||||
|
||||
class Like(_AbstractSearchString):
|
||||
@classmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
return "like"
|
||||
|
||||
|
||||
class NotLike(_AbstractSearchString):
|
||||
@classmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
return "notLike"
|
||||
|
||||
|
||||
class _AbstractMultiSearchString(Function, metaclass=abc.ABCMeta):
|
||||
def __init__(self, name, patterns: list, alias: str = None):
|
||||
super(_AbstractMultiSearchString, self).__init__(self.clickhouse_function(), name, alias=alias)
|
||||
|
||||
self._patterns = patterns
|
||||
|
||||
@classmethod
|
||||
@abc.abstractmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
pass
|
||||
|
||||
def get_sql(self, with_alias=False, with_namespace=False, quote_char=None, dialect=None, **kwargs):
|
||||
args = []
|
||||
for p in self.args:
|
||||
if hasattr(p, "get_sql"):
|
||||
args.append('toString("{arg}")'.format(arg=p.get_sql(with_alias=False, **kwargs)))
|
||||
else:
|
||||
args.append(str(p))
|
||||
|
||||
sql = "{name}({args},[{patterns}])".format(
|
||||
name=self.name,
|
||||
args=",".join(args),
|
||||
patterns=",".join(["'%s'" % i for i in self._patterns]),
|
||||
)
|
||||
return format_alias_sql(sql, self.alias, **kwargs)
|
||||
|
||||
|
||||
class MultiSearchAny(_AbstractMultiSearchString):
|
||||
@classmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
return "multiSearchAny"
|
||||
|
||||
|
||||
class MultiMatchAny(_AbstractMultiSearchString):
|
||||
@classmethod
|
||||
def clickhouse_function(cls) -> str:
|
||||
return "multiMatchAny"
|
||||
@@ -0,0 +1,88 @@
|
||||
from pypika.terms import (
|
||||
Field,
|
||||
Function,
|
||||
)
|
||||
from pypika.utils import format_alias_sql
|
||||
|
||||
|
||||
class ToString(Function):
|
||||
def __init__(self, name, alias: str = None):
|
||||
super(ToString, self).__init__("toString", name, alias=alias)
|
||||
|
||||
|
||||
class ToFixedString(Function):
|
||||
def __init__(self, field, length: int, alias: str = None, schema: str = None):
|
||||
self._length = length
|
||||
self._field = field
|
||||
self.alias = alias
|
||||
self.name = "toFixedString"
|
||||
self.schema = schema
|
||||
self.args = ()
|
||||
|
||||
def get_sql(self, with_alias=False, with_namespace=False, quote_char=None, dialect=None, **kwargs):
|
||||
sql = "{name}({field},{length})".format(
|
||||
name=self.name,
|
||||
field=self._field if isinstance(self._field, Field) else "'%s'" % str(self._field),
|
||||
length=self._length,
|
||||
)
|
||||
return format_alias_sql(sql, self.alias, **kwargs)
|
||||
|
||||
|
||||
class ToInt8(Function):
|
||||
def __init__(self, name, alias: str = None):
|
||||
super(ToInt8, self).__init__("toInt8", name, alias=alias)
|
||||
|
||||
|
||||
class ToInt16(Function):
|
||||
def __init__(self, name, alias: str = None):
|
||||
super(ToInt16, self).__init__("toInt16", name, alias=alias)
|
||||
|
||||
|
||||
class ToInt32(Function):
|
||||
def __init__(self, name, alias: str = None):
|
||||
super(ToInt32, self).__init__("toInt32", name, alias=alias)
|
||||
|
||||
|
||||
class ToInt64(Function):
|
||||
def __init__(self, name, alias: str = None):
|
||||
super(ToInt64, self).__init__("toInt64", name, alias=alias)
|
||||
|
||||
|
||||
class ToUInt8(Function):
|
||||
def __init__(self, name, alias: str = None):
|
||||
super(ToUInt8, self).__init__("toUInt8", 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):
|
||||
super(ToDateTime, self).__init__("toDateTime", name, alias=alias)
|
||||
Reference in New Issue
Block a user