Skip to content

Commit 959fa04

Browse files
l46kokcopybara-github
authored andcommitted
Change CEL_MAP_TYPE_CODE sentinel from -1 to -10
PiperOrigin-RevId: 1010663299
1 parent 8eeb17a commit 959fa04

5 files changed

Lines changed: 28 additions & 28 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public abstract class SelectField {
3939
private static final int MAX_FIELD_NUMBER = 536870911;
4040

4141
/** CEL-specific type code used to encode CEL maps on the wire. */
42-
public static final int CEL_MAP_TYPE_CODE = -1;
42+
public static final int CEL_MAP_TYPE_CODE = -10;
4343

4444
/** Sentinel for a presence-test qualifier, whose 2-tuple carries no type code. */
4545
static final int NO_TYPE_CODE = 0;

‎common/src/test/java/dev/cel/common/values/SelectFieldTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public void mapEntrySpec_validKeyTypeCodes_success(
227227
@Test
228228
public void mapEntrySpec_invalidKeyTypeCode_throwsIllegalArgumentException(
229229
@TestParameter({
230-
"-1", // CEL_MAP_TYPE_CODE
230+
"-10", // CEL_MAP_TYPE_CODE
231231
"0", // NO_TYPE_CODE
232232
"1", // DOUBLE
233233
"2", // FLOAT
@@ -245,7 +245,7 @@ public void mapEntrySpec_invalidKeyTypeCode_throwsIllegalArgumentException(
245245
@Test
246246
public void mapEntrySpec_invalidValueTypeCode_throwsIllegalArgumentException(
247247
@TestParameter({
248-
"-1", // CEL_MAP_TYPE_CODE
248+
"-10", // CEL_MAP_TYPE_CODE
249249
"0", // NO_TYPE_CODE
250250
"10", // GROUP
251251
"19" // OUT_OF_BOUNDS

‎optimizer/src/main/java/dev/cel/optimizer/optimizers/SelectOptimizer.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
* <li>Scalar, repeated, and message fields are represented as 3-tuples: {@code [field_num,
9898
* field_name, type_code]}.
9999
* <li>Map fields are represented as 4-tuples with a 2-element field type code spec: {@code
100-
* [field_num, field_name, -1, [key_type_code, val_type_code]]}.
100+
* [field_num, field_name, -10, [key_type_code, val_type_code]]}.
101101
* </ul>
102102
*
103103
* <p>The 3rd argument of {@code cel.@attribute} is a typed expression that binds the result type
@@ -158,7 +158,7 @@ public final class SelectOptimizer implements CelAstOptimizer {
158158
* <p>Protobuf wire format encodes maps as repeated message entries ({@code MapEntry}). To avoid
159159
* wire-decoding ambiguities with singular submessages, maps use this dedicated type code.
160160
*/
161-
private static final long CEL_MAP_TYPE_CODE = -1L;
161+
private static final long CEL_MAP_TYPE_CODE = -10L;
162162

163163
private static final TypeParamType TYPE_PARAM_T = TypeParamType.create("T");
164164

‎optimizer/src/test/java/dev/cel/optimizer/optimizers/SelectOptimizerTest.java‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,49 +325,49 @@ private enum RewriteTestCase {
325325
// Map selects
326326
MAP_STRING_STRING(
327327
"msg.map_string_string",
328-
"cel.@attribute(msg, [[61, \"map_string_string\", -1, [9, 9]]], {\"\": \"\"})"),
328+
"cel.@attribute(msg, [[61, \"map_string_string\", -10, [9, 9]]], {\"\": \"\"})"),
329329
MAP_BOOL_STRING(
330330
"msg.map_bool_string",
331-
"cel.@attribute(msg, [[64, \"map_bool_string\", -1, [8, 9]]], {false: \"\"})"),
331+
"cel.@attribute(msg, [[64, \"map_bool_string\", -10, [8, 9]]], {false: \"\"})"),
332332
MAP_UINT32_DOUBLE(
333333
"msg.map_uint32_double",
334-
"cel.@attribute(msg, [[204, \"map_uint32_double\", -1, [13, 1]]], {0u: 0.0})"),
334+
"cel.@attribute(msg, [[204, \"map_uint32_double\", -10, [13, 1]]], {0u: 0.0})"),
335335
MAP_INT64_ENUM(
336336
"msg.map_int64_enum",
337-
"cel.@attribute(msg, [[94, \"map_int64_enum\", -1, [3, 14]]], {0: 0})"),
337+
"cel.@attribute(msg, [[94, \"map_int64_enum\", -10, [3, 14]]], {0: 0})"),
338338
MAP_STRING_DURATION(
339339
"msg.map_string_duration",
340-
"cel.@attribute(msg, [[243, \"map_string_duration\", -1, [9, 11]]],"
340+
"cel.@attribute(msg, [[243, \"map_string_duration\", -10, [9, 11]]],"
341341
+ " {\"\": google.protobuf.Duration{}})"),
342342
MAP_FIELD_INDEXING(
343343
"msg.map_int64_message[1].bb",
344-
"cel.@attribute(msg, [[95, \"map_int64_message\", -1, [3, 11]], 1, [1, \"bb\", 5]], 0)"),
344+
"cel.@attribute(msg, [[95, \"map_int64_message\", -10, [3, 11]], 1, [1, \"bb\", 5]], 0)"),
345345
REPEATED_FIELD_INDEXING(
346346
"msg.repeated_nested_message[0].bb",
347347
"cel.@attribute(msg, [[51, \"repeated_nested_message\", 11], 0, [1, \"bb\", 5]], 0)"),
348348
MAP_AND_REPEATED_FIELD_INDEXING(
349349
"msg.map_int64_nested_type[1].child.payload.repeated_nested_message[0].bb",
350-
"cel.@attribute(msg, [[62, \"map_int64_nested_type\", -1, [3, 11]], 1, "
350+
"cel.@attribute(msg, [[62, \"map_int64_nested_type\", -10, [3, 11]], 1, "
351351
+ "[1, \"child\", 11], [2, \"payload\", 11], "
352352
+ "[51, \"repeated_nested_message\", 11], 0, [1, \"bb\", 5]], 0)"),
353353
MAP_FIELD_UINT_KEY_INDEXING(
354354
"msg.map_uint64_message[1u].bb",
355-
"cel.@attribute(msg, [[217, \"map_uint64_message\", -1, [4, 11]], 1u, "
355+
"cel.@attribute(msg, [[217, \"map_uint64_message\", -10, [4, 11]], 1u, "
356356
+ "[1, \"bb\", 5]], 0)"),
357357
MAP_FIELD_BOOL_KEY_INDEXING(
358358
"msg.map_bool_message[true].bb",
359-
"cel.@attribute(msg, [[73, \"map_bool_message\", -1, [8, 11]], true, "
359+
"cel.@attribute(msg, [[73, \"map_bool_message\", -10, [8, 11]], true, "
360360
+ "[1, \"bb\", 5]], 0)"),
361361
REPEATED_FIELD_HAS_THROUGH_INDEX(
362362
"has(msg.repeated_nested_message[0].bb)",
363363
"cel.@hasField(msg, [[51, \"repeated_nested_message\", 11], 0, [1, \"bb\"]])"),
364364
MAP_FIELD_HAS_THROUGH_INDEX(
365365
"has(msg.map_int64_nested_type[1].child.payload.single_int64)",
366-
"cel.@hasField(msg, [[62, \"map_int64_nested_type\", -1, [3, 11]], 1, "
366+
"cel.@hasField(msg, [[62, \"map_int64_nested_type\", -10, [3, 11]], 1, "
367367
+ "[1, \"child\"], [2, \"payload\"], [2, \"single_int64\"]])"),
368368
HAS_THROUGH_TWO_INDICES(
369369
"has(msg.map_int64_nested_type[1].child.payload.repeated_nested_message[0].bb)",
370-
"cel.@hasField(msg, [[62, \"map_int64_nested_type\", -1, [3, 11]], 1, "
370+
"cel.@hasField(msg, [[62, \"map_int64_nested_type\", -10, [3, 11]], 1, "
371371
+ "[1, \"child\", 11], [2, \"payload\", 11], "
372372
+ "[51, \"repeated_nested_message\", 11], 0, [1, \"bb\"]])"),
373373
REPEATED_FIELD_DYNAMIC_INDEX_STOPS_AT_INDEX(
@@ -404,18 +404,18 @@ private enum RewriteTestCase {
404404
PROTO_MAP_FIELD_SELECT_STOPS_AT_MAP_BOUNDARY(
405405
"msg.map_string_message.key.bb",
406406
"cel.@attribute("
407-
+ "cel.@attribute(msg, [[227, \"map_string_message\", -1, [9, 11]]],"
407+
+ "cel.@attribute(msg, [[227, \"map_string_message\", -10, [9, 11]]],"
408408
+ " {\"\": cel.expr.conformance.proto3.TestAllTypes.NestedMessage{}}).key, "
409409
+ "[[1, \"bb\", 5]], 0)"),
410410
PROTO_MAP_FIELD_HAS_STOPS_AT_MAP_BOUNDARY(
411411
"has(msg.map_string_message.key.bb)",
412412
"cel.@hasField("
413-
+ "cel.@attribute(msg, [[227, \"map_string_message\", -1, [9, 11]]],"
413+
+ "cel.@attribute(msg, [[227, \"map_string_message\", -10, [9, 11]]],"
414414
+ " {\"\": cel.expr.conformance.proto3.TestAllTypes.NestedMessage{}}).key, "
415415
+ "[[1, \"bb\"]])"),
416416
PROTO_MAP_FIELD_SELECT_STOPS_AT_ANY_BOUNDARY(
417417
"msg.map_string_any['k'].value",
418-
"cel.@attribute(msg, [[311, \"map_string_any\", -1, [9, 11]]],"
418+
"cel.@attribute(msg, [[311, \"map_string_any\", -10, [9, 11]]],"
419419
+ " {\"\": google.protobuf.Any{}})[\"k\"].value"),
420420
ANY_FIELD(
421421
"msg.single_any",
@@ -561,7 +561,7 @@ public void optimize_withFileDescriptorsIterable_success() throws Exception {
561561
+ " cel.@attribute(msg, [[51, \"repeated_nested_message\", 11]],"
562562
+ " [.cel.expr.conformance.proto3.TestAllTypes.NestedMessage{}]))'}",
563563
"{expression: '[[1]].map(cel, msg.map_int64_message)', expected: '[[1]].map(cel,"
564-
+ " cel.@attribute(msg, [[95, \"map_int64_message\", -1, [3, 11]]],"
564+
+ " cel.@attribute(msg, [[95, \"map_int64_message\", -10, [3, 11]]],"
565565
+ " {0: .cel.expr.conformance.proto3.TestAllTypes.NestedMessage{}}))'}"
566566
})
567567
public void optimize_messageNameUnderShadowingComprehensionVar_rewrites(
@@ -681,7 +681,7 @@ public void optimize_messageNameInBindInit_rewrites() throws Exception {
681681
+ " cel.@attribute(msg, [[102, \"single_timestamp\", 11]],"
682682
+ " .google.protobuf.Timestamp{}))'}",
683683
"{expression: '[1].map(duration, msg.map_string_duration)', expected: '[1].map(duration,"
684-
+ " cel.@attribute(msg, [[243, \"map_string_duration\", -1, [9, 11]]],"
684+
+ " cel.@attribute(msg, [[243, \"map_string_duration\", -10, [9, 11]]],"
685685
+ " {\"\": .google.protobuf.Duration{}}))'}"
686686
})
687687
public void optimize_durationOrTimestampUnderShadowingComprehensionVar_rewrites(
@@ -1724,7 +1724,7 @@ public void optimize_optionalMapKeySelection_rewritesMapField() throws Exception
17241724

17251725
assertThat(CEL_UNPARSER.unparse(optimizedAst))
17261726
.isEqualTo(
1727-
"cel.@attribute(msg, [[61, \"map_string_string\", -1, [9, 9]]], {\"\": \"\"}).?key");
1727+
"cel.@attribute(msg, [[61, \"map_string_string\", -10, [9, 9]]], {\"\": \"\"}).?key");
17281728
}
17291729

17301730
@Test

‎runtime/src/test/java/dev/cel/runtime/planner/OptimizedSelectPlannerTest.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public void plan_invalidAst_mapHopWithMissingEntrySpec_throwsEvaluationException
611611
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
612612
CelExpr.ofConstant(
613613
6L, CelConstant.ofValue("map_string_string")),
614-
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L))),
614+
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L))),
615615
ImmutableList.of())),
616616
ImmutableList.of()),
617617
CelExpr.ofMap(
@@ -648,7 +648,7 @@ public void plan_invalidAst_mapEntrySpecMalformed_throwsEvaluationException() {
648648
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
649649
CelExpr.ofConstant(
650650
6L, CelConstant.ofValue("map_string_string")),
651-
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L)),
651+
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L)),
652652
CelExpr.ofList(
653653
8L,
654654
ImmutableList.of(
@@ -715,7 +715,7 @@ private enum ScalarDummyMismatchTestCase {
715715
ImmutableList.of(
716716
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
717717
CelExpr.ofConstant(6L, CelConstant.ofValue("map_string_string")),
718-
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L)),
718+
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L)),
719719
mapEntrySpec(9L, 9L)),
720720
CelExpr.ofMap(
721721
20L,
@@ -729,7 +729,7 @@ private enum ScalarDummyMismatchTestCase {
729729
ImmutableList.of(
730730
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
731731
CelExpr.ofConstant(6L, CelConstant.ofValue("map_string_string")),
732-
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L)),
732+
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L)),
733733
mapEntrySpec(9L, 9L)),
734734
CelExpr.ofMap(
735735
20L,
@@ -800,7 +800,7 @@ public void plan_invalidAst_mapFieldWithEmptyMapDummy_throwsEvaluationException(
800800
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
801801
CelExpr.ofConstant(
802802
6L, CelConstant.ofValue("map_string_string")),
803-
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L)),
803+
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L)),
804804
CelExpr.ofList(
805805
8L,
806806
ImmutableList.of(
@@ -934,7 +934,7 @@ private static CelExpr mapHop(
934934
ImmutableList.of(
935935
CelExpr.ofConstant(0L, CelConstant.ofValue(fieldNumber)),
936936
CelExpr.ofConstant(0L, CelConstant.ofValue(fieldName)),
937-
CelExpr.ofConstant(0L, CelConstant.ofValue(-1L)),
937+
CelExpr.ofConstant(0L, CelConstant.ofValue(-10L)),
938938
mapEntrySpec(keyTypeCode, valueTypeCode)),
939939
ImmutableList.of());
940940
}

0 commit comments

Comments
 (0)