@@ -28,6 +28,8 @@ pub struct ColumnBinding {
28
28
pub column_position : Option < usize > ,
29
29
/// Table index of this `ColumnBinding` in current context
30
30
pub table_index : Option < IndexType > ,
31
+ /// Source table index of this `ColumnBinding` in current context
32
+ pub source_table_index : Option < IndexType > ,
31
33
/// Column name of this `ColumnBinding` in current context
32
34
pub column_name : String ,
33
35
/// Column index of ColumnBinding
@@ -72,6 +74,7 @@ impl ColumnBinding {
72
74
table_name : None ,
73
75
column_position : None ,
74
76
table_index : None ,
77
+ source_table_index : None ,
75
78
column_name : name,
76
79
index,
77
80
data_type,
@@ -83,6 +86,25 @@ impl ColumnBinding {
83
86
pub fn is_dummy ( & self ) -> bool {
84
87
self . index >= DummyColumnType :: Other . type_identifier ( )
85
88
}
89
+
90
+ // Only table_index and column_position are retained to determine whether two columns are the same column of the same table.
91
+ // Avoid situations where aliases and other situations may cause inability to judge
92
+ pub fn as_source ( & self ) -> Option < ColumnBinding > {
93
+ self . source_table_index
94
+ . or ( self . table_index )
95
+ . map ( |table_index| ColumnBinding {
96
+ database_name : None ,
97
+ table_name : None ,
98
+ column_position : self . column_position ,
99
+ table_index : Some ( table_index) ,
100
+ source_table_index : None ,
101
+ column_name : "" . to_string ( ) ,
102
+ index : 0 ,
103
+ data_type : self . data_type . clone ( ) ,
104
+ visibility : self . visibility . clone ( ) ,
105
+ virtual_expr : None ,
106
+ } )
107
+ }
86
108
}
87
109
88
110
impl ColumnIndex for ColumnBinding { }
@@ -96,6 +118,8 @@ pub struct ColumnBindingBuilder {
96
118
pub column_position : Option < usize > ,
97
119
/// Table index of this `ColumnBinding` in current context
98
120
pub table_index : Option < IndexType > ,
121
+ /// Source table index of this `ColumnBinding` in current context
122
+ pub source_table_index : Option < IndexType > ,
99
123
/// Column name of this `ColumnBinding` in current context
100
124
pub column_name : String ,
101
125
/// Column index of ColumnBinding
@@ -120,6 +144,7 @@ impl ColumnBindingBuilder {
120
144
table_name : None ,
121
145
column_position : None ,
122
146
table_index : None ,
147
+ source_table_index : None ,
123
148
column_name,
124
149
index,
125
150
data_type,
@@ -148,6 +173,11 @@ impl ColumnBindingBuilder {
148
173
self
149
174
}
150
175
176
+ pub fn source_table_index ( mut self , index : Option < IndexType > ) -> ColumnBindingBuilder {
177
+ self . source_table_index = index;
178
+ self
179
+ }
180
+
151
181
pub fn virtual_expr ( mut self , virtual_expr : Option < String > ) -> ColumnBindingBuilder {
152
182
self . virtual_expr = virtual_expr;
153
183
self
@@ -159,6 +189,7 @@ impl ColumnBindingBuilder {
159
189
table_name : self . table_name ,
160
190
column_position : self . column_position ,
161
191
table_index : self . table_index ,
192
+ source_table_index : self . source_table_index ,
162
193
column_name : self . column_name ,
163
194
index : self . index ,
164
195
data_type : self . data_type ,
0 commit comments