sdf-jkl commented on code in PR #26822:
URL: https://github.com/apache/datafusion/pull/26822#discussion_r4788310720


##########
datafusion/sql/src/planner.rs:
##########
@@ -673,6 +673,21 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             SQLDataType::JSON => Ok(Arc::new(
                 Field::new("", DataType::Utf8, 
true).with_extension_type(Json::default()),
             )),
+            // sqlparser has no VARIANT keyword, so it parses as a custom type
+            SQLDataType::Custom(name, modifiers)

Review Comment:
   Instead of waiting for a new sqlparser-rs release I think we could add it 
here right away and use it in SLTs
   
   I will open a PR upstream too



##########
datafusion/sqllogictest/test_files/sql_extension_types.slt:
##########
@@ -111,6 +111,53 @@ NULL
 statement ok
 DROP TABLE test_json;
 
+#######
+# Parquet Variant Extension Type
+#######
+
+# VARIANT maps to unshredded storage with non-nullable metadata and value 
fields
+statement ok
+CREATE TABLE test_variant (v VARIANT);
+
+query TTT
+DESCRIBE test_variant;
+----
+v VARIANT YES
+
+statement ok
+INSERT INTO test_variant VALUES (NULL);
+
+query ?T
+SELECT v, arrow_metadata(v, 'ARROW:extension:name') FROM test_variant;
+----
+NULL arrow.parquet.variant
+
+statement ok
+DROP TABLE test_variant;
+
+# SQL has no Variant constructor, so attach the extension metadata to an 
encoded {"a": 1}
+statement ok
+CREATE TABLE test_variant AS
+SELECT
+    with_metadata(
+        named_struct('metadata', X'1101000161', 'value', X'02010000020C01'),
+        'ARROW:extension:name', 'arrow.parquet.variant',
+        'ARROW:extension:metadata', ''
+    ) AS v;

Review Comment:
   Thanks @tschwarzinger 



##########
datafusion/common/src/types/canonical_extensions/parquet_variant.rs:
##########
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for 
additional information regarding copyright ownership
+// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) 
under one or more contributor license agreements
+
+use crate::Result;
+use crate::types::extension::DFExtensionType;
+use arrow::datatypes::DataType;
+use arrow_schema::extension::{ExtensionType, VariantType};
+use std::borrow::Cow;
+
+/// Defines the extension type logic for the canonical `arrow.parquet.variant` 
extension type.
+///
+/// See [`DFExtensionType`] for information on DataFusion's extension type 
mechanism. See also
+/// [`VariantType`] for the implementation of arrow-rs, which this type uses 
internally.
+///
+/// 
<https://arrow.apache.org/docs/format/CanonicalExtensions.html#parquet-variant>
+#[derive(Debug, Clone)]
+pub struct DFVariant {

Review Comment:
   I don't think other ext types do that 🤷 



-- 
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