fix(jdbc): support Caché data grid pagination

Closes #3423
This commit is contained in:
t8y2 committed 2026-08-13 20:50:07 +08:00
1 parent 65cd4cfe28
commit fc6c5d4aa6
14 files changed
+160 -1

No files matched your search

+16
View File
@@ -3093,6 +3093,22 @@ mod tests {
}
}
#[test]
fn iris_data_grid_count_queries_the_table_without_wrapping_top_sql() {
assert_eq!(
build_data_grid_count_sql(DataGridCountSqlOptions {
database_type: Some(DatabaseType::Iris),
identifier_quote: Some("\"".to_string()),
catalog: None,
database: None,
schema: Some("SS".to_string()),
table_name: "SS_User".to_string(),
where_input: Some("SSUSR_IsActive = 'Y'".to_string()),
}),
"SELECT COUNT(*) AS cnt FROM \"SS\".\"SS_User\" WHERE (SSUSR_IsActive = 'Y')"
);
}
#[test]
fn postgres_keyless_update_preserves_jsonb_array_elements() {
let endpoints =
+23
View File
@@ -885,6 +885,7 @@ pub struct QueryExecutionOptions {
pub max_rows: Option<usize>,
pub fetch_size: Option<usize>,
pub page_size: Option<usize>,
pub row_offset: Option<usize>,
pub max_result_bytes: Option<usize>,
/// Result columns that must stay exact because clients use them as stable
/// row identifiers when fetching full large-cell values on demand.
@@ -975,6 +976,9 @@ pub fn agent_execute_query_params(
if let Some(fetch_size) = options.fetch_size {
params["fetchSize"] = serde_json::json!(agent_protocol_row_count(fetch_size));
}
if let Some(row_offset) = options.row_offset {
params["rowOffset"] = serde_json::json!(agent_protocol_row_offset(row_offset));
}
if let Some(timeout_secs) = options.timeout_secs {
params["timeoutSecs"] = serde_json::json!(timeout_secs);
}
@@ -1001,6 +1005,9 @@ pub fn agent_execute_query_page_params(
if let Some(fetch_size) = options.fetch_size {
params["fetchSize"] = serde_json::json!(agent_protocol_row_count(fetch_size));
}
if let Some(row_offset) = options.row_offset {
params["rowOffset"] = serde_json::json!(agent_protocol_row_offset(row_offset));
}
if let Some(timeout_secs) = options.timeout_secs {
params["timeoutSecs"] = serde_json::json!(timeout_secs);
}
@@ -1018,6 +1025,10 @@ fn agent_protocol_row_count(value: usize) -> usize {
value.clamp(1, AGENT_PROTOCOL_MAX_ROWS)
}
fn agent_protocol_row_offset(value: usize) -> usize {
value.min(AGENT_PROTOCOL_MAX_ROWS)
}
pub fn agent_close_query_session_params(session_id: &str) -> serde_json::Value {
serde_json::json!({
"sessionId": session_id,
@@ -2100,6 +2111,9 @@ fn external_driver_query_params(
if let Some(fetch_size) = options.fetch_size {
params["fetchSize"] = serde_json::json!(fetch_size);
}
if let Some(row_offset) = options.row_offset {
params["rowOffset"] = serde_json::json!(agent_protocol_row_offset(row_offset));
}
if let Some(timeout_secs) = options.timeout_secs {
params["timeoutSecs"] = serde_json::json!(timeout_secs);
}
@@ -6800,6 +6814,7 @@ for line in sys.stdin:
&QueryExecutionOptions {
max_rows: Some(500),
fetch_size: Some(250),
row_offset: Some(100),
timeout_secs: Some(600),
..Default::default()
},
@@ -6811,6 +6826,7 @@ for line in sys.stdin:
assert_eq!(params["schema"], "app");
assert_eq!(params["maxRows"], 500);
assert_eq!(params["fetchSize"], 250);
assert_eq!(params["rowOffset"], 100);
assert_eq!(params["timeoutSecs"], 600);
}
@@ -6823,6 +6839,7 @@ for line in sys.stdin:
QueryExecutionOptions {
max_rows: Some(500),
fetch_size: Some(250),
row_offset: Some(100),
timeout_secs: Some(600),
..Default::default()
},
@@ -6833,6 +6850,7 @@ for line in sys.stdin:
assert_eq!(params["schema"], "app");
assert_eq!(params["maxRows"], 500);
assert_eq!(params["fetchSize"], 250);
assert_eq!(params["rowOffset"], 100);
assert_eq!(params["timeoutSecs"], 600);
}
@@ -6988,6 +7006,7 @@ for line in sys.stdin:
assert!(params.get("schema").is_none());
assert_eq!(params["maxRows"], MAX_ROWS);
assert!(params.get("fetchSize").is_none());
assert!(params.get("rowOffset").is_none());
assert!(params.get("timeoutSecs").is_none());
}
@@ -7000,6 +7019,7 @@ for line in sys.stdin:
QueryExecutionOptions {
page_size: Some(500),
fetch_size: Some(250),
row_offset: Some(100),
timeout_secs: Some(600),
..Default::default()
},
@@ -7010,6 +7030,7 @@ for line in sys.stdin:
assert_eq!(params["schema"], "app");
assert_eq!(params["pageSize"], 500);
assert_eq!(params["fetchSize"], 250);
assert_eq!(params["rowOffset"], 100);
assert_eq!(params["timeoutSecs"], 600);
assert_eq!(params["maxRows"], MAX_ROWS);
}
@@ -7025,6 +7046,7 @@ for line in sys.stdin:
page_size: Some(oversized),
fetch_size: Some(oversized),
max_rows: Some(oversized),
row_offset: Some(oversized),
..Default::default()
},
);
@@ -7032,6 +7054,7 @@ for line in sys.stdin:
assert_eq!(params["pageSize"], AGENT_PROTOCOL_MAX_ROWS);
assert_eq!(params["fetchSize"], AGENT_PROTOCOL_MAX_ROWS);
assert_eq!(params["maxRows"], AGENT_PROTOCOL_MAX_ROWS);
assert_eq!(params["rowOffset"], AGENT_PROTOCOL_MAX_ROWS);
assert_eq!(agent_fetch_query_page_params("session-1", oversized)["pageSize"], AGENT_PROTOCOL_MAX_ROWS);
}
@@ -225,7 +225,11 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
match table_pagination_strategy(database_type) {
TablePaginationStrategy::IrisTop => {
format!("SELECT TOP {limit} {select_columns} FROM {table_alias}{where_clause}{order}")
if options.use_driver_row_offset {
format!("SELECT {select_columns} FROM {table_alias}{where_clause}{order}")
} else {
format!("SELECT TOP {limit} {select_columns} FROM {table_alias}{where_clause}{order}")
}
}
TablePaginationStrategy::InformixFirst => {
let row_limit = informix_row_limit_clause(limit, options.offset.unwrap_or(0));
@@ -654,6 +658,7 @@ mod tests {
order_by: None,
limit: Some(10),
offset: None,
use_driver_row_offset: false,
where_input: None,
include_row_id: false,
}
+19
View File
@@ -621,6 +621,25 @@ fn builds_table_data_where_and_schema_queries() {
}),
"SELECT TOP 100 * FROM \"Ens\".\"AlarmResponse\""
);
assert_eq!(
build_table_data_select_sql(TableDataSelectSqlOptions {
database_type: Some(DatabaseType::Iris),
schema: Some("Ens".to_string()),
table_name: "AlarmResponse".to_string(),
table_type: None,
primary_keys: Vec::new(),
columns: Vec::new(),
fallback_order_columns: Vec::new(),
order_by: Some("\"ID\" ASC".to_string()),
limit: Some(100),
offset: Some(100),
use_driver_row_offset: true,
where_input: Some("Status = 'Open'".to_string()),
include_row_id: false,
..Default::default()
}),
"SELECT * FROM \"Ens\".\"AlarmResponse\" WHERE (Status = 'Open') ORDER BY \"ID\" ASC"
);
assert_eq!(
build_table_data_select_sql(TableDataSelectSqlOptions {
database_type: Some(DatabaseType::Iotdb),
+5
View File
@@ -61,6 +61,11 @@ pub struct TableDataSelectSqlOptions {
pub limit: Option<usize>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub offset: Option<usize>,
/// The JDBC driver advances the ResultSet before collecting the page.
/// This keeps database-specific identifier rules while avoiding SQL
/// pagination syntax that the selected driver does not support.
#[serde(default)]
pub use_driver_row_offset: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub where_input: Option<String>,
#[serde(default)]