@@ -95,6 +95,69 @@ def project(
9595 expressions : Iterable [ExtendedExpressionOrUnbound ],
9696 extension : Optional [AdvancedExtension ] = None ,
9797) -> UnboundPlan :
98+ """
99+ Builds an UnboundPlan with ProjectRel as the root node. Expressions are appended to the parent relation fields to produce an output.
100+ Semantically similar to a withColumn transformation.
101+
102+ :param plan: Parent plan
103+ :type plan: PlanOrUnbound
104+ :param expressions: Expressions to project
105+ :type expressions: Iterable[ExtendedExpressionOrUnbound]
106+ :param extension: Optional user-defined extension
107+ :type extension: Optional[AdvancedExtension]
108+ :return: UnboundPlan with ProjectRel as the root node
109+ :rtype: UnboundPlan
110+ """
111+
112+ def resolve (registry : ExtensionRegistry ) -> stp .Plan :
113+ _plan = plan if isinstance (plan , stp .Plan ) else plan (registry )
114+ ns = infer_plan_schema (_plan )
115+ bound_expressions : Iterable [stee .ExtendedExpression ] = [
116+ resolve_expression (e , ns , registry ) for e in expressions
117+ ]
118+
119+ names = list (_plan .relations [- 1 ].root .names ) + [
120+ e .output_names [0 ] for ee in bound_expressions for e in ee .referred_expr
121+ ]
122+
123+ rel = stalg .Rel (
124+ project = stalg .ProjectRel (
125+ input = _plan .relations [- 1 ].root .input ,
126+ expressions = [
127+ e .expression for ee in bound_expressions for e in ee .referred_expr
128+ ],
129+ advanced_extension = extension ,
130+ )
131+ )
132+
133+ return stp .Plan (
134+ version = default_version ,
135+ relations = [stp .PlanRel (root = stalg .RelRoot (input = rel , names = names ))],
136+ ** _merge_extensions (_plan , * bound_expressions ),
137+ )
138+
139+ return resolve
140+
141+
142+ def select (
143+ plan : PlanOrUnbound ,
144+ expressions : Iterable [ExtendedExpressionOrUnbound ],
145+ extension : Optional [AdvancedExtension ] = None ,
146+ ) -> UnboundPlan :
147+ """
148+ Builds an UnboundPlan with ProjectRel as the root node. Expressions make up the fields of an output relation.
149+ Semantically similar to a select transformation.
150+
151+ :param plan: Parent plan
152+ :type plan: PlanOrUnbound
153+ :param expressions: Expressions to project
154+ :type expressions: Iterable[ExtendedExpressionOrUnbound]
155+ :param extension: Optional user-defined extension
156+ :type extension: Optional[AdvancedExtension]
157+ :return: UnboundPlan with ProjectRel as the root node
158+ :rtype: UnboundPlan
159+ """
160+
98161 def resolve (registry : ExtensionRegistry ) -> stp .Plan :
99162 _plan = plan if isinstance (plan , stp .Plan ) else plan (registry )
100163 ns = infer_plan_schema (_plan )
0 commit comments