-
Notifications
You must be signed in to change notification settings - Fork 26
Conversation
@@ -546,20 +546,20 @@ def in_(self, container: Union["Expr", List[Any]]) -> "InExpr": | |||
from psycopg2.extensions import adapt # type: ignore | |||
|
|||
|
|||
def _serialize(value: Any) -> str: | |||
def _serialize_to_expr(obj: Any, db: Optional[Database] = None) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not name it to serialize_to_expr? since others will import it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to prevent it from being imported by the user.
greenplumpython/type.py
Outdated
# def _bind( | ||
# self, | ||
# dataframe: Optional["DataFrame"] = None, | ||
# db: Optional[Database] = None, | ||
# column_name: str = None, | ||
# ) -> "Expr": | ||
# # noqa D102 | ||
# self._db = db | ||
# if isinstance(self._obj, Expr): | ||
# self._obj = self._obj._bind( | ||
# dataframe=dataframe, | ||
# db=db, | ||
# ) | ||
# return self | ||
# | ||
# def apply( | ||
# self, expand: bool = False, column_name: Optional[str] = None, row_id: Optional[str] = None | ||
# ) -> "DataFrame": | ||
# # noqa D102 | ||
# from greenplumpython.dataframe import DataFrame | ||
|
||
# if expand and column_name is None: | ||
# column_name = "func_" + uuid4().hex | ||
# return DataFrame( | ||
# f""" | ||
# SELECT {(row_id + ',') if row_id is not None else ''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be dropped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Perhaps we should add an extra test cases to cover operators
, select conditions in brackets and with where()
method to add a bit more complexity to the test.
Previously,
db
is an attribute of classExpr
and its valuecannot be decided when init a new object. As a result, when the
Expr
is serialized, we need to explicitly bind it to a db tocreate functions or types. However, in some cases we forgot to
do that, which lead to errros.
To avoid forgotting this, this patch moves db to a parameter of
serialize()
and pass db to it each time we call it.This patch fixes the following bugs in
serialize()
:type.
*
is not serialized correctly in column filedswhen expanding a composite type result.
count(*)
returns wrong result when dataframe containsNone
.