Skip to content

add string(bool) overload #728

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2025
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 @@ -159,6 +159,7 @@ enum StandardFunction {
Overload.Conversions.INT64_TO_STRING,
Overload.Conversions.UINT64_TO_STRING,
Overload.Conversions.DOUBLE_TO_STRING,
Overload.Conversions.BOOL_TO_STRING,
Overload.Conversions.BYTES_TO_STRING,
Overload.Conversions.TIMESTAMP_TO_STRING,
Overload.Conversions.DURATION_TO_STRING),
Expand Down Expand Up @@ -679,6 +680,9 @@ public enum Conversions implements StandardOverload {
DOUBLE_TO_STRING(
CelOverloadDecl.newGlobalOverload(
"double_to_string", "type conversion", SimpleType.STRING, SimpleType.DOUBLE)),
BOOL_TO_STRING(
CelOverloadDecl.newGlobalOverload(
"bool_to_string", "type conversion", SimpleType.STRING, SimpleType.BOOL)),
BYTES_TO_STRING(
CelOverloadDecl.newGlobalOverload(
"bytes_to_string", "type conversion", SimpleType.STRING, SimpleType.BYTES)),
Expand Down
1 change: 1 addition & 0 deletions checker/src/test/resources/standardEnvDump.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ declare string {
function int64_to_string (int) -> string
function uint64_to_string (uint) -> string
function double_to_string (double) -> string
function bool_to_string (bool) -> string
function bytes_to_string (bytes) -> string
function timestamp_to_string (google.protobuf.Timestamp) -> string
function duration_to_string (google.protobuf.Duration) -> string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public enum StandardFunction {
Conversions.STRING_TO_STRING,
Conversions.INT64_TO_STRING,
Conversions.DOUBLE_TO_STRING,
Conversions.BOOL_TO_STRING,
Conversions.BYTES_TO_STRING,
Conversions.TIMESTAMP_TO_STRING,
Conversions.DURATION_TO_STRING,
Expand Down Expand Up @@ -478,6 +479,7 @@ public enum Conversions implements StandardOverload {
STRING_TO_STRING(StringOverload.STRING_TO_STRING::newFunctionBinding),
INT64_TO_STRING(StringOverload.INT64_TO_STRING::newFunctionBinding),
DOUBLE_TO_STRING(StringOverload.DOUBLE_TO_STRING::newFunctionBinding),
BOOL_TO_STRING(StringOverload.BOOL_TO_STRING::newFunctionBinding),
BYTES_TO_STRING(StringOverload.BYTES_TO_STRING::newFunctionBinding),
TIMESTAMP_TO_STRING(StringOverload.TIMESTAMP_TO_STRING::newFunctionBinding),
DURATION_TO_STRING(StringOverload.DURATION_TO_STRING::newFunctionBinding),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ public enum StringOverload implements CelStandardOverload {
(celOptions, runtimeEquality) ->
CelFunctionBinding.from("int64_to_string", Long.class, Object::toString)),
DOUBLE_TO_STRING(
(celOptions, runtimeEquality) ->
CelFunctionBinding.from("double_to_string", Double.class, Object::toString)),
(celOptions, runtimeEquality) ->
CelFunctionBinding.from("double_to_string", Double.class, Object::toString)),
BOOL_TO_STRING(
(celOptions, runtimeEquality) ->
CelFunctionBinding.from("bool_to_string", Boolean.class, Object::toString)),
BYTES_TO_STRING(
(celOptions, runtimeEquality) ->
CelFunctionBinding.from(
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/test/resources/stringConversions.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Source: string(-1)
bindings: {}
result: -1

Source: string(true)
=====>
bindings: {}
result: true

Source: string(b'abc\303\203')
=====>
bindings: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,9 @@ public void stringConversions() {
source = "string(-1)"; // int converts to '-1'
runTest();

source = "string(true)"; // bool converts to 'true'
runTest();

// Byte literals in Google SQL only take the leading byte of an escape character.
// This means that to translate a byte literal to a UTF-8 encoded string, all bytes must be
// encoded in the literal as they would be laid out in memory for UTF-8, hence the extra octal
Expand Down