Skip to content

Commit 25e0412

Browse files
jckingcopybara-github
authored andcommitted
Remove <map_or_list>.filter(<iter>, <iter2>, <expr>)
PiperOrigin-RevId: 743291773
1 parent 8a1b7bd commit 25e0412

File tree

2 files changed

+0
-76
lines changed

2 files changed

+0
-76
lines changed

extensions/comprehensions_v2_macros.cc

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -182,55 +182,6 @@ Macro MakeExistsOneMacro2() {
182182
return std::move(*status_or_macro);
183183
}
184184

185-
absl::optional<Expr> ExpandFilterMacro2(MacroExprFactory& factory, Expr& target,
186-
absl::Span<Expr> args) {
187-
if (args.size() != 3) {
188-
return factory.ReportError("filter() requires 3 arguments");
189-
}
190-
if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) {
191-
return factory.ReportErrorAt(
192-
args[0], "filter() first variable name must be a simple identifier");
193-
}
194-
if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) {
195-
return factory.ReportErrorAt(
196-
args[1], "filter() second variable name must be a simple identifier");
197-
}
198-
if (args[0].ident_expr().name() == args[1].ident_expr().name()) {
199-
return factory.ReportErrorAt(
200-
args[0],
201-
"filter() second variable must be different from the first variable");
202-
}
203-
if (args[0].ident_expr().name() == kAccumulatorVariableName) {
204-
return factory.ReportErrorAt(
205-
args[0], absl::StrCat("filter() first variable name cannot be ",
206-
kAccumulatorVariableName));
207-
}
208-
if (args[1].ident_expr().name() == kAccumulatorVariableName) {
209-
return factory.ReportErrorAt(
210-
args[1], absl::StrCat("filter() second variable name cannot be ",
211-
kAccumulatorVariableName));
212-
}
213-
auto name = args[0].ident_expr().name();
214-
auto name2 = args[1].ident_expr().name();
215-
auto init = factory.NewList();
216-
auto condition = factory.NewBoolConst(true);
217-
auto step = factory.NewCall(
218-
CelOperator::ADD, factory.NewAccuIdent(),
219-
factory.NewList(factory.NewListElement(std::move(args[1]))));
220-
step = factory.NewCall(CelOperator::CONDITIONAL, std::move(args[2]),
221-
std::move(step), factory.NewAccuIdent());
222-
return factory.NewComprehension(
223-
name, name2, std::move(target), factory.AccuVarName(), std::move(init),
224-
std::move(condition), std::move(step), factory.NewAccuIdent());
225-
}
226-
227-
Macro MakeFilterMacro2() {
228-
auto status_or_macro =
229-
Macro::Receiver(CelOperator::FILTER, 3, ExpandFilterMacro2);
230-
ABSL_CHECK_OK(status_or_macro); // Crash OK
231-
return std::move(*status_or_macro);
232-
}
233-
234185
absl::optional<Expr> ExpandTransformList3Macro(MacroExprFactory& factory,
235186
Expr& target,
236187
absl::Span<Expr> args) {
@@ -444,11 +395,6 @@ const Macro& ExistsOneMacro2() {
444395
return *macro;
445396
}
446397

447-
const Macro& FilterMacro2() {
448-
static const absl::NoDestructor<Macro> macro(MakeFilterMacro2());
449-
return *macro;
450-
}
451-
452398
const Macro& TransformList3Macro() {
453399
static const absl::NoDestructor<Macro> macro(MakeTransformList3Macro());
454400
return *macro;
@@ -477,7 +423,6 @@ absl::Status RegisterComprehensionsV2Macros(MacroRegistry& registry,
477423
CEL_RETURN_IF_ERROR(registry.RegisterMacro(AllMacro2()));
478424
CEL_RETURN_IF_ERROR(registry.RegisterMacro(ExistsMacro2()));
479425
CEL_RETURN_IF_ERROR(registry.RegisterMacro(ExistsOneMacro2()));
480-
CEL_RETURN_IF_ERROR(registry.RegisterMacro(FilterMacro2()));
481426
CEL_RETURN_IF_ERROR(registry.RegisterMacro(TransformList3Macro()));
482427
CEL_RETURN_IF_ERROR(registry.RegisterMacro(TransformList4Macro()));
483428
CEL_RETURN_IF_ERROR(registry.RegisterMacro(TransformMap3Macro()));

extensions/comprehensions_v2_macros_test.cc

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,6 @@ INSTANTIATE_TEST_SUITE_P(
119119
.expression = "[].existsOne(e, foo.bar, true)",
120120
.error = "second variable name must be a simple identifier",
121121
},
122-
{
123-
.expression = "[].filter(__result__, v, v == 0)",
124-
.error = "variable name cannot be __result__",
125-
},
126-
{
127-
.expression = "[].filter(i, __result__, i == 0)",
128-
.error = "variable name cannot be __result__",
129-
},
130-
{
131-
.expression = "[].filter(e, e, e == e)",
132-
.error =
133-
"second variable must be different from the first variable",
134-
},
135-
{
136-
.expression = "[].filter(foo.bar, e, true)",
137-
.error = "first variable name must be a simple identifier",
138-
},
139-
{
140-
.expression = "[].filter(e, foo.bar, true)",
141-
.error = "second variable name must be a simple identifier",
142-
},
143122
{
144123
.expression = "[].transformList(__result__, v, v)",
145124
.error = "variable name cannot be __result__",

0 commit comments

Comments
 (0)