fix(iris): skip schema execution context
This commit is contained in:
1 parent
e3fec0f5d9
commit
72ababd2b8
3 files changed
+38
-1
No files matched your search
@@ -28,6 +28,24 @@ async fn connection_mysql_query_dialect(state: &AppState, connection_id: &str) -
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn connection_database_type_for_pool_key(state: &AppState, pool_key: &str) -> Option<DatabaseType> {
|
||||||
|
let configs = state.configs.read().await;
|
||||||
|
configs
|
||||||
|
.iter()
|
||||||
|
.filter(|(connection_id, _)| {
|
||||||
|
pool_key.strip_prefix(connection_id.as_str()).is_some_and(|rest| rest.is_empty() || rest.starts_with(':'))
|
||||||
|
})
|
||||||
|
.max_by_key(|(connection_id, _)| connection_id.len())
|
||||||
|
.map(|(_, config)| config.db_type)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn schema_for_execution_context(db_type: Option<DatabaseType>, schema: Option<&str>) -> Option<&str> {
|
||||||
|
match db_type {
|
||||||
|
Some(DatabaseType::Iris) => None,
|
||||||
|
_ => schema,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct QueryExecutionOptions {
|
pub struct QueryExecutionOptions {
|
||||||
pub max_rows: Option<usize>,
|
pub max_rows: Option<usize>,
|
||||||
@@ -478,6 +496,7 @@ pub async fn do_execute(
|
|||||||
.get(pool_key)
|
.get(pool_key)
|
||||||
.map(|config| config.attached_databases.iter().map(|database| database.name.clone()).collect::<Vec<_>>())
|
.map(|config| config.attached_databases.iter().map(|database| database.name.clone()).collect::<Vec<_>>())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
let pool_db_type = connection_database_type_for_pool_key(state, pool_key).await;
|
||||||
let connections = state.connections.read().await;
|
let connections = state.connections.read().await;
|
||||||
let pool = connections.get(pool_key).ok_or("Connection not found")?;
|
let pool = connections.get(pool_key).ok_or("Connection not found")?;
|
||||||
|
|
||||||
@@ -586,7 +605,7 @@ pub async fn do_execute(
|
|||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
let sql = sql.to_string();
|
let sql = sql.to_string();
|
||||||
let database = database.map(|s| s.to_string());
|
let database = database.map(|s| s.to_string());
|
||||||
let schema = schema.map(|s| s.to_string());
|
let schema = schema_for_execution_context(pool_db_type, schema).map(|s| s.to_string());
|
||||||
let max_rows = options.max_rows;
|
let max_rows = options.max_rows;
|
||||||
let rpc_timeout = query_timeout;
|
let rpc_timeout = query_timeout;
|
||||||
drop(connections);
|
drop(connections);
|
||||||
@@ -1238,6 +1257,8 @@ async fn exec_tx_explicit_inner(
|
|||||||
) -> Result<db::QueryResult, String> {
|
) -> Result<db::QueryResult, String> {
|
||||||
let conns = state.connections.read().await;
|
let conns = state.connections.read().await;
|
||||||
if let Some(crate::connection::PoolKind::Agent(client)) = conns.get(pool_key) {
|
if let Some(crate::connection::PoolKind::Agent(client)) = conns.get(pool_key) {
|
||||||
|
let db_type = connection_database_type_for_pool_key(state, pool_key).await;
|
||||||
|
let schema = schema_for_execution_context(db_type, schema);
|
||||||
let mut client = client.lock().await;
|
let mut client = client.lock().await;
|
||||||
let result: db::QueryResult = client.execute_transaction(database, statements, schema).await?;
|
let result: db::QueryResult = client.execute_transaction(database, statements, schema).await?;
|
||||||
return Ok(db::QueryResult { execution_time_ms: start.elapsed().as_millis(), ..result });
|
return Ok(db::QueryResult { execution_time_ms: start.elapsed().as_millis(), ..result });
|
||||||
@@ -1626,6 +1647,13 @@ mod tests {
|
|||||||
assert_eq!(params["timeoutSecs"], 600);
|
assert_eq!(params["timeoutSecs"], 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn iris_execution_context_omits_schema() {
|
||||||
|
assert_eq!(schema_for_execution_context(Some(DatabaseType::Iris), Some("SQLUser")), None);
|
||||||
|
assert_eq!(schema_for_execution_context(Some(DatabaseType::Oracle), Some("APP")), Some("APP"));
|
||||||
|
assert_eq!(schema_for_execution_context(None, Some("APP")), Some("APP"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn agent_execute_query_params_default_to_safety_row_limit() {
|
fn agent_execute_query_params_default_to_safety_row_limit() {
|
||||||
let params = agent_execute_query_params("SELECT * FROM events", None, None, QueryExecutionOptions::default());
|
let params = agent_execute_query_params("SELECT * FROM events", None, None, QueryExecutionOptions::default());
|
||||||
|
|||||||
@@ -44,9 +44,11 @@ public final class DbxJdbcPlugin {
|
|||||||
private static final int MAX_ROWS = 10_000;
|
private static final int MAX_ROWS = 10_000;
|
||||||
private static final JdbcDriverQuirks DEFAULT_QUIRKS = new JdbcDriverQuirks(false, false);
|
private static final JdbcDriverQuirks DEFAULT_QUIRKS = new JdbcDriverQuirks(false, false);
|
||||||
private static final JdbcDriverQuirks YASHAN_QUIRKS = new JdbcDriverQuirks(true, true);
|
private static final JdbcDriverQuirks YASHAN_QUIRKS = new JdbcDriverQuirks(true, true);
|
||||||
|
private static final JdbcDriverQuirks IRIS_QUIRKS = new JdbcDriverQuirks(true, false);
|
||||||
private static final JdbcDriverQuirks ORACLE_QUIRKS = new JdbcDriverQuirks(false, true);
|
private static final JdbcDriverQuirks ORACLE_QUIRKS = new JdbcDriverQuirks(false, true);
|
||||||
private static final List<JdbcDriverQuirkRule> DRIVER_QUIRK_RULES = List.of(
|
private static final List<JdbcDriverQuirkRule> DRIVER_QUIRK_RULES = List.of(
|
||||||
new JdbcDriverQuirkRule("jdbc:yasdb:", YASHAN_QUIRKS),
|
new JdbcDriverQuirkRule("jdbc:yasdb:", YASHAN_QUIRKS),
|
||||||
|
new JdbcDriverQuirkRule("jdbc:iris:", IRIS_QUIRKS),
|
||||||
new JdbcDriverQuirkRule("jdbc:oracle:", ORACLE_QUIRKS),
|
new JdbcDriverQuirkRule("jdbc:oracle:", ORACLE_QUIRKS),
|
||||||
new JdbcDriverQuirkRule("jdbc:dm:", ORACLE_QUIRKS)
|
new JdbcDriverQuirkRule("jdbc:dm:", ORACLE_QUIRKS)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -173,6 +173,11 @@ final class DbxJdbcPluginTest {
|
|||||||
"connection_string": "jdbc:yasdb://172.26.128.159:20027/yasdb"
|
"connection_string": "jdbc:yasdb://172.26.128.159:20027/yasdb"
|
||||||
}
|
}
|
||||||
""");
|
""");
|
||||||
|
JsonNode iris = MAPPER.readTree("""
|
||||||
|
{
|
||||||
|
"connection_string": "jdbc:IRIS://127.0.0.1:1972/USER"
|
||||||
|
}
|
||||||
|
""");
|
||||||
JsonNode h2 = MAPPER.readTree("""
|
JsonNode h2 = MAPPER.readTree("""
|
||||||
{
|
{
|
||||||
"connection_string": "jdbc:h2:mem:dbx_quirks"
|
"connection_string": "jdbc:h2:mem:dbx_quirks"
|
||||||
@@ -181,6 +186,8 @@ final class DbxJdbcPluginTest {
|
|||||||
|
|
||||||
assertEquals(true, DbxJdbcPlugin.driverQuirks(yashan).skipExecutionContext());
|
assertEquals(true, DbxJdbcPlugin.driverQuirks(yashan).skipExecutionContext());
|
||||||
assertEquals(true, DbxJdbcPlugin.driverQuirks(yashan).useOracleMetadata());
|
assertEquals(true, DbxJdbcPlugin.driverQuirks(yashan).useOracleMetadata());
|
||||||
|
assertEquals(true, DbxJdbcPlugin.driverQuirks(iris).skipExecutionContext());
|
||||||
|
assertEquals(false, DbxJdbcPlugin.driverQuirks(iris).useOracleMetadata());
|
||||||
assertEquals(false, DbxJdbcPlugin.driverQuirks(h2).skipExecutionContext());
|
assertEquals(false, DbxJdbcPlugin.driverQuirks(h2).skipExecutionContext());
|
||||||
assertEquals(false, DbxJdbcPlugin.driverQuirks(h2).useOracleMetadata());
|
assertEquals(false, DbxJdbcPlugin.driverQuirks(h2).useOracleMetadata());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user