Skip to content

Commit 107f471

Browse files
update uuid_string function.
1 parent d3b1413 commit 107f471

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/snowflake/snowpark/_functions/scalar_functions.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,7 +4427,7 @@ def uuid_string(
44274427
uuid: ColumnOrName = None, name: ColumnOrName = None, _emit_ast: bool = True
44284428
) -> Column:
44294429
"""
4430-
Returns a universally unique identifier (UUID) as a string.
4430+
Returns a universally unique identifier (UUID) as a string. If the uuid is provided, also the name must be provided.
44314431
44324432
Args:
44334433
uuid (ColumnOrName, optional): The namespace UUID as a string. If provided, generates a UUID based on this namespace.
@@ -4437,28 +4437,25 @@ def uuid_string(
44374437
Column: The UUID string.
44384438
44394439
Examples::
4440-
>>> df = session.create_dataframe([["test"]], schema=["a"])
4441-
>>> df.select(uuid_string().alias("random_uuid")).collect() # doctest: +SKIP
4442-
[Row(RANDOM_UUID='...')]
4440+
>>> from snowflake.snowpark.functions import col
44434441
4444-
>>> df.select(uuid_string("fe971b24-9572-4005-b22f-351e9c09274d", "foo").alias("named_uuid")).collect() # doctest: +SKIP
4445-
[Row(NAMED_UUID='...')]
4442+
>>> df = session.create_dataframe(
4443+
... [["fe971b24-9572-4005-b22f-351e9c09274d", "foo"]], schema=["uuid", "name"]
4444+
... )
44464445
4447-
>>> df.select(uuid_string("fe971b24-9572-4005-b22f-351e9c09274d").alias("uuid_with_namespace")).collect() # doctest: +SKIP
4448-
[Row(UUID_WITH_NAMESPACE='...')]
4446+
>>> df.select(uuid_string().alias("random_uuid")).collect()
4447+
[Row(RANDOM_UUID='...')]
44494448
4450-
>>> df.select(uuid_string(name="foo").alias("uuid_with_name")).collect() # doctest: +SKIP
4451-
[Row(UUID_WITH_NAME='...')]
4449+
>>> result = df.select(
4450+
... uuid_string(col("uuid"), col("name")).alias("NAMED_UUID")
4451+
... ).collect()
4452+
>>> expected_uuid = "dc0b6f65-fca6-5b4b-9d37-ccc3fde1f3e2"
4453+
>>> result[0]["NAMED_UUID"] == expected_uuid
4454+
True
44524455
"""
44534456
if uuid is None and name is None:
44544457
return builtin("uuid_string", _emit_ast=_emit_ast)()
4455-
elif uuid is not None and name is not None:
4458+
else:
44564459
uuid_col = _to_col_if_str(uuid, "uuid_string")
44574460
name_col = _to_col_if_str(name, "uuid_string")
44584461
return builtin("uuid_string", _emit_ast=_emit_ast)(uuid_col, name_col)
4459-
elif uuid is not None:
4460-
uuid_col = _to_col_if_str(uuid, "uuid_string")
4461-
return builtin("uuid_string", _emit_ast=_emit_ast)(uuid_col)
4462-
else:
4463-
name_col = _to_col_if_str(name, "uuid_string")
4464-
return builtin("uuid_string", _emit_ast=_emit_ast)(name_col)

0 commit comments

Comments
 (0)