1515import net .sf .jsqlparser .schema .Table ;
1616import net .sf .jsqlparser .statement .LikeClause ;
1717import net .sf .jsqlparser .statement .alter .AlterExpression ;
18+ import net .sf .jsqlparser .statement .alter .AlterExpressionPartition ;
1819import net .sf .jsqlparser .statement .alter .AlterExpressionPrimaryKey ;
1920import net .sf .jsqlparser .statement .create .index .CreateIndex ;
2021import net .sf .jsqlparser .statement .create .table .CheckConstraint ;
2627import net .sf .jsqlparser .statement .create .table .ForeignKeyIndex ;
2728import net .sf .jsqlparser .statement .create .table .Index ;
2829import net .sf .jsqlparser .statement .create .table .TableElement ;
30+ import net .sf .jsqlparser .statement .create .table .TablePartitioning ;
31+ import net .sf .jsqlparser .statement .create .table .PartitionBound ;
2932
3033/** Traverses structured table definitions without interpreting legacy raw column options. */
3134public final class TableDefinitionTraversal {
@@ -54,6 +57,26 @@ public static void visit(AlterExpression action, Consumer<Expression> expression
5457 if (action .getIndex () != null ) {
5558 visit (action .getIndex (), expressions , tables );
5659 }
60+ if (action instanceof AlterExpressionPartition ) {
61+ AlterExpressionPartition partition = (AlterExpressionPartition ) action ;
62+ switch (partition .getOperation ()) {
63+ case ATTACH_PARTITION :
64+ accept (partition .getPartitionTable (), tables );
65+ visit (partition .getPartitionBound (), expressions );
66+ break ;
67+ case DETACH_PARTITION :
68+ accept (partition .getPartitionTable (), tables );
69+ break ;
70+ case EXCHANGE_PARTITION :
71+ accept (partition .getExchangeTable (), tables );
72+ break ;
73+ case PARTITION_BY :
74+ visit (partition .getPartitioning (), expressions );
75+ break ;
76+ default :
77+ break ;
78+ }
79+ }
5780 if (action instanceof AlterExpressionPrimaryKey ) {
5881 AlterExpressionPrimaryKey primaryKey = (AlterExpressionPrimaryKey ) action ;
5982 if (primaryKey .isUsingHash ()) {
@@ -76,6 +99,30 @@ public static void visit(CreateTable table, Consumer<Expression> expressions,
7699 }
77100 accept (table .getTrailingLikeTable (), tables );
78101 accept (table .getPartitionOf (), tables );
102+ visit (table .getPartitioning (), expressions );
103+ visit (table .getPartitionBound (), expressions );
104+ }
105+
106+ /** Visits the active partition key and any subpartition key. Raw bounds remain opaque. */
107+ public static void visit (TablePartitioning partitioning , Consumer <Expression > expressions ) {
108+ if (partitioning == null ) {
109+ return ;
110+ }
111+ if (partitioning .getExpression () != null ) {
112+ accept (partitioning .getExpression (), expressions );
113+ } else if (partitioning .getExpressionList () != null ) {
114+ accept (partitioning .getExpressionList (), expressions );
115+ } else {
116+ accept (partitioning .getColumns (), expressions );
117+ }
118+ visit (partitioning .getSubPartitioning (), expressions );
119+ }
120+
121+ /** Visits expressions belonging to the selected PostgreSQL bound type. */
122+ public static void visit (PartitionBound bound , Consumer <Expression > expressions ) {
123+ if (bound != null ) {
124+ bound .visitExpressions (expressions );
125+ }
79126 }
80127
81128 public static void visit (TableElement element , Consumer <Expression > expressions ,
0 commit comments