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

Snow-1830500: Bit and unary operations on columns. #2741

Merged
merged 3 commits into from
Dec 10, 2024
Merged
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
26 changes: 26 additions & 0 deletions tests/ast/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ def decode_timezone_expr(self, tz_expr: proto.PythonTimeZone) -> Any:
def binop(self, ast, fn):
sfc-gh-vbudati marked this conversation as resolved.
Show resolved Hide resolved
return fn(self.decode_expr(ast.lhs), self.decode_expr(ast.rhs))

def bitop(self, ast, fn):
lhs = self.decode_expr(ast.lhs)
rhs = self.decode_expr(ast.rhs)
return getattr(lhs, fn)(rhs)

def get_statement_params(self, d: Dict):
statement_params = {}
statement_params_list = d.get("statementParams", [])
Expand Down Expand Up @@ -732,6 +737,27 @@ def decode_expr(self, expr: proto.Expr) -> Any:
# "or" is reserved keyword in python - so have to use getattr here.
return self.binop(getattr(expr, "or"), lambda lhs, rhs: lhs | rhs)

# bit operations on columns
case "bit_and":
return self.bitop(expr.bit_and, "bitwiseAnd")

case "bit_or":
return self.bitop(expr.bit_or, "bitwiseOR")

case "bit_xor":
return self.bitop(expr.bit_xor, "bitwiseXOR")

# Unary operations on columns:
case "neg":
col = self.decode_expr(expr.neg.operand)
return -col

case "not":
# not is a reserved word in python.
col_expr = getattr(expr, "not").operand
col = self.decode_expr(col_expr)
return ~col

# DATAFRAME FUNCTIONS
case "sp_create_dataframe":
data = self.decode_dataframe_data_expr(expr.sp_create_dataframe.data)
Expand Down
Loading