fixing problems
This commit is contained in:
@@ -815,10 +815,11 @@ async fn qualified_visible_table(
|
||||
profile_name: &str,
|
||||
table_name: &str,
|
||||
) -> Result<String, Status> {
|
||||
let resolved = sqlx::query_as::<_, (String, String)>(
|
||||
r#"SELECT owner.name, definition.table_name
|
||||
let resolved = sqlx::query_as::<_, (i64, String, String, Option<serde_json::Value>)>(
|
||||
r#"SELECT definition.schema_id, owner.name, definition.table_name, binding.storage
|
||||
FROM table_definitions definition
|
||||
JOIN schemas owner ON owner.id = definition.schema_id
|
||||
LEFT JOIN table_storage_bindings binding ON binding.table_definition_id = definition.id
|
||||
WHERE definition.canonical_table_name = $2
|
||||
AND definition.deleted = FALSE
|
||||
AND (owner.name = $1 OR definition.is_global = TRUE)
|
||||
@@ -831,8 +832,15 @@ async fn qualified_visible_table(
|
||||
.await
|
||||
.map_err(|error| Status::internal(format!("Table storage lookup failed: {error}")))?
|
||||
.ok_or_else(|| Status::not_found(format!("Table '{table_name}' was not found")))?;
|
||||
let (storage_schema, stored_table_name) = resolved;
|
||||
Ok(qualify_profile_table(&storage_schema, &stored_table_name))
|
||||
let (schema_id, storage_schema, stored_table_name, storage) = resolved;
|
||||
match storage {
|
||||
Some(storage) => {
|
||||
let storage = serde_json::from_value::<common::catalog_storage::StorageSpec>(storage)
|
||||
.map_err(|error| Status::internal(format!("Invalid table storage binding: {error}")))?;
|
||||
Ok(storage.read_sql(schema_id))
|
||||
}
|
||||
None => Ok(qualify_profile_table(&storage_schema, &stored_table_name)),
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_request(req: SearchRequest) -> Result<NormalizedSearchRequest, Status> {
|
||||
@@ -1289,6 +1297,7 @@ async fn resolve_order_column(
|
||||
.or_else(|| {
|
||||
(is_system_column(&requested_key)
|
||||
&& !is_internal_column(&requested_key)
|
||||
&& requested_key != common::system_column::ACCOUNT_REFERENCE_COLUMN
|
||||
&& !physical_to_display.contains_key(&requested_key))
|
||||
.then(|| requested_key.clone())
|
||||
})
|
||||
@@ -1299,37 +1308,6 @@ async fn resolve_order_column(
|
||||
))
|
||||
})?;
|
||||
|
||||
let physical_column = sqlx::query_scalar::<_, String>(
|
||||
r#"
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = (
|
||||
SELECT owner.name
|
||||
FROM table_definitions definition
|
||||
JOIN schemas owner ON owner.id = definition.schema_id
|
||||
WHERE definition.table_name = $2
|
||||
AND definition.deleted = FALSE
|
||||
AND (owner.name = $1 OR definition.is_global = TRUE)
|
||||
ORDER BY definition.is_global ASC
|
||||
LIMIT 1
|
||||
)
|
||||
AND table_name = $2
|
||||
AND LOWER(column_name) = LOWER($3)
|
||||
"#,
|
||||
)
|
||||
.bind(profile_name)
|
||||
.bind(table_name)
|
||||
.bind(&physical_column)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(format!("Order column lookup failed: {}", e)))?;
|
||||
let Some(physical_column) = physical_column else {
|
||||
return Err(Status::invalid_argument(format!(
|
||||
"Order column '{}' was not found in table '{}.{}'",
|
||||
requested_column, profile_name, table_name
|
||||
)));
|
||||
};
|
||||
|
||||
Ok(ResolvedOrderColumn::Column(physical_column))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user