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

with_alias handling missing in various criterion #735

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
37 changes: 24 additions & 13 deletions pypika/terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,11 @@ def nodes_(self) -> Iterator[NodeT]:
for value in self.values:
yield from value.nodes_()

def get_sql(self, **kwargs: Any) -> str:
def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str:
sql = "({})".format(",".join(term.get_sql(**kwargs) for term in self.values))
return format_alias_sql(sql, self.alias, **kwargs)
if with_alias:
return format_alias_sql(sql, self.alias, **kwargs)
return sql

@property
def is_aggregate(self) -> bool:
Expand Down Expand Up @@ -812,13 +814,15 @@ def replace_table(self, current_table: Optional["Table"], new_table: Optional["T
"""
self.term = self.term.replace_table(current_table, new_table)

def get_sql(self, subquery: Any = None, **kwargs: Any) -> str:
def get_sql(self, subquery: Any = None, with_alias: bool = False, **kwargs: Any) -> str:
sql = "{term} {not_}IN {container}".format(
term=self.term.get_sql(**kwargs),
container=self.container.get_sql(subquery=True, **kwargs),
not_="NOT " if self._is_negated else "",
)
return format_alias_sql(sql, self.alias, **kwargs)
if with_alias:
return format_alias_sql(sql, self.alias, **kwargs)
return sql

@builder
def negate(self) -> "ContainsCriterion":
Expand Down Expand Up @@ -920,12 +924,14 @@ def replace_table(self, current_table: Optional["Table"], new_table: Optional["T
"""
self.term = self.term.replace_table(current_table, new_table)

def get_sql(self, **kwargs: Any) -> str:
def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str:
sql = "({term} & {value})".format(
term=self.term.get_sql(**kwargs),
value=self.value,
)
return format_alias_sql(sql, self.alias, **kwargs)
if with_alias:
return format_alias_sql(sql, self.alias, **kwargs)
return sql


class NullCriterion(Criterion):
Expand Down Expand Up @@ -955,7 +961,9 @@ def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str:
sql = "{term} IS NULL".format(
term=self.term.get_sql(**kwargs),
)
return format_alias_sql(sql, self.alias, **kwargs)
if with_alias:
return format_alias_sql(sql, self.alias, **kwargs)
return sql


class NotNullCriterion(NullCriterion):
Expand Down Expand Up @@ -1180,10 +1188,12 @@ def nodes_(self) -> Iterator[NodeT]:
yield self
yield from self.term.nodes_()

def get_sql(self, **kwargs: Any) -> str:
def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str:
kwargs["subcriterion"] = True
sql = "NOT {term}".format(term=self.term.get_sql(**kwargs))
return format_alias_sql(sql, self.alias, **kwargs)
if with_alias:
return format_alias_sql(sql, self.alias, **kwargs)
return sql

@ignore_copy
def __getattr__(self, name: str) -> Any:
Expand Down Expand Up @@ -1228,9 +1238,11 @@ def nodes_(self) -> Iterator[NodeT]:
yield self
yield from self.term.nodes_()

def get_sql(self, **kwargs: Any) -> str:
def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str:
sql = "{term} ALL".format(term=self.term.get_sql(**kwargs))
return format_alias_sql(sql, self.alias, **kwargs)
if with_alias:
return format_alias_sql(sql, self.alias, **kwargs)
return sql


class CustomFunction:
Expand Down Expand Up @@ -1317,8 +1329,7 @@ def get_function_sql(self, **kwargs: Any) -> str:
special=(" " + special_params_sql) if special_params_sql else "",
)

def get_sql(self, **kwargs: Any) -> str:
with_alias = kwargs.pop("with_alias", False)
def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str:
with_namespace = kwargs.pop("with_namespace", False)
quote_char = kwargs.pop("quote_char", None)
dialect = kwargs.pop("dialect", None)
Expand Down