GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement LiteAttributeStep for evaluating optimized select qualifier… · cel-expr/cel-java@da631de

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • common/src
    • main/java/dev/cel/common/values
      • BUILD.bazel
      • OptimizedSelectable.java
      • ProtoLiteCelValueConverter.java
      • ProtoMessageLiteValue.java
      • RawProtoMessageLiteValue.java
      • SelectField.java
    • test/java/dev/cel/common/values
      • BUILD.bazel
      • ProtoMessageLiteValueTest.java
      • RawProtoMessageLiteValueTest.java
      • SelectFieldTest.java
  • protobuf/src
    • main/java/dev/cel/protobuf
      • CelLiteDescriptor.java
    • test/java/dev/cel/protobuf
      • BUILD.bazel
      • CelLiteDescriptorTest.java
  • runtime/src
    • main/java/dev/cel/runtime
      • BUILD.bazel
      • LiteAttributeStep.java
    • test/java/dev/cel/runtime
      • BUILD.bazel
      • LiteAttributeStepTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎common/src/main/java/dev/cel/common/values/BUILD.bazel‎

Copy file name to clipboardExpand all lines: common/src/main/java/dev/cel/common/values/BUILD.bazel
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ CEL_VALUES_SOURCES = [
1717
"ErrorValue.java",
1818
"NullValue.java",
1919
"OpaqueValue.java",
20+
"OptimizedSelectable.java",
2021
"OptionalValue.java",
22+
"SelectField.java",
2123
"SelectableValue.java",
2224
"StructValue.java",
2325
]
@@ -167,6 +169,7 @@ java_library(
167169
":preadapted_list",
168170
"//:auto_value",
169171
"//common/annotations",
172+
"//common/exceptions:attribute_not_found",
170173
"//common/types",
171174
"//common/types:type_providers",
172175
"@maven//:com_google_errorprone_error_prone_annotations",
@@ -218,6 +221,7 @@ cel_android_library(
218221
":preadapted_list_android",
219222
"//:auto_value",
220223
"//common/annotations",
224+
"//common/exceptions:attribute_not_found",
221225
"//common/types:type_providers_android",
222226
"//common/types:types_android",
223227
"@maven//:com_google_errorprone_error_prone_annotations",
@@ -317,6 +321,7 @@ java_library(
317321
srcs = [
318322
"ProtoLiteCelValueConverter.java",
319323
"ProtoMessageLiteValue.java",
324+
"RawProtoMessageLiteValue.java",
320325
],
321326
tags = [
322327
],
@@ -325,6 +330,7 @@ java_library(
325330
":values",
326331
"//:auto_value",
327332
"//common/annotations",
333+
"//common/exceptions:attribute_not_found",
328334
"//common/internal:cel_lite_descriptor_pool",
329335
"//common/internal:well_known_proto",
330336
"//common/types",
@@ -333,6 +339,7 @@ java_library(
333339
"//protobuf:cel_lite_descriptor",
334340
"@maven//:com_google_errorprone_error_prone_annotations",
335341
"@maven//:com_google_guava_guava",
342+
"@maven//:org_jspecify_jspecify",
336343
"@maven_android//:com_google_protobuf_protobuf_javalite",
337344
],
338345
)
@@ -342,6 +349,7 @@ cel_android_library(
342349
srcs = [
343350
"ProtoLiteCelValueConverter.java",
344351
"ProtoMessageLiteValue.java",
352+
"RawProtoMessageLiteValue.java",
345353
],
346354
tags = [
347355
],
@@ -350,6 +358,7 @@ cel_android_library(
350358
":values_android",
351359
"//:auto_value",
352360
"//common/annotations",
361+
"//common/exceptions:attribute_not_found",
353362
"//common/internal:cel_lite_descriptor_pool_android",
354363
"//common/internal:well_known_proto_android",
355364
"//common/types:type_providers_android",
@@ -358,6 +367,7 @@ cel_android_library(
358367
"//protobuf:cel_lite_descriptor",
359368
"@maven//:com_google_errorprone_error_prone_annotations",
360369
"@maven//:com_google_guava_guava",
370+
"@maven//:org_jspecify_jspecify",
361371
"@maven_android//:com_google_guava_guava",
362372
"@maven_android//:com_google_protobuf_protobuf_javalite",
363373
],
Collapse file

‎common/src/main/java/dev/cel/common/values/OptimizedSelectable.java‎

Copy file name to clipboard
+152Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package dev.cel.common.values;
16+
17+
import com.google.common.collect.ImmutableList;
18+
import com.google.errorprone.annotations.Immutable;
19+
import dev.cel.common.annotations.Internal;
20+
import dev.cel.common.exceptions.CelAttributeNotFoundException;
21+
import java.util.Map;
22+
import java.util.Optional;
23+
import org.jspecify.annotations.Nullable;
24+
25+
/**
26+
* Represents a value capable of evaluating optimized field selection and presence testing for field
27+
* selection optimization.
28+
*
29+
* <p>CEL Library Internals. Do Not Use.
30+
*/
31+
@Internal
32+
@Immutable
33+
public interface OptimizedSelectable {
34+
35+
/**
36+
* Evaluates a multi-hop qualification chain across the provided fields.
37+
*
38+
* <p>Implementations may override this method to provide an allocation-free traversal over
39+
* underlying schema or message descriptors. The default implementation iterates sequentially over
40+
* {@link #selectField} for intermediate submessages and the leaf.
41+
*/
42+
default Object qualify(ImmutableList<SelectField> fields) {
43+
Object current = this;
44+
for (SelectField field : fields) {
45+
if (current instanceof OptimizedSelectable) {
46+
current = ((OptimizedSelectable) current).selectField(field);
47+
} else if (current instanceof SelectableValue) {
48+
Optional<Object> found =
49+
SelectField.findField((SelectableValue<?>) current, field.fieldName());
50+
if (found.isPresent()) {
51+
current = found.get();
52+
} else if (field.defaultValue() != null) {
53+
current = field.defaultValue();
54+
} else {
55+
throw CelAttributeNotFoundException.forFieldResolution(field.fieldName());
56+
}
57+
} else if (current instanceof Map) {
58+
Map<?, ?> map = (Map<?, ?>) current;
59+
Object mapValue = map.get(field.fieldName());
60+
if (mapValue != null) {
61+
current = mapValue;
62+
} else if (map.containsKey(field.fieldName())) {
63+
current = NullValue.NULL_VALUE;
64+
} else {
65+
throw CelAttributeNotFoundException.forMissingMapKey(field.fieldName());
66+
}
67+
} else {
68+
throw CelAttributeNotFoundException.forFieldResolution(field.fieldName());
69+
}
70+
}
71+
return current;
72+
}
73+
74+
/**
75+
* Performs field selection for a single hop in an optimized selection chain.
76+
*
77+
* @param field The field hop descriptor containing field number, name, type code, and default
78+
* value.
79+
* @return The selected field value, or default value / empty submessage if absent.
80+
*/
81+
Object selectField(SelectField field);
82+
83+
/**
84+
* Evaluates presence testing across the provided fields.
85+
*
86+
* <p>Implementations may override this method to provide an allocation-free traversal over
87+
* underlying schema or message descriptors. The default implementation iterates sequentially over
88+
* {@link #navigateField} for intermediate submessages and {@link #hasField} for the leaf.
89+
*/
90+
default boolean hasField(ImmutableList<SelectField> fields) {
91+
if (fields.isEmpty()) {
92+
return false;
93+
}
94+
int lastIndex = fields.size() - 1;
95+
Object current = this;
96+
for (int i = 0; i < lastIndex; i++) {
97+
SelectField field = fields.get(i);
98+
if (current instanceof OptimizedSelectable) {
99+
current = ((OptimizedSelectable) current).navigateField(field);
100+
if (current == null) {
101+
return false;
102+
}
103+
} else if (current instanceof SelectableValue) {
104+
Optional<Object> found =
105+
SelectField.findField((SelectableValue<?>) current, field.fieldName());
106+
if (!found.isPresent()) {
107+
return false;
108+
}
109+
current = found.get();
110+
} else if (current instanceof Map) {
111+
Map<?, ?> map = (Map<?, ?>) current;
112+
if (!map.containsKey(field.fieldName())) {
113+
return false;
114+
}
115+
Object mapValue = map.get(field.fieldName());
116+
current = (mapValue != null) ? mapValue : NullValue.NULL_VALUE;
117+
} else {
118+
throw CelAttributeNotFoundException.forFieldResolution(field.fieldName());
119+
}
120+
}
121+
SelectField terminalField = fields.get(lastIndex);
122+
if (current instanceof OptimizedSelectable) {
123+
return ((OptimizedSelectable) current).hasField(terminalField);
124+
} else if (current instanceof SelectableValue) {
125+
return SelectField.findField((SelectableValue<?>) current, terminalField.fieldName())
126+
.isPresent();
127+
} else if (current instanceof Map) {
128+
return ((Map<?, ?>) current).containsKey(terminalField.fieldName());
129+
} else {
130+
throw CelAttributeNotFoundException.forFieldResolution(terminalField.fieldName());
131+
}
132+
}
133+
134+
/**
135+
* Evaluates presence testing for a single hop in an optimized selection chain.
136+
*
137+
* @param field The field hop descriptor.
138+
* @return True if the field is present, false otherwise.
139+
*/
140+
boolean hasField(SelectField field);
141+
142+
/**
143+
* Navigates into an intermediate submessage for presence testing.
144+
*
145+
* <p>Returns {@code null} instead of an {@link Optional} to avoid object allocation overhead on
146+
* hot-path intermediate navigation hops.
147+
*
148+
* @param field The field hop descriptor.
149+
* @return The submessage if present, or {@code null} if absent.
150+
*/
151+
@Nullable Object navigateField(SelectField field);
152+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.