You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by cs...@apache.org on 2026/09/17 07:19:43 UTC
(impala) 01/02: IMPALA-15202: Add explicit CAST support between UUID and STRING
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 4ec7bebb59c8cea5c0b706bf2f3b639dad03af63
Author: Arnab Karmakar <ar...@gmail.com>
AuthorDate: Thu Sep 10 23:08:53 2026 -0700
IMPALA-15202: Add explicit CAST support between UUID and STRING
Add explicit CAST(expr AS UUID) and CAST(expr AS STRING) for Iceberg
UUID columns. Implicit casts between UUID and other types remain blocked
via UuidCompatibility. Users must write explicit casts to compare UUID
columns with string literals or to use string functions.
Key changes:
- Add CastToUuid to parse canonical 36-char strings into 16-byte UUID
values with runtime validation and error reporting
- Add CastUuidToString to format UUID bytes as canonical lowercase
strings
- Register explicit STRING/VARCHAR/CHAR -> UUID and UUID -> STRING cast
builtins in CastExpr.initBuiltins()
- Support UUID results from constant expression evaluation in
LiteralExpr.createBounded()
Testing:
- Extend iceberg uuid test suite with explicit CAST coverage alongside
existing scalar-subquery predicate tests
- Add positive tests for UUID <-> STRING casts, UUID -> CHAR(36),
CHAR(36)/VARCHAR(36) -> UUID, CAST(NULL AS UUID), and string functions
via explicit UUID -> STRING cast
- Add negative tests for invalid UUID strings, unsupported cast targets
(including UUID -> VARCHAR(36)), and write-path INSERT/CTAS with
explicit casts
Change-Id: I51af55c6e343f7155cae22bf3714e293f31561d5
Assisted-by: Composer 2.5 (Cursor)
Reviewed-on: http://gerrit.cloudera.org:8080/24817
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
be/src/exprs/cast-functions-ir.cc | 34 +++
be/src/exprs/cast-functions.h | 3 +
be/src/exprs/literal.cc | 14 +-
.../java/org/apache/impala/analysis/CastExpr.java | 21 +-
.../org/apache/impala/analysis/LiteralExpr.java | 5 +
.../apache/impala/catalog/UuidCompatibility.java | 2 +-
.../queries/QueryTest/iceberg-uuid-type.test | 264 ++++++++++++++++++++-
7 files changed, 332 insertions(+), 11 deletions(-)
diff --git a/be/src/exprs/cast-functions-ir.cc b/be/src/exprs/cast-functions-ir.cc
index bce7262e6..9b702a056 100644
--- a/be/src/exprs/cast-functions-ir.cc
+++ b/be/src/exprs/cast-functions-ir.cc
@@ -35,6 +35,7 @@
#include "runtime/timestamp-value.h"
#include "runtime/timestamp-value.inline.h"
#include "util/string-parser.h"
+#include "util/uuid-util.h"
using namespace impala;
using namespace impala_udf;
@@ -414,6 +415,39 @@ StringVal CastFunctions::CastToStringVal(FunctionContext* ctx, const StringVal&
return val;
}
+StringVal CastFunctions::CastToUuid(FunctionContext* ctx, const StringVal& val) {
+ if (val.is_null) return StringVal::null();
+
+ const FunctionContext::TypeDesc& type = ctx->GetReturnType();
+ DCHECK_EQ(type.type, FunctionContext::TYPE_UUID);
+ DCHECK_EQ(type.len, UUID_BYTE_LEN);
+ char* dest = reinterpret_cast<char*>(ctx->impl()->AllocateForResults(UUID_BYTE_LEN));
+ if (UNLIKELY(dest == NULL)) {
+ DCHECK(!ctx->impl()->state()->GetQueryStatus().ok());
+ return StringVal::null();
+ }
+ if (!ParseCanonicalUuidStringToBytes(reinterpret_cast<char*>(val.ptr), val.len,
+ reinterpret_cast<uint8_t*>(dest))) {
+ string invalid_val(reinterpret_cast<const char*>(val.ptr), val.len);
+ ctx->SetError(Substitute("String to UUID parse failed. Invalid string val: '$0'",
+ invalid_val).c_str());
+ return StringVal::null();
+ }
+ return StringVal(reinterpret_cast<uint8_t*>(dest), UUID_BYTE_LEN);
+}
+
+StringVal CastFunctions::CastUuidToString(FunctionContext* ctx, const StringVal& val) {
+ if (val.is_null) return StringVal::null();
+ DCHECK_EQ(val.len, UUID_BYTE_LEN);
+ char* dest = reinterpret_cast<char*>(ctx->impl()->AllocateForResults(UUID_STRING_LEN));
+ if (UNLIKELY(dest == NULL)) {
+ DCHECK(!ctx->impl()->state()->GetQueryStatus().ok());
+ return StringVal::null();
+ }
+ UuidBytesToString(val.ptr, dest);
+ return StringVal(reinterpret_cast<uint8_t*>(dest), UUID_STRING_LEN);
+}
+
StringVal CastFunctions::CastToChar(FunctionContext* ctx, const StringVal& val) {
if (val.is_null) return StringVal::null();
diff --git a/be/src/exprs/cast-functions.h b/be/src/exprs/cast-functions.h
index 8342d4d78..1a2d6c200 100644
--- a/be/src/exprs/cast-functions.h
+++ b/be/src/exprs/cast-functions.h
@@ -119,6 +119,9 @@ class CastFunctions {
static StringVal CastToStringVal(FunctionContext* context, const DateVal& val);
static StringVal CastToStringVal(FunctionContext* context, const StringVal& val);
+ static StringVal CastToUuid(FunctionContext* context, const StringVal& val);
+ static StringVal CastUuidToString(FunctionContext* context, const StringVal& val);
+
static StringVal CastToChar(FunctionContext* context, const StringVal& val);
static StringVal CastToVarchar(FunctionContext* context, const StringVal& val);
diff --git a/be/src/exprs/literal.cc b/be/src/exprs/literal.cc
index f765b46c3..2521a906b 100644
--- a/be/src/exprs/literal.cc
+++ b/be/src/exprs/literal.cc
@@ -31,6 +31,7 @@
#include "runtime/runtime-state.h"
#include "runtime/timestamp-parse-util.h"
#include "util/decimal-util.h"
+#include "util/uuid-util.h"
#include "common/names.h"
@@ -112,6 +113,16 @@ Literal::Literal(const TExprNode& node)
value_.Init(str);
break;
}
+ case TYPE_UUID: {
+ DCHECK_EQ(node.node_type, TExprNodeType::STRING_LITERAL);
+ DCHECK(node.__isset.string_literal);
+ const string& str = node.string_literal.value;
+ uint8_t bytes[UUID_BYTE_LEN];
+ bool parsed = ParseCanonicalUuidStringToBytes(str.data(), str.size(), bytes);
+ CHECK(parsed) << "Invalid UUID literal: " << str;
+ value_.Init(string(reinterpret_cast<char*>(bytes), UUID_BYTE_LEN));
+ break;
+ }
case TYPE_DECIMAL: {
DCHECK_EQ(node.node_type, TExprNodeType::DECIMAL_LITERAL);
DCHECK(node.__isset.decimal_literal);
@@ -287,7 +298,7 @@ DoubleVal Literal::GetDoubleValInterpreted(
StringVal Literal::GetStringValInterpreted(
ScalarExprEvaluator* eval, const TupleRow* row) const {
- DCHECK(type_.IsStringType()) << type_;
+ DCHECK(type_.IsStringType() || type_.IsUuidType()) << type_;
StringVal result;
value_.string_val.ToStringVal(&result);
return result;
@@ -420,6 +431,7 @@ Status Literal::GetCodegendComputeFnImpl(LlvmCodeGen* codegen, llvm::Function**
case TYPE_STRING:
case TYPE_VARCHAR:
case TYPE_CHAR:
+ case TYPE_UUID:
v.SetLen(builder.getInt32(value_.string_val.Len()));
v.SetPtr(codegen->GetStringConstant(
&builder, value_.string_val.Ptr(), value_.string_val.Len()));
diff --git a/fe/src/main/java/org/apache/impala/analysis/CastExpr.java b/fe/src/main/java/org/apache/impala/analysis/CastExpr.java
index c2bfff190..1adeaf6d7 100644
--- a/fe/src/main/java/org/apache/impala/analysis/CastExpr.java
+++ b/fe/src/main/java/org/apache/impala/analysis/CastExpr.java
@@ -53,6 +53,9 @@ public class CastExpr extends Expr {
protected final static String CAST_FUNCTION_PREFIX = "castto";
private final static String CAST_TO_CHAR_FN = "impala::CastFunctions::CastToChar";
private final static String CAST_TO_VARCHAR_FN = "impala::CastFunctions::CastToVarchar";
+ private final static String CAST_TO_UUID_FN = "impala::CastFunctions::CastToUuid";
+ private final static String CAST_UUID_TO_STRING_FN =
+ "impala::CastFunctions::CastUuidToString";
// Stores the value of the FORMAT clause.
private final String castFormat_;
@@ -122,7 +125,19 @@ public class CastExpr extends Expr {
if (fromType.isNull()) continue;
for (Type toType : Type.getSupportedTypes()) {
if (toType.isNull()) continue;
- // TODO: Add UUID cast builtin support.
+ // Explicit STRING/VARCHAR/CHAR <-> UUID casts only.
+ if (toType.isUuid() && fromType.isStringType()) {
+ db.addBuiltin(ScalarFunction.createBuiltin(getFnName(Type.UUID),
+ Lists.newArrayList(fromType), false, Type.UUID, CAST_TO_UUID_FN,
+ null, null, true));
+ continue;
+ }
+ if (fromType.isUuid() && toType.isString()) {
+ db.addBuiltin(ScalarFunction.createBuiltin(getFnName(Type.STRING),
+ Lists.newArrayList((Type) Type.UUID), false, Type.STRING,
+ CAST_UUID_TO_STRING_FN, null, null, true));
+ continue;
+ }
if (fromType.isUuid() || toType.isUuid()) continue;
// Disable casting from string to boolean
if (fromType.isStringType() && toType.isBoolean()) continue;
@@ -322,10 +337,12 @@ public class CastExpr extends Expr {
"Unsupported cast to complex type: " + type_.toSql());
}
+ // Skip UUID: no UUID->CHAR builtin is registered, so getFunction() below rejects it.
boolean twoStepCastNeeded =
type_.getPrimitiveType() == PrimitiveType.CHAR &&
children_.get(0).getType().getPrimitiveType() != PrimitiveType.STRING &&
- children_.get(0).getType().getPrimitiveType() != PrimitiveType.CHAR;
+ children_.get(0).getType().getPrimitiveType() != PrimitiveType.CHAR &&
+ !children_.get(0).getType().isUuid();
if (twoStepCastNeeded) {
// Back end functions only exist to cast string types to CHAR, there is not a cast
// for every type since it is redundant with STRING. Casts to go through 2 casts:
diff --git a/fe/src/main/java/org/apache/impala/analysis/LiteralExpr.java b/fe/src/main/java/org/apache/impala/analysis/LiteralExpr.java
index 4dee1ea8f..fd0ba4bc3 100644
--- a/fe/src/main/java/org/apache/impala/analysis/LiteralExpr.java
+++ b/fe/src/main/java/org/apache/impala/analysis/LiteralExpr.java
@@ -286,6 +286,11 @@ public abstract class LiteralExpr extends Expr implements Comparable<LiteralExpr
result = new DateLiteral(val.int_val, val.getString_val());
}
break;
+ case UUID:
+ if (val.isSetString_val()) {
+ result = new StringLiteral(val.getString_val(), Type.UUID, false);
+ }
+ break;
case DATETIME:
return null;
default:
diff --git a/fe/src/main/java/org/apache/impala/catalog/UuidCompatibility.java b/fe/src/main/java/org/apache/impala/catalog/UuidCompatibility.java
index f0f67de81..cc75d25d9 100644
--- a/fe/src/main/java/org/apache/impala/catalog/UuidCompatibility.java
+++ b/fe/src/main/java/org/apache/impala/catalog/UuidCompatibility.java
@@ -19,7 +19,7 @@ package org.apache.impala.catalog;
import static org.apache.impala.catalog.Type.UUID;
-// UUID is incompatible with all other types until predicate/cast support is added.
+// UUID is incompatible with all other types except via explicit CAST.
public class UuidCompatibility implements CompatibilityRule {
@Override
public void apply(PrimitiveType[][] matrix) {
diff --git a/testdata/workloads/functional-query/queries/QueryTest/iceberg-uuid-type.test b/testdata/workloads/functional-query/queries/QueryTest/iceberg-uuid-type.test
index 24798b783..1d1efa006 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/iceberg-uuid-type.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/iceberg-uuid-type.test
@@ -1,7 +1,7 @@
====
---- QUERY
# Iceberg UUID Parquet read-path tests.
-# Casts, LIKE, and aggregates are not yet supported.
+# Aggregates are not yet supported.
DESCRIBE iceberg_uuid_test
---- RESULTS: VERIFY_IS_SUBSET
'id','int','','true'
@@ -76,6 +76,14 @@ SELECT id FROM iceberg_uuid_test WHERE uuid_col = (SELECT uuid_col FROM iceberg_
INT
====
---- QUERY
+# Equality predicate with explicit string-to-UUID cast.
+SELECT id FROM iceberg_uuid_test WHERE uuid_col = CAST('12345678-1234-5678-1234-567812345678' AS UUID)
+---- RESULTS
+1
+---- TYPES
+INT
+====
+---- QUERY
# Inequality predicate on two UUID-typed operands.
SELECT id, name FROM iceberg_uuid_test
WHERE uuid_col != (SELECT uuid_col FROM iceberg_uuid_test WHERE id = 3) AND id = 5
@@ -86,6 +94,16 @@ ORDER BY id
INT,STRING
====
---- QUERY
+# Inequality predicate with explicit string-to-UUID cast.
+SELECT id, name FROM iceberg_uuid_test
+WHERE uuid_col != CAST('00000000-0000-0000-0000-000000000000' AS UUID) AND id = 5
+ORDER BY id
+---- RESULTS
+5,'max'
+---- TYPES
+INT,STRING
+====
+---- QUERY
# IN predicate with a UUID-typed subquery.
SELECT id FROM iceberg_uuid_test
WHERE uuid_col IN (SELECT uuid_col FROM iceberg_uuid_test WHERE id IN (1, 2))
@@ -97,6 +115,19 @@ ORDER BY id
INT
====
---- QUERY
+# IN predicate with explicit string-to-UUID casts.
+SELECT id FROM iceberg_uuid_test
+WHERE uuid_col IN (
+ CAST('12345678-1234-5678-1234-567812345678' AS UUID),
+ CAST('abcdefab-cdef-abcd-efab-cdefabcdefab' AS UUID))
+ORDER BY id
+---- RESULTS
+1
+2
+---- TYPES
+INT
+====
+---- QUERY
# NOT IN predicate with a UUID-typed subquery.
# Rows with NULL uuid_col are excluded (NULL NOT IN (...) is unknown).
SELECT id FROM iceberg_uuid_test
@@ -109,6 +140,20 @@ ORDER BY id
INT
====
---- QUERY
+# NOT IN predicate with explicit string-to-UUID casts.
+# Rows with NULL uuid_col are excluded (NULL NOT IN (...) is unknown).
+SELECT id FROM iceberg_uuid_test
+WHERE uuid_col NOT IN (
+ CAST('12345678-1234-5678-1234-567812345678' AS UUID),
+ CAST('abcdefab-cdef-abcd-efab-cdefabcdefab' AS UUID))
+ORDER BY id
+---- RESULTS
+3
+5
+---- TYPES
+INT
+====
+---- QUERY
# Range comparison predicates on UUID-typed operands.
SELECT id, name FROM iceberg_uuid_test
WHERE uuid_col > (SELECT uuid_col FROM iceberg_uuid_test WHERE id = 3)
@@ -121,6 +166,18 @@ ORDER BY uuid_col DESC
INT,STRING
====
---- QUERY
+# Range comparison predicates with explicit string-to-UUID casts.
+SELECT id, name FROM iceberg_uuid_test
+WHERE uuid_col > CAST('00000000-0000-0000-0000-000000000000' AS UUID)
+ AND uuid_col < CAST('ffffffff-ffff-ffff-ffff-ffffffffffff' AS UUID)
+ORDER BY uuid_col DESC
+---- RESULTS
+2,'bob'
+1,'alice'
+---- TYPES
+INT,STRING
+====
+---- QUERY
# BETWEEN predicate on UUID-typed operands.
SELECT id FROM iceberg_uuid_test
WHERE uuid_col BETWEEN
@@ -134,6 +191,19 @@ ORDER BY id
INT
====
---- QUERY
+# BETWEEN predicate with explicit string-to-UUID casts.
+SELECT id FROM iceberg_uuid_test
+WHERE uuid_col BETWEEN
+ CAST('12345678-1234-5678-1234-567812345678' AS UUID)
+ AND CAST('abcdefab-cdef-abcd-efab-cdefabcdefab' AS UUID)
+ORDER BY id
+---- RESULTS
+1
+2
+---- TYPES
+INT
+====
+---- QUERY
# JOIN on a UUID column exercises UUID equality.
SELECT a.id FROM iceberg_uuid_test a
JOIN iceberg_uuid_test b ON a.uuid_col = b.uuid_col AND b.id = 1
@@ -202,6 +272,16 @@ ORDER BY id
INT
====
---- QUERY
+# IS NOT DISTINCT FROM on equal UUID values (null-safe equality).
+SELECT id FROM iceberg_uuid_test
+WHERE uuid_col IS NOT DISTINCT FROM CAST('12345678-1234-5678-1234-567812345678' AS UUID)
+ORDER BY id
+---- RESULTS
+1
+---- TYPES
+INT
+====
+---- QUERY
# IS DISTINCT FROM on different UUID values.
SELECT id FROM iceberg_uuid_test
WHERE uuid_col IS DISTINCT FROM (SELECT uuid_col FROM iceberg_uuid_test WHERE id = 1) AND id != 1
@@ -215,7 +295,20 @@ ORDER BY id
INT
====
---- QUERY
-# IS NOT DISTINCT FROM treats two NULL UUIDs as equal.
+# IS DISTINCT FROM on different UUID values.
+SELECT id FROM iceberg_uuid_test
+WHERE uuid_col IS DISTINCT FROM CAST('12345678-1234-5678-1234-567812345678' AS UUID) AND id != 1
+ORDER BY id
+---- RESULTS
+2
+3
+4
+5
+---- TYPES
+INT
+====
+---- QUERY
+# IS NOT DISTINCT FROM treats two NULL UUIDs as equal (scalar subquery).
SELECT id FROM iceberg_uuid_test
WHERE uuid_col IS NOT DISTINCT FROM (SELECT uuid_col FROM iceberg_uuid_test WHERE id = 4)
ORDER BY id
@@ -225,6 +318,14 @@ ORDER BY id
INT
====
---- QUERY
+# IS NOT DISTINCT FROM treats two NULL UUIDs as equal (CAST(NULL AS UUID)).
+SELECT id FROM iceberg_uuid_test WHERE uuid_col IS NOT DISTINCT FROM CAST(NULL AS UUID)
+---- RESULTS
+4
+---- TYPES
+INT
+====
+---- QUERY
# IS DISTINCT FROM treats NULL and non-NULL UUIDs as distinct.
SELECT id FROM iceberg_uuid_test
WHERE uuid_col IS DISTINCT FROM (SELECT uuid_col FROM iceberg_uuid_test WHERE id = 1)
@@ -238,6 +339,19 @@ ORDER BY id
INT
====
---- QUERY
+# IS DISTINCT FROM treats NULL and non-NULL UUIDs as distinct.
+SELECT id FROM iceberg_uuid_test
+WHERE uuid_col IS DISTINCT FROM CAST('12345678-1234-5678-1234-567812345678' AS UUID)
+ORDER BY id
+---- RESULTS
+2
+3
+4
+5
+---- TYPES
+INT
+====
+---- QUERY
# JOIN on IS NOT DISTINCT FROM supports null-safe UUID equality.
SELECT a.id FROM iceberg_uuid_test a
JOIN iceberg_uuid_test b ON a.uuid_col IS NOT DISTINCT FROM b.uuid_col AND b.id = 4
@@ -274,16 +388,136 @@ SELECT id FROM iceberg_uuid_test WHERE uuid_col LIKE 'ffffffff%'
left operand of LIKE must be of type STRING
====
---- QUERY
-# Explicit CAST from UUID to STRING is not yet supported.
+# Explicit CAST from UUID to STRING.
SELECT CAST(uuid_col AS STRING) FROM iceberg_uuid_test WHERE id = 1
----- CATCH
-Invalid type cast of uuid_col from UUID to STRING
+---- RESULTS
+'12345678-1234-5678-1234-567812345678'
+---- TYPES
+STRING
====
---- QUERY
-# Explicit CAST from STRING to UUID is not yet supported.
+# Explicit CAST from STRING to UUID.
SELECT CAST('12345678-1234-5678-1234-567812345678' AS UUID)
+---- RESULTS
+'12345678-1234-5678-1234-567812345678'
+---- TYPES
+UUID
+---- HS2_TYPES
+STRING
+====
+---- QUERY
+# CAST from STRING to UUID rejects invalid canonical strings at runtime.
+SELECT CAST('invalid-uuid-format' AS UUID)
+---- CATCH
+String to UUID parse failed. Invalid string val: 'invalid-uuid-format'
+====
+---- QUERY
+# CAST from STRING to UUID rejects strings without dashes.
+SELECT CAST('12345678123456781234567812345678' AS UUID)
+---- CATCH
+String to UUID parse failed. Invalid string val: '12345678123456781234567812345678'
+====
+---- QUERY
+# CAST from STRING to UUID rejects brace-wrapped strings.
+SELECT CAST('{12345678-1234-5678-1234-567812345678}' AS UUID)
+---- CATCH
+String to UUID parse failed. Invalid string val: '{12345678-1234-5678-1234-567812345678}'
+====
+---- QUERY
+# CAST from STRING to UUID rejects leading or trailing whitespace.
+SELECT CAST(' 12345678-1234-5678-1234-567812345678 ' AS UUID)
+---- CATCH
+String to UUID parse failed. Invalid string val: ' 12345678-1234-5678-1234-567812345678 '
+====
+---- QUERY
+# CAST from STRING to UUID rejects empty strings.
+SELECT CAST('' AS UUID)
+---- CATCH
+String to UUID parse failed. Invalid string val: ''
+====
+---- QUERY
+# Uppercase UUID input is accepted and normalized to lowercase on output.
+SELECT CAST(CAST('ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB' AS UUID) AS STRING)
+---- RESULTS
+'abcdefab-cdef-abcd-efab-cdefabcdefab'
+---- TYPES
+STRING
+====
+---- QUERY
+# Non-constant STRING expression preserves UUID values.
+SELECT count(*) FROM iceberg_uuid_test WHERE CAST(CAST(uuid_col AS STRING) AS UUID) = uuid_col AND uuid_col IS NOT NULL
+---- RESULTS
+4
+---- TYPES
+BIGINT
+====
+---- QUERY
+# CAST from CHAR/VARCHAR literals to UUID.
+SELECT CAST(CAST('12345678-1234-5678-1234-567812345678' AS CHAR(36)) AS UUID)
+---- RESULTS
+'12345678-1234-5678-1234-567812345678'
+---- TYPES
+UUID
+---- HS2_TYPES
+STRING
+====
+---- QUERY
+SELECT CAST(CAST('12345678-1234-5678-1234-567812345678' AS VARCHAR(36)) AS UUID)
+---- RESULTS
+'12345678-1234-5678-1234-567812345678'
+---- TYPES
+UUID
+---- HS2_TYPES
+STRING
+====
+---- QUERY
+# CAST from UUID to CHAR is rejected; use CAST(uuid AS STRING) instead.
+SELECT CAST(uuid_col AS CHAR(36)) FROM iceberg_uuid_test WHERE id = 1
---- CATCH
-Invalid type cast of '12345678-1234-5678-1234-567812345678' from STRING to UUID
+Invalid type cast of uuid_col from UUID to CHAR(36)
+====
+---- QUERY
+# CAST from UUID to CHAR(N) for N != 36 is also rejected.
+SELECT CAST(uuid_col AS CHAR(30)) FROM iceberg_uuid_test WHERE id = 1
+---- CATCH
+Invalid type cast of uuid_col from UUID to CHAR(30)
+====
+---- QUERY
+# CAST from UUID to VARCHAR is rejected; use CAST(uuid AS STRING) instead.
+SELECT CAST(uuid_col AS VARCHAR(36)) FROM iceberg_uuid_test WHERE id = 1
+---- CATCH
+Invalid type cast of uuid_col from UUID to VARCHAR(36)
+====
+---- QUERY
+# Fixed-width CHAR output is available via an explicit UUID to STRING cast first.
+SELECT CAST(CAST(uuid_col AS STRING) AS CHAR(36)) FROM iceberg_uuid_test WHERE id = 1
+---- RESULTS
+'12345678-1234-5678-1234-567812345678'
+---- TYPES
+CHAR
+====
+---- QUERY
+# INSERT with an explicit UUID cast is still blocked on the write path.
+INSERT INTO iceberg_uuid_test
+VALUES (10, CAST('12345678-1234-5678-1234-567812345678' AS UUID), 'test')
+---- CATCH
+Impala does not support writing UUID columns
+====
+---- QUERY
+# CTAS producing UUID columns in Parquet is blocked (Iceberg-only type).
+CREATE TABLE uuid_cast_ctas_parquet
+STORED AS PARQUET
+AS SELECT CAST('12345678-1234-5678-1234-567812345678' AS UUID) AS u
+---- CATCH
+UUID type is only supported for Iceberg tables
+====
+---- QUERY
+# CTAS producing UUID columns in Iceberg is blocked on the write path.
+CREATE TABLE uuid_cast_ctas_iceberg
+STORED AS ICEBERG
+AS SELECT CAST('12345678-1234-5678-1234-567812345678' AS UUID) AS u
+---- CATCH
+Impala does not support writing UUID columns
====
---- QUERY
# UUID cannot be cast to non-string types.
@@ -292,6 +526,22 @@ SELECT CAST(uuid_col AS INT) FROM iceberg_uuid_test WHERE id = 1
Invalid type cast of uuid_col from UUID to INT
====
---- QUERY
+# CAST to STRING enables string functions on UUID columns.
+SELECT length(CAST(uuid_col AS STRING)) FROM iceberg_uuid_test WHERE id = 1
+---- RESULTS
+36
+---- TYPES
+INT
+====
+---- QUERY
+# LIKE requires an explicit UUID to STRING cast.
+SELECT id FROM iceberg_uuid_test WHERE CAST(uuid_col AS STRING) LIKE '12345678%'
+---- RESULTS
+1
+---- TYPES
+INT
+====
+---- QUERY
# MIN() is not yet supported on UUID columns.
SELECT MIN(uuid_col) FROM iceberg_uuid_test
---- CATCH