Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rename @cel.attribute to cel.@attribute to be consistent with other cel-namespaced internal functions. #772

Merged
1 commit merged into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 11 additions & 8 deletions eval/public/portable_cel_expr_builder_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace {
using ::cel::MemoryManagerRef;
using ::cel::ast_internal::AstImpl;
using ::cel::extensions::CreateSelectOptimizationProgramOptimizer;
using ::cel::extensions::kCelAttribute;
using ::cel::extensions::kCelHasField;
using ::cel::extensions::ProtoMemoryManagerRef;
using ::cel::extensions::SelectOptimizationAstUpdater;
using ::cel::runtime_internal::CreateConstantFoldingOptimizer;
Expand Down Expand Up @@ -108,17 +110,18 @@ std::unique_ptr<CelExpressionBuilder> CreatePortableExprBuilder(
// Add overloads for select optimization signature.
// These are never bound, only used to prevent the builder from failing on
// the overloads check.
absl::Status status = builder->GetRegistry()->RegisterLazyFunction(
CelFunctionDescriptor(cel::extensions::kCelAttribute, false,
{cel::Kind::kAny, cel::Kind::kList}));
absl::Status status =
builder->GetRegistry()->RegisterLazyFunction(CelFunctionDescriptor(
kCelAttribute, false, {cel::Kind::kAny, cel::Kind::kList}));
if (!status.ok()) {
ABSL_LOG(ERROR) << "Failed to register @cel.attribute: " << status;
ABSL_LOG(ERROR) << "Failed to register " << kCelAttribute << ": "
<< status;
}
status = builder->GetRegistry()->RegisterLazyFunction(
CelFunctionDescriptor(cel::extensions::kFieldsHas, false,
{cel::Kind::kAny, cel::Kind::kList}));
status = builder->GetRegistry()->RegisterLazyFunction(CelFunctionDescriptor(
kCelHasField, false, {cel::Kind::kAny, cel::Kind::kList}));
if (!status.ok()) {
ABSL_LOG(ERROR) << "Failed to register @cel.hasField: " << status;
ABSL_LOG(ERROR) << "Failed to register " << kCelHasField << ": "
<< status;
}
// Add runtime implementation.
flat_expr_builder.AddProgramOptimizer(
Expand Down
1 change: 1 addition & 0 deletions extensions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ cc_library(
"//base/ast_internal:expr",
"//common:ast_rewrite",
"//common:casting",
"//common:expr",
"//common:kind",
"//common:native_type",
"//common:type",
Expand Down
15 changes: 7 additions & 8 deletions extensions/select_optimization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "base/function_descriptor.h"
#include "common/ast_rewrite.h"
#include "common/casting.h"
#include "common/expr.h"
#include "common/kind.h"
#include "common/native_type.h"
#include "common/type.h"
Expand Down Expand Up @@ -97,7 +98,7 @@ struct SelectPath {
};

// Generates the AST representation of the qualification path for the optimized
// select branch. I.e., the list-typed second argument of the @cel.attribute
// select branch. I.e., the list-typed second argument of the cel.@attribute
// call.
Expr MakeSelectPathExpr(
const std::vector<QualifierInstruction>& select_instructions) {
Expand Down Expand Up @@ -446,7 +447,7 @@ class RewriterImpl : public AstRewriterBase {
SelectPath path = GetSelectPath(&expr);

// generate the new cel.attribute call.
absl::string_view fn = path.test_only ? kFieldsHas : kCelAttribute;
absl::string_view fn = path.test_only ? kCelHasField : kCelAttribute;

Expr operand(std::move(*path.operand));
Expr call;
Expand Down Expand Up @@ -786,7 +787,7 @@ absl::Status SelectOptimizer::OnPostVisit(PlannerContext& context,
}

absl::string_view fn = node.call_expr().function();
if (fn != kFieldsHas && fn != kCelAttribute) {
if (fn != kCelHasField && fn != kCelAttribute) {
return absl::OkStatus();
}

Expand All @@ -808,7 +809,7 @@ absl::Status SelectOptimizer::OnPostVisit(PlannerContext& context,

bool presence_test = false;

if (fn == kFieldsHas) {
if (fn == kCelHasField) {
presence_test = true;
}

Expand Down Expand Up @@ -918,12 +919,10 @@ absl::Status EnableSelectOptimization(
// These are never bound, only used to prevent the builder from failing on
// the overloads check.
CEL_RETURN_IF_ERROR(builder.function_registry().RegisterLazyFunction(
FunctionDescriptor(cel::extensions::kCelAttribute, false,
{cel::Kind::kAny, cel::Kind::kList})));
FunctionDescriptor(kCelAttribute, false, {Kind::kAny, Kind::kList})));

CEL_RETURN_IF_ERROR(builder.function_registry().RegisterLazyFunction(
FunctionDescriptor(cel::extensions::kFieldsHas, false,
{cel::Kind::kAny, cel::Kind::kList})));
FunctionDescriptor(kCelHasField, false, {Kind::kAny, Kind::kList})));
// Add runtime implementation.
flat_expr_builder->AddProgramOptimizer(
CreateSelectOptimizationProgramOptimizer(options));
Expand Down
4 changes: 2 additions & 2 deletions extensions/select_optimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

namespace cel::extensions {

constexpr char kCelAttribute[] = "@cel.attribute";
constexpr char kFieldsHas[] = "@cel.hasField";
constexpr char kCelAttribute[] = "cel.@attribute";
constexpr char kCelHasField[] = "cel.@hasField";

// Configuration options for the select optimization.
struct SelectOptimizationOptions {
Expand Down