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 {
@@ -50,6 +53,26 @@ public static void visit(AlterExpression action, Consumer<Expression> expression
5053 if (action .getIndex () != null ) {
5154 visit (action .getIndex (), expressions , tables );
5255 }
56+ if (action instanceof AlterExpressionPartition ) {
57+ AlterExpressionPartition partition = (AlterExpressionPartition ) action ;
58+ switch (partition .getOperation ()) {
59+ case ATTACH_PARTITION :
60+ accept (partition .getPartitionTable (), tables );
61+ visit (partition .getPartitionBound (), expressions );
62+ break ;
63+ case DETACH_PARTITION :
64+ accept (partition .getPartitionTable (), tables );
65+ break ;
66+ case EXCHANGE_PARTITION :
67+ accept (partition .getExchangeTable (), tables );
68+ break ;
69+ case PARTITION_BY :
70+ visit (partition .getPartitioning (), expressions );
71+ break ;
72+ default :
73+ break ;
74+ }
75+ }
5376 if (action instanceof AlterExpressionPrimaryKey ) {
5477 AlterExpressionPrimaryKey primaryKey = (AlterExpressionPrimaryKey ) action ;
5578 if (primaryKey .isUsingHash ()) {
@@ -72,6 +95,45 @@ public static void visit(CreateTable table, Consumer<Expression> expressions,
7295 }
7396 accept (table .getTrailingLikeTable (), tables );
7497 accept (table .getPartitionOf (), tables );
98+ visit (table .getPartitioning (), expressions );
99+ visit (table .getPartitionBound (), expressions );
100+ }
101+
102+ /** Visits the active partition key and any subpartition key. Raw bounds remain opaque. */
103+ public static void visit (TablePartitioning partitioning , Consumer <Expression > expressions ) {
104+ if (partitioning == null ) {
105+ return ;
106+ }
107+ if (partitioning .getExpression () != null ) {
108+ accept (partitioning .getExpression (), expressions );
109+ } else if (partitioning .getExpressionList () != null ) {
110+ accept (partitioning .getExpressionList (), expressions );
111+ } else {
112+ accept (partitioning .getColumns (), expressions );
113+ }
114+ visit (partitioning .getSubPartitioning (), expressions );
115+ }
116+
117+ /** Visits expressions belonging to the selected PostgreSQL bound type. */
118+ public static void visit (PartitionBound bound , Consumer <Expression > expressions ) {
119+ if (bound == null || bound .getType () == null ) {
120+ return ;
121+ }
122+ switch (bound .getType ()) {
123+ case RANGE :
124+ accept (bound .getFromExpressions (), expressions );
125+ accept (bound .getToExpressions (), expressions );
126+ break ;
127+ case LIST :
128+ accept (bound .getInExpressions (), expressions );
129+ break ;
130+ case HASH :
131+ accept (bound .getModulus (), expressions );
132+ accept (bound .getRemainder (), expressions );
133+ break ;
134+ default :
135+ break ;
136+ }
75137 }
76138
77139 public static void visit (TableElement element , Consumer <Expression > expressions ,
0 commit comments