@@ -202,6 +202,51 @@ async fn main() -> Result<()> {
202202}
203203```
204204
205+ #### Example: Supporting the UUID Type
206+
207+ ``` rust
208+ # use std :: sync :: Arc ;
209+ # use arrow :: datatypes :: {FieldRef , TimeUnit };
210+ # use datafusion :: error :: Result ;
211+ # use datafusion :: prelude :: * ;
212+ # use datafusion :: execution :: SessionStateBuilder ;
213+ use datafusion_expr :: planner :: TypePlanner ;
214+ # use sqlparser :: ast;
215+
216+ #[derive(Debug )]
217+ struct MyTypePlanner ;
218+
219+ impl TypePlanner for MyTypePlanner {
220+ fn plan_type_field (& self , sql_type : & ast :: DataType ) -> Result <Option <FieldRef >> {
221+ match sql_type {
222+ sqlparser :: ast :: DataType :: Uuid => Ok (Some (Arc :: new (
223+ Field :: new ("" , DataType :: FixedSizeBinary (16 ), true ). with_metadata (
224+ [(" ARROW:extension:name" . to_string (), " arrow.uuid" . to_string ())]
225+ . into (),
226+ ),
227+ ))),
228+ _ => Ok (self
229+ . plan_type (sql_type )?
230+ . map (| data_type | data_type . into_nullable_field_ref ())),
231+ }
232+ }
233+ }
234+
235+ #[tokio:: main]
236+ async fn main () -> Result <()> {
237+ let state = SessionStateBuilder :: new ()
238+ . with_default_features ()
239+ . with_type_planner (Arc :: new (MyTypePlanner ))
240+ . build ();
241+
242+ let ctx = SessionContext :: new_with_state (state );
243+
244+ // Now UUID type is recognized
245+ ctx . sql (" CREATE TABLE idx (uuid UUID)" ). await ? ;
246+ Ok (())
247+ }
248+ ```
249+
205250For more details, see the [ TypePlanner API documentation] .
206251
207252### RelationPlanner: Custom FROM Clause Elements
0 commit comments