Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public abstract class SelectField {
private static final int MAX_FIELD_NUMBER = 536870911;

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

/** Sentinel for a presence-test qualifier, whose 2-tuple carries no type code. */
static final int NO_TYPE_CODE = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void mapEntrySpec_validKeyTypeCodes_success(
@Test
public void mapEntrySpec_invalidKeyTypeCode_throwsIllegalArgumentException(
@TestParameter({
"-1", // CEL_MAP_TYPE_CODE
"-10", // CEL_MAP_TYPE_CODE
"0", // NO_TYPE_CODE
"1", // DOUBLE
"2", // FLOAT
Expand All @@ -245,7 +245,7 @@ public void mapEntrySpec_invalidKeyTypeCode_throwsIllegalArgumentException(
@Test
public void mapEntrySpec_invalidValueTypeCode_throwsIllegalArgumentException(
@TestParameter({
"-1", // CEL_MAP_TYPE_CODE
"-10", // CEL_MAP_TYPE_CODE
"0", // NO_TYPE_CODE
"10", // GROUP
"19" // OUT_OF_BOUNDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
* <li>Scalar, repeated, and message fields are represented as 3-tuples: {@code [field_num,
* field_name, type_code]}.
* <li>Map fields are represented as 4-tuples with a 2-element field type code spec: {@code
* [field_num, field_name, -1, [key_type_code, val_type_code]]}.
* [field_num, field_name, -10, [key_type_code, val_type_code]]}.
* </ul>
*
* <p>The 3rd argument of {@code cel.@attribute} is a typed expression that binds the result type
Expand Down Expand Up @@ -158,7 +158,7 @@ public final class SelectOptimizer implements CelAstOptimizer {
* <p>Protobuf wire format encodes maps as repeated message entries ({@code MapEntry}). To avoid
* wire-decoding ambiguities with singular submessages, maps use this dedicated type code.
*/
private static final long CEL_MAP_TYPE_CODE = -1L;
private static final long CEL_MAP_TYPE_CODE = -10L;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,49 +325,49 @@ private enum RewriteTestCase {
// Map selects
MAP_STRING_STRING(
"msg.map_string_string",
"cel.@attribute(msg, [[61, \"map_string_string\", -1, [9, 9]]], {\"\": \"\"})"),
"cel.@attribute(msg, [[61, \"map_string_string\", -10, [9, 9]]], {\"\": \"\"})"),
MAP_BOOL_STRING(
"msg.map_bool_string",
"cel.@attribute(msg, [[64, \"map_bool_string\", -1, [8, 9]]], {false: \"\"})"),
"cel.@attribute(msg, [[64, \"map_bool_string\", -10, [8, 9]]], {false: \"\"})"),
MAP_UINT32_DOUBLE(
"msg.map_uint32_double",
"cel.@attribute(msg, [[204, \"map_uint32_double\", -1, [13, 1]]], {0u: 0.0})"),
"cel.@attribute(msg, [[204, \"map_uint32_double\", -10, [13, 1]]], {0u: 0.0})"),
MAP_INT64_ENUM(
"msg.map_int64_enum",
"cel.@attribute(msg, [[94, \"map_int64_enum\", -1, [3, 14]]], {0: 0})"),
"cel.@attribute(msg, [[94, \"map_int64_enum\", -10, [3, 14]]], {0: 0})"),
MAP_STRING_DURATION(
"msg.map_string_duration",
"cel.@attribute(msg, [[243, \"map_string_duration\", -1, [9, 11]]],"
"cel.@attribute(msg, [[243, \"map_string_duration\", -10, [9, 11]]],"
+ " {\"\": google.protobuf.Duration{}})"),
MAP_FIELD_INDEXING(
"msg.map_int64_message[1].bb",
"cel.@attribute(msg, [[95, \"map_int64_message\", -1, [3, 11]], 1, [1, \"bb\", 5]], 0)"),
"cel.@attribute(msg, [[95, \"map_int64_message\", -10, [3, 11]], 1, [1, \"bb\", 5]], 0)"),
REPEATED_FIELD_INDEXING(
"msg.repeated_nested_message[0].bb",
"cel.@attribute(msg, [[51, \"repeated_nested_message\", 11], 0, [1, \"bb\", 5]], 0)"),
MAP_AND_REPEATED_FIELD_INDEXING(
"msg.map_int64_nested_type[1].child.payload.repeated_nested_message[0].bb",
"cel.@attribute(msg, [[62, \"map_int64_nested_type\", -1, [3, 11]], 1, "
"cel.@attribute(msg, [[62, \"map_int64_nested_type\", -10, [3, 11]], 1, "
+ "[1, \"child\", 11], [2, \"payload\", 11], "
+ "[51, \"repeated_nested_message\", 11], 0, [1, \"bb\", 5]], 0)"),
MAP_FIELD_UINT_KEY_INDEXING(
"msg.map_uint64_message[1u].bb",
"cel.@attribute(msg, [[217, \"map_uint64_message\", -1, [4, 11]], 1u, "
"cel.@attribute(msg, [[217, \"map_uint64_message\", -10, [4, 11]], 1u, "
+ "[1, \"bb\", 5]], 0)"),
MAP_FIELD_BOOL_KEY_INDEXING(
"msg.map_bool_message[true].bb",
"cel.@attribute(msg, [[73, \"map_bool_message\", -1, [8, 11]], true, "
"cel.@attribute(msg, [[73, \"map_bool_message\", -10, [8, 11]], true, "
+ "[1, \"bb\", 5]], 0)"),
REPEATED_FIELD_HAS_THROUGH_INDEX(
"has(msg.repeated_nested_message[0].bb)",
"cel.@hasField(msg, [[51, \"repeated_nested_message\", 11], 0, [1, \"bb\"]])"),
MAP_FIELD_HAS_THROUGH_INDEX(
"has(msg.map_int64_nested_type[1].child.payload.single_int64)",
"cel.@hasField(msg, [[62, \"map_int64_nested_type\", -1, [3, 11]], 1, "
"cel.@hasField(msg, [[62, \"map_int64_nested_type\", -10, [3, 11]], 1, "
+ "[1, \"child\"], [2, \"payload\"], [2, \"single_int64\"]])"),
HAS_THROUGH_TWO_INDICES(
"has(msg.map_int64_nested_type[1].child.payload.repeated_nested_message[0].bb)",
"cel.@hasField(msg, [[62, \"map_int64_nested_type\", -1, [3, 11]], 1, "
"cel.@hasField(msg, [[62, \"map_int64_nested_type\", -10, [3, 11]], 1, "
+ "[1, \"child\", 11], [2, \"payload\", 11], "
+ "[51, \"repeated_nested_message\", 11], 0, [1, \"bb\"]])"),
REPEATED_FIELD_DYNAMIC_INDEX_STOPS_AT_INDEX(
Expand Down Expand Up @@ -404,18 +404,18 @@ private enum RewriteTestCase {
PROTO_MAP_FIELD_SELECT_STOPS_AT_MAP_BOUNDARY(
"msg.map_string_message.key.bb",
"cel.@attribute("
+ "cel.@attribute(msg, [[227, \"map_string_message\", -1, [9, 11]]],"
+ "cel.@attribute(msg, [[227, \"map_string_message\", -10, [9, 11]]],"
+ " {\"\": cel.expr.conformance.proto3.TestAllTypes.NestedMessage{}}).key, "
+ "[[1, \"bb\", 5]], 0)"),
PROTO_MAP_FIELD_HAS_STOPS_AT_MAP_BOUNDARY(
"has(msg.map_string_message.key.bb)",
"cel.@hasField("
+ "cel.@attribute(msg, [[227, \"map_string_message\", -1, [9, 11]]],"
+ "cel.@attribute(msg, [[227, \"map_string_message\", -10, [9, 11]]],"
+ " {\"\": cel.expr.conformance.proto3.TestAllTypes.NestedMessage{}}).key, "
+ "[[1, \"bb\"]])"),
PROTO_MAP_FIELD_SELECT_STOPS_AT_ANY_BOUNDARY(
"msg.map_string_any['k'].value",
"cel.@attribute(msg, [[311, \"map_string_any\", -1, [9, 11]]],"
"cel.@attribute(msg, [[311, \"map_string_any\", -10, [9, 11]]],"
+ " {\"\": google.protobuf.Any{}})[\"k\"].value"),
ANY_FIELD(
"msg.single_any",
Expand Down Expand Up @@ -561,7 +561,7 @@ public void optimize_withFileDescriptorsIterable_success() throws Exception {
+ " cel.@attribute(msg, [[51, \"repeated_nested_message\", 11]],"
+ " [.cel.expr.conformance.proto3.TestAllTypes.NestedMessage{}]))'}",
"{expression: '[[1]].map(cel, msg.map_int64_message)', expected: '[[1]].map(cel,"
+ " cel.@attribute(msg, [[95, \"map_int64_message\", -1, [3, 11]]],"
+ " cel.@attribute(msg, [[95, \"map_int64_message\", -10, [3, 11]]],"
+ " {0: .cel.expr.conformance.proto3.TestAllTypes.NestedMessage{}}))'}"
})
public void optimize_messageNameUnderShadowingComprehensionVar_rewrites(
Expand Down Expand Up @@ -681,7 +681,7 @@ public void optimize_messageNameInBindInit_rewrites() throws Exception {
+ " cel.@attribute(msg, [[102, \"single_timestamp\", 11]],"
+ " .google.protobuf.Timestamp{}))'}",
"{expression: '[1].map(duration, msg.map_string_duration)', expected: '[1].map(duration,"
+ " cel.@attribute(msg, [[243, \"map_string_duration\", -1, [9, 11]]],"
+ " cel.@attribute(msg, [[243, \"map_string_duration\", -10, [9, 11]]],"
+ " {\"\": .google.protobuf.Duration{}}))'}"
})
public void optimize_durationOrTimestampUnderShadowingComprehensionVar_rewrites(
Expand Down Expand Up @@ -1724,7 +1724,7 @@ public void optimize_optionalMapKeySelection_rewritesMapField() throws Exception

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ public void plan_invalidAst_mapHopWithMissingEntrySpec_throwsEvaluationException
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
CelExpr.ofConstant(
6L, CelConstant.ofValue("map_string_string")),
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L))),
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L))),
ImmutableList.of())),
ImmutableList.of()),
CelExpr.ofMap(
Expand Down Expand Up @@ -648,7 +648,7 @@ public void plan_invalidAst_mapEntrySpecMalformed_throwsEvaluationException() {
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
CelExpr.ofConstant(
6L, CelConstant.ofValue("map_string_string")),
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L)),
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L)),
CelExpr.ofList(
8L,
ImmutableList.of(
Expand Down Expand Up @@ -715,7 +715,7 @@ private enum ScalarDummyMismatchTestCase {
ImmutableList.of(
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
CelExpr.ofConstant(6L, CelConstant.ofValue("map_string_string")),
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L)),
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L)),
mapEntrySpec(9L, 9L)),
CelExpr.ofMap(
20L,
Expand All @@ -729,7 +729,7 @@ private enum ScalarDummyMismatchTestCase {
ImmutableList.of(
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
CelExpr.ofConstant(6L, CelConstant.ofValue("map_string_string")),
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L)),
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L)),
mapEntrySpec(9L, 9L)),
CelExpr.ofMap(
20L,
Expand Down Expand Up @@ -800,7 +800,7 @@ public void plan_invalidAst_mapFieldWithEmptyMapDummy_throwsEvaluationException(
CelExpr.ofConstant(5L, CelConstant.ofValue(1L)),
CelExpr.ofConstant(
6L, CelConstant.ofValue("map_string_string")),
CelExpr.ofConstant(7L, CelConstant.ofValue(-1L)),
CelExpr.ofConstant(7L, CelConstant.ofValue(-10L)),
CelExpr.ofList(
8L,
ImmutableList.of(
Expand Down Expand Up @@ -934,7 +934,7 @@ private static CelExpr mapHop(
ImmutableList.of(
CelExpr.ofConstant(0L, CelConstant.ofValue(fieldNumber)),
CelExpr.ofConstant(0L, CelConstant.ofValue(fieldName)),
CelExpr.ofConstant(0L, CelConstant.ofValue(-1L)),
CelExpr.ofConstant(0L, CelConstant.ofValue(-10L)),
mapEntrySpec(keyTypeCode, valueTypeCode)),
ImmutableList.of());
}
Expand Down
Loading