cyberbeam524 commented on code in PR #27788:
URL: https://github.com/apache/datafusion/pull/27788#discussion_r4735103422


##########
datafusion/sqllogictest/test_files/sql_extension_types.slt:
##########
@@ -192,3 +192,106 @@ INSERT INTO t1 VALUES (NULL);
 
 statement ok
 DROP TABLE t1;
+
+statement ok
+CREATE TABLE t (id UUID);
+
+statement ok
+INSERT INTO t VALUES
+  (CAST(arrow_cast(X'00010203040506070809000102030506', 'FixedSizeBinary(16)') 
AS UUID));
+
+# Verify t.id actually has arrow.uuid metadata
+query T
+SELECT arrow_metadata(id, 'ARROW:extension:name') FROM t;
+----
+arrow.uuid
+
+# UNION and UNION ALL between UUID and a bare Binary literal return a planning 
error
+statement error UNION types cannot be unified for column 'id'
+SELECT id FROM t
+UNION
+SELECT X'00010203040506070809000102030507';
+
+statement error UNION types cannot be unified for column 'id'
+SELECT id FROM t
+UNION ALL
+SELECT X'00010203040506070809000102030507';
+
+# A plain FixedSizeBinary(16) keeps the UUID type, as in 56.0.0
+query ?T
+SELECT id, arrow_metadata(id, 'ARROW:extension:name') FROM (
+  SELECT id FROM t
+  UNION ALL
+  SELECT arrow_cast(X'00010203040506070809000102030507', 'FixedSizeBinary(16)')
+) ORDER BY id;
+----
+00010203040506070809000102030506 arrow.uuid
+00010203040506070809000102030507 arrow.uuid
+
+# The coerced storage type (Utf8View) already carries arrow.json in one input
+query TT
+SELECT j, arrow_metadata(j, 'ARROW:extension:name') FROM (
+  SELECT with_metadata('{"a":1}', 'ARROW:extension:name', 'arrow.json') AS j
+  UNION ALL
+  SELECT with_metadata(arrow_cast('{"b":2}', 'Utf8View'), 
'ARROW:extension:name', 'arrow.json')
+) ORDER BY j;
+----
+{"a":1} arrow.json
+{"b":2} arrow.json
+
+# Extension metadata that differs only in its bytes is not an error (#26810)
+query T
+SELECT arrow_metadata(j, 'ARROW:extension:name') FROM (
+  SELECT with_metadata(with_metadata('{"a":1}', 'ARROW:extension:name', 
'arrow.json'), 'ARROW:extension:metadata', '{}') AS j
+  UNION ALL
+  SELECT with_metadata(with_metadata('{"b":2}', 'ARROW:extension:name', 
'arrow.json'), 'ARROW:extension:metadata', '{ }')
+);
+----
+arrow.json
+arrow.json
+
+# Utf8View never carried arrow.json in any input, so the result would drop it
+statement error UNION types cannot be unified for column 'j'
+SELECT with_metadata('{"a":1}', 'ARROW:extension:name', 'arrow.json') AS j
+UNION ALL
+SELECT arrow_cast('{"b":2}', 'Utf8View');
+
+# Different extension names are an error, as in CASE and COALESCE
+statement error Cannot merge field metadata with differing values of 
'ARROW:extension:name'
+SELECT with_metadata('{"a":1}', 'ARROW:extension:name', 'arrow.json') AS j
+UNION ALL
+SELECT with_metadata('x', 'ARROW:extension:name', 'arrow.opaque');
+
+# A NULL input's metadata does not pick the extension type
+query T
+SELECT arrow_metadata(j, 'ARROW:extension:name') FROM (
+  SELECT with_metadata(NULL, 'ARROW:extension:name', 'arrow.opaque') AS j
+  UNION ALL
+  SELECT with_metadata('x', 'ARROW:extension:name', 'arrow.json')
+) WHERE j IS NOT NULL;
+----
+arrow.json
+
+# NULL branch does not force incompatibility and preserves extension metadata
+query T
+SELECT arrow_metadata(id, 'ARROW:extension:name') FROM (
+  SELECT id FROM t
+  UNION ALL
+  SELECT NULL
+) LIMIT 1;
+----
+arrow.uuid
+
+# UNION between two UUID columns works and preserves arrow.uuid
+query T
+SELECT arrow_metadata(id, 'ARROW:extension:name') FROM (
+  SELECT id FROM t
+  UNION
+  SELECT CAST(arrow_cast(X'00010203040506070809000102030507', 
'FixedSizeBinary(16)') AS UUID)
+);
+----
+arrow.uuid
+arrow.uuid
+
+statement ok
+DROP TABLE t;

Review Comment:
   Added the trailing newline!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to