@@ -45,20 +45,20 @@ use datafusion_expr::utils::expr_to_columns;
45
45
use datafusion_expr:: {
46
46
cast, col, Analyze , CreateCatalog , CreateCatalogSchema ,
47
47
CreateExternalTable as PlanCreateExternalTable , CreateFunction , CreateFunctionBody ,
48
- CreateMemoryTable , CreateView , DescribeTable , DmlStatement , DropCatalogSchema ,
49
- DropFunction , DropTable , DropView , EmptyRelation , Explain , Expr , ExprSchemable ,
50
- Filter , LogicalPlan , LogicalPlanBuilder , OperateFunctionArg , PlanType , Prepare ,
51
- SetVariable , Statement as PlanStatement , ToStringifiedPlan , TransactionAccessMode ,
52
- TransactionConclusion , TransactionEnd , TransactionIsolationLevel , TransactionStart ,
53
- Volatility , WriteOp ,
48
+ CreateIndex as PlanCreateIndex , CreateMemoryTable , CreateView , DescribeTable ,
49
+ DmlStatement , DropCatalogSchema , DropFunction , DropTable , DropView , EmptyRelation ,
50
+ Explain , Expr , ExprSchemable , Filter , LogicalPlan , LogicalPlanBuilder ,
51
+ OperateFunctionArg , PlanType , Prepare , SetVariable , Statement as PlanStatement ,
52
+ ToStringifiedPlan , TransactionAccessMode , TransactionConclusion , TransactionEnd ,
53
+ TransactionIsolationLevel , TransactionStart , Volatility , WriteOp ,
54
54
} ;
55
55
use sqlparser:: ast;
56
56
use sqlparser:: ast:: {
57
- Assignment , AssignmentTarget , ColumnDef , CreateTable , CreateTableOptions , Delete ,
58
- DescribeAlias , Expr as SQLExpr , FromTable , Ident , Insert , ObjectName , ObjectType ,
59
- OneOrManyWithParens , Query , SchemaName , SetExpr , ShowCreateObject ,
60
- ShowStatementFilter , Statement , TableConstraint , TableFactor , TableWithJoins ,
61
- TransactionMode , UnaryOperator , Value ,
57
+ Assignment , AssignmentTarget , ColumnDef , CreateIndex , CreateTable ,
58
+ CreateTableOptions , Delete , DescribeAlias , Expr as SQLExpr , FromTable , Ident , Insert ,
59
+ ObjectName , ObjectType , OneOrManyWithParens , Query , SchemaName , SetExpr ,
60
+ ShowCreateObject , ShowStatementFilter , Statement , TableConstraint , TableFactor ,
61
+ TableWithJoins , TransactionMode , UnaryOperator , Value ,
62
62
} ;
63
63
use sqlparser:: parser:: ParserError :: ParserError ;
64
64
@@ -769,6 +769,42 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
769
769
exec_err ! ( "Function name not provided" )
770
770
}
771
771
}
772
+ Statement :: CreateIndex ( CreateIndex {
773
+ name,
774
+ table_name,
775
+ using,
776
+ columns,
777
+ unique,
778
+ if_not_exists,
779
+ ..
780
+ } ) => {
781
+ let name: Option < String > = name. as_ref ( ) . map ( object_name_to_string) ;
782
+ let table = self . object_name_to_table_reference ( table_name) ?;
783
+ let table_schema = self
784
+ . context_provider
785
+ . get_table_source ( table. clone ( ) ) ?
786
+ . schema ( )
787
+ . to_dfschema_ref ( ) ?;
788
+ let using: Option < String > = using. as_ref ( ) . map ( ident_to_string) ;
789
+ let columns = self . order_by_to_sort_expr (
790
+ columns,
791
+ & table_schema,
792
+ planner_context,
793
+ false ,
794
+ None ,
795
+ ) ?;
796
+ Ok ( LogicalPlan :: Ddl ( DdlStatement :: CreateIndex (
797
+ PlanCreateIndex {
798
+ name,
799
+ table,
800
+ using,
801
+ columns,
802
+ unique,
803
+ if_not_exists,
804
+ schema : DFSchemaRef :: new ( DFSchema :: empty ( ) ) ,
805
+ } ,
806
+ ) ) )
807
+ }
772
808
_ => {
773
809
not_impl_err ! ( "Unsupported SQL statement: {sql:?}" )
774
810
}
0 commit comments