Skip to content

Commit

Permalink
Update query to order by split id when offset is provided (#4047)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalesh0406 authored Oct 29, 2023
1 parent 02b480a commit 9c0a73d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions quickwit/quickwit-metastore/src/metastore/postgresql_metastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use quickwit_proto::metastore::{
};
use quickwit_proto::types::IndexUid;
use sea_query::{
all, any, Asterisk, Cond, Expr, Func, PostgresQueryBuilder, Query, SelectStatement,
all, any, Asterisk, Cond, Expr, Func, Order, PostgresQueryBuilder, Query, SelectStatement,
};
use sea_query_binder::SqlxBinder;
use sqlx::migrate::Migrator;
Expand Down Expand Up @@ -341,7 +341,8 @@ fn append_query_filters(sql: &mut SelectStatement, query: &ListSplitsQuery) {
}

if let Some(offset) = query.offset {
sql.offset(offset as u64);
sql.order_by(Splits::SplitId, Order::Asc)
.offset(offset as u64);
}
}

Expand Down Expand Up @@ -1770,6 +1771,19 @@ mod tests {
r#"SELECT * FROM "splits" WHERE "index_uid" = '{index_uid}' AND NOT ($$tag-2$$ = ANY(tags))"#
)
);

let mut select_statement = Query::select();
let sql = select_statement.column(Asterisk).from(Splits::Table);

let query = ListSplitsQuery::for_index(index_uid.clone()).with_offset(4);
append_query_filters(sql, &query);

assert_eq!(
sql.to_string(PostgresQueryBuilder),
format!(
r#"SELECT * FROM "splits" WHERE "index_uid" = '{index_uid}' ORDER BY "split_id" ASC OFFSET 4"#
)
);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl PgIndex {
#[allow(dead_code)]
pub enum Splits {
Table,
SplitId,
SplitState,
TimeRangeStart,
TimeRangeEnd,
Expand Down

0 comments on commit 9c0a73d

Please sign in to comment.