@@ -107,40 +107,40 @@ pub(crate) fn overlap_query(query_params: QueryParams) -> String {
107107
108108 // Always include the required coordinate columns
109109 selected_columns. push ( format ! (
110- "b .`{}` as `{}{}`" ,
111- query_params. columns_2 [ 0 ] , query_params. columns_2 [ 0 ] , query_params. suffixes. 0
110+ "a .`{}` as `{}{}`" ,
111+ query_params. columns_1 [ 0 ] , query_params. columns_1 [ 0 ] , query_params. suffixes. 0
112112 ) ) ;
113113 selected_columns. push ( format ! (
114- "b .`{}` as `{}{}`" ,
115- query_params. columns_2 [ 1 ] , query_params. columns_2 [ 1 ] , query_params. suffixes. 0
114+ "a .`{}` as `{}{}`" ,
115+ query_params. columns_1 [ 1 ] , query_params. columns_1 [ 1 ] , query_params. suffixes. 0
116116 ) ) ;
117117 selected_columns. push ( format ! (
118- "b .`{}` as `{}{}`" ,
119- query_params. columns_2 [ 2 ] , query_params. columns_2 [ 2 ] , query_params. suffixes. 0
118+ "a .`{}` as `{}{}`" ,
119+ query_params. columns_1 [ 2 ] , query_params. columns_1 [ 2 ] , query_params. suffixes. 0
120120 ) ) ;
121121 selected_columns. push ( format ! (
122- "a .`{}` as `{}{}`" ,
123- query_params. columns_1 [ 0 ] , query_params. columns_1 [ 0 ] , query_params. suffixes. 1
122+ "b .`{}` as `{}{}`" ,
123+ query_params. columns_2 [ 0 ] , query_params. columns_2 [ 0 ] , query_params. suffixes. 1
124124 ) ) ;
125125 selected_columns. push ( format ! (
126- "a .`{}` as `{}{}`" ,
127- query_params. columns_1 [ 1 ] , query_params. columns_1 [ 1 ] , query_params. suffixes. 1
126+ "b .`{}` as `{}{}`" ,
127+ query_params. columns_2 [ 1 ] , query_params. columns_2 [ 1 ] , query_params. suffixes. 1
128128 ) ) ;
129129 selected_columns. push ( format ! (
130- "a .`{}` as `{}{}`" ,
131- query_params. columns_1 [ 2 ] , query_params. columns_1 [ 2 ] , query_params. suffixes. 1
130+ "b .`{}` as `{}{}`" ,
131+ query_params. columns_2 [ 2 ] , query_params. columns_2 [ 2 ] , query_params. suffixes. 1
132132 ) ) ;
133133
134134 // Add other columns only if they are in the projected columns
135- for col in & query_params. other_columns_2 {
135+ for col in & query_params. other_columns_1 {
136136 if projected_cols. iter ( ) . any ( |pc| pc. contains ( col) ) {
137137 selected_columns. push ( format ! (
138138 "a.`{}` as `{}{}`" ,
139139 col, col, query_params. suffixes. 0
140140 ) ) ;
141141 }
142142 }
143- for col in & query_params. other_columns_1 {
143+ for col in & query_params. other_columns_2 {
144144 if projected_cols. iter ( ) . any ( |pc| pc. contains ( col) ) {
145145 selected_columns. push ( format ! (
146146 "b.`{}` as `{}{}`" ,
@@ -153,38 +153,38 @@ pub(crate) fn overlap_query(query_params: QueryParams) -> String {
153153 } else {
154154 // Use original logic when no projection is specified
155155 format ! (
156- "b.`{}` as `{}{}`, -- contig
157- b.`{}` as `{}{}`, -- pos_start
158- b.`{}` as `{}{}`, -- pos_end
159- a.`{}` as `{}{}`, -- contig
156+ "a.`{}` as `{}{}`, -- contig
160157 a.`{}` as `{}{}`, -- pos_start
161- a.`{}` as `{}{}` -- pos_end
158+ a.`{}` as `{}{}`, -- pos_end
159+ b.`{}` as `{}{}`, -- contig
160+ b.`{}` as `{}{}`, -- pos_start
161+ b.`{}` as `{}{}` -- pos_end
162162 {}
163163 {}" ,
164- query_params. columns_2[ 0 ] ,
165- query_params. columns_2[ 0 ] ,
166- query_params. suffixes. 0 ,
167- query_params. columns_2[ 1 ] ,
168- query_params. columns_2[ 1 ] ,
169- query_params. suffixes. 0 ,
170- query_params. columns_2[ 2 ] ,
171- query_params. columns_2[ 2 ] ,
172- query_params. suffixes. 0 ,
173164 query_params. columns_1[ 0 ] ,
174165 query_params. columns_1[ 0 ] ,
175- query_params. suffixes. 1 ,
166+ query_params. suffixes. 0 ,
176167 query_params. columns_1[ 1 ] ,
177168 query_params. columns_1[ 1 ] ,
178- query_params. suffixes. 1 ,
169+ query_params. suffixes. 0 ,
179170 query_params. columns_1[ 2 ] ,
180171 query_params. columns_1[ 2 ] ,
172+ query_params. suffixes. 0 ,
173+ query_params. columns_2[ 0 ] ,
174+ query_params. columns_2[ 0 ] ,
175+ query_params. suffixes. 1 ,
176+ query_params. columns_2[ 1 ] ,
177+ query_params. columns_2[ 1 ] ,
178+ query_params. suffixes. 1 ,
179+ query_params. columns_2[ 2 ] ,
180+ query_params. columns_2[ 2 ] ,
181181 query_params. suffixes. 1 ,
182182 if !query_params. other_columns_2. is_empty( ) {
183183 "," . to_string( )
184184 + & format_non_join_tables(
185185 query_params. other_columns_2. clone( ) ,
186- "a " . to_string( ) ,
187- query_params. suffixes. 0 . clone( ) ,
186+ "b " . to_string( ) ,
187+ query_params. suffixes. 1 . clone( ) ,
188188 )
189189 } else {
190190 "" . to_string( )
@@ -193,8 +193,8 @@ pub(crate) fn overlap_query(query_params: QueryParams) -> String {
193193 "," . to_string( )
194194 + & format_non_join_tables(
195195 query_params. other_columns_1. clone( ) ,
196- "b " . to_string( ) ,
197- query_params. suffixes. 1 . clone( ) ,
196+ "a " . to_string( ) ,
197+ query_params. suffixes. 0 . clone( ) ,
198198 )
199199 } else {
200200 "" . to_string( )
@@ -207,7 +207,7 @@ pub(crate) fn overlap_query(query_params: QueryParams) -> String {
207207 SELECT
208208 {}
209209 FROM
210- {} AS a , {} AS b
210+ {} AS b , {} AS a
211211 WHERE
212212 a.`{}`=b.`{}`
213213 AND
0 commit comments