mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-20 00:17:44 +00:00
fix(hana): sort results without derived column alias list
This commit is contained in:
@@ -390,7 +390,8 @@ pub fn build_sorted_query_sql(options: SortedQuerySqlOptions) -> QuerySqlBuildRe
|
||||
&& options.database_type != Some(DatabaseType::DuckDb)
|
||||
&& options.database_type != Some(DatabaseType::Dameng)
|
||||
&& options.database_type != Some(DatabaseType::Oracle)
|
||||
&& options.database_type != Some(DatabaseType::OceanbaseOracle);
|
||||
&& options.database_type != Some(DatabaseType::OceanbaseOracle)
|
||||
&& options.database_type != Some(DatabaseType::SapHana);
|
||||
let sort_alias = if use_derived_column_aliases {
|
||||
aliases
|
||||
.get(options.column_index)
|
||||
@@ -412,7 +413,7 @@ pub fn build_sorted_query_sql(options: SortedQuerySqlOptions) -> QuerySqlBuildRe
|
||||
let use_sort_ordinal = !use_derived_column_aliases
|
||||
&& matches!(
|
||||
options.database_type,
|
||||
Some(DatabaseType::Dameng | DatabaseType::Oracle | DatabaseType::OceanbaseOracle)
|
||||
Some(DatabaseType::Dameng | DatabaseType::Oracle | DatabaseType::OceanbaseOracle | DatabaseType::SapHana)
|
||||
)
|
||||
&& options.result_columns.get(options.column_index).is_some_and(|column| {
|
||||
options.result_columns.iter().filter(|candidate| candidate.eq_ignore_ascii_case(column)).count() > 1
|
||||
@@ -4564,6 +4565,23 @@ WHERE u.id = picked.id;
|
||||
assert_eq!(result.sql.unwrap(), "SELECT * FROM (SELECT * FROM admin LIMIT 100) t ORDER BY `login_name` ASC;");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_saphana_sorted_query_without_derived_column_alias_list() {
|
||||
let result = build_sorted_query_sql(SortedQuerySqlOptions {
|
||||
original_sql: "SELECT ID, NAME, AMOUNT FROM DBX_ISSUE_7274_SORT".to_string(),
|
||||
database_type: Some(DatabaseType::SapHana),
|
||||
result_columns: vec!["ID".to_string(), "NAME".to_string(), "AMOUNT".to_string()],
|
||||
column_index: 1,
|
||||
column: "NAME".to_string(),
|
||||
direction: QuerySortDirection::Asc,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
result.sql.unwrap(),
|
||||
"SELECT * FROM (SELECT ID, NAME, AMOUNT FROM DBX_ISSUE_7274_SORT) t ORDER BY \"NAME\" ASC;"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_sort_preserves_directives_at_outermost_start() {
|
||||
for prefix in [
|
||||
@@ -4706,6 +4724,23 @@ WHERE u.id = picked.id;
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_saphana_sorted_query_by_ordinal_for_duplicate_columns() {
|
||||
let result = build_sorted_query_sql(SortedQuerySqlOptions {
|
||||
original_sql: "SELECT a.id, b.id FROM a JOIN b ON b.a_id = a.id".to_string(),
|
||||
database_type: Some(DatabaseType::SapHana),
|
||||
result_columns: vec!["ID".to_string(), "ID".to_string()],
|
||||
column_index: 1,
|
||||
column: "ID".to_string(),
|
||||
direction: QuerySortDirection::Asc,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
result.sql.unwrap(),
|
||||
"SELECT * FROM (SELECT a.id, b.id FROM a JOIN b ON b.a_id = a.id) t ORDER BY 2 ASC;"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserves_derived_column_aliases_for_generic_jdbc() {
|
||||
let result = build_sorted_query_sql(SortedQuerySqlOptions {
|
||||
|
||||
Reference in New Issue
Block a user