1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use crateResult;
use Array;
use ;
use DataType;
use Debug;
use Arc;
/// A cheaply cloneable pointer to a [`DFExtensionType`].
pub type DFExtensionTypeRef = ;
/// Represents an implementation of a DataFusion extension type, including the storage [`DataType`].
/// While, in general, an extension type can support several different storage types, a specific
/// instance of it is always locked into just one exact storage type and metadata pairing.
///
/// This trait allows users to customize the behavior of DataFusion for certain types. Having this
/// ability is necessary because extension types affect how columns should be treated by the query
/// engine. This effect includes which operations are possible on a column and what are the expected
/// results from these operations. The extension type mechanism allows users to define how these
/// operations apply to a particular extension type.
///
/// For example, adding two values of [`Int64`](arrow::datatypes::DataType::Int64) is a sensible
/// thing to do. However, if the same column is annotated with an extension type like `custom.id`,
/// the correct interpretation of a column changes. Adding together two `custom.id` values, even
/// though they are stored as integers, may no longer make sense.
///
/// Note that DataFusion's extension type support is still young and therefore might not cover all
/// relevant use cases. Currently, the following operations can be customized:
/// - Pretty-printing values in record batches
///
/// # Relation to Arrow's [`ExtensionType`](arrow_schema::extension::ExtensionType)
///
/// The purpose of Arrow's [`ExtensionType`](arrow_schema::extension::ExtensionType) trait, for the
/// time being, is to allow reading and writing extension type metadata in a type-safe manner. The
/// trait does not provide any customization options. Therefore, downstream users (such as
/// DataFusion) have the flexibility to implement the extension type mechanism according to their
/// needs. [`DFExtensionType`] is DataFusion's implementation of this extension type mechanism.
///
/// Furthermore, the current trait in arrow-rs is not dyn-compatible, which we need for implementing
/// extension type registries. In the future, the two implementations may increasingly converge.
///
/// Another difference is that [`DFExtensionType`] represents a fully resolved extension type that
/// has a fixed storage type (i.e., [`DataType`]). This is different from arrow-rs, which only
/// stores the extension type's metadata. For example, an instance of DataFusion's JSON extension
/// type fixes one of the three possible storage types: [`DataType::Utf8`],
/// [`DataType::LargeUtf8`], or [`DataType::Utf8View`]. This fixed storaga type is returned in
/// [`DFExtensionType::storage_type`]. This is not possible in arrow-rs' extension type instances.
/// This is the reason why we have different types in DataFusion that usually delegate the metadata
/// processing to the underlying arrow-rs extension type instance
/// (e.g., [`DFJson`](crate::types::DFJson) instead of [`Json`](arrow_schema::extension::Json)).
///
/// # Examples
///
/// Examples for using the extension type machinery can be found in the DataFusion examples
/// directory.