-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathunary_expression.py
More file actions
120 lines (89 loc) · 2.94 KB
/
unary_expression.py
File metadata and controls
120 lines (89 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#
# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
#
from typing import AbstractSet, Dict, List, Optional
from snowflake.snowpark._internal.analyzer.expression import (
Expression,
NamedExpression,
derive_dependent_columns,
derive_dependent_columns_with_duplication,
)
from snowflake.snowpark._internal.analyzer.query_plan_analysis_utils import (
PlanNodeCategory,
)
from snowflake.snowpark.types import DataType
class UnaryExpression(Expression):
sql_operator: str
operator_first: bool
def __init__(self, child: Expression) -> None:
super().__init__()
self.child = child
self.nullable = child.nullable
self.children = [child]
self.datatype = self.child.datatype
def __str__(self):
return (
f"{self.sql_operator} {self.child}"
if self.operator_first
else f"{self.child} {self.sql_operator}"
)
def dependent_column_names(self) -> Optional[AbstractSet[str]]:
return derive_dependent_columns(self.child)
def dependent_column_names_with_duplication(self) -> List[str]:
return derive_dependent_columns_with_duplication(self.child)
@property
def plan_node_category(self) -> PlanNodeCategory:
return PlanNodeCategory.LOW_IMPACT
class Cast(UnaryExpression):
sql_operator = "CAST"
operator_first = True
def __init__(
self,
child: Expression,
to: DataType,
try_: bool = False,
is_rename: bool = False,
is_add: bool = False,
) -> None:
super().__init__(child)
self.to = to
self.try_ = try_
self.is_rename = is_rename
self.is_add = is_add
class UnaryMinus(UnaryExpression):
sql_operator = "-"
operator_first = True
class IsNull(UnaryExpression):
sql_operator = "IS NULL"
operator_first = False
class IsNotNull(UnaryExpression):
sql_operator = "IS NOT NULL"
operator_first = False
class IsNaN(UnaryExpression):
sql_operator = "= 'NAN'"
operator_first = False
class Not(UnaryExpression):
sql_operator = "NOT"
operator_first = True
class Alias(UnaryExpression, NamedExpression):
sql_operator = "AS"
operator_first = False
def __init__(self, child: Expression, name: str) -> None:
super().__init__(child)
self.name = name
def __str__(self):
return f"{self.child} {self.sql_operator} {self.name}"
@property
def individual_node_complexity(self) -> Dict[PlanNodeCategory, int]:
# do not add additional complexity for alias
return {}
class UnresolvedAlias(UnaryExpression, NamedExpression):
sql_operator = "AS"
operator_first = False
def __init__(self, child: Expression) -> None:
super().__init__(child)
self.name = child.sql
@property
def individual_node_complexity(self) -> Dict[PlanNodeCategory, int]:
# this is a wrapper around child
return {}