diff --git a/aerospike-core/src/client.rs b/aerospike-core/src/client.rs index 66ac4232..a417d429 100644 --- a/aerospike-core/src/client.rs +++ b/aerospike-core/src/client.rs @@ -1960,7 +1960,7 @@ impl Client { } let task_id: u64 = rand::random(); - let scan = statement.filters.is_none(); + let scan = statement.filter().is_none(); let mut last_err: Option = None; for node in &nodes { @@ -2034,7 +2034,7 @@ impl Client { } let task_id: u64 = rand::random(); - let scan = statement.filters.is_none(); + let scan = statement.filter().is_none(); let mut last_err: Option = None; for node in &nodes { diff --git a/aerospike-core/src/commands/buffer.rs b/aerospike-core/src/commands/buffer.rs index be149731..15992d57 100644 --- a/aerospike-core/src/commands/buffer.rs +++ b/aerospike-core/src/commands/buffer.rs @@ -1443,7 +1443,7 @@ impl Buffer { node_partitions: Option<&NodePartitions>, execute_where: Option<&[u8]>, ) -> Result<()> { - let filter = statement.filters.as_ref().map(|filters| &filters[0]); + let filter = statement.filter(); let is_background = direction.is_background(); let supports_ops_ext = node.version().supports_query_ops_projection_ext(); let records_per_second = direction.records_per_second(); diff --git a/aerospike-core/src/commands/query_command.rs b/aerospike-core/src/commands/query_command.rs index 54589a09..03191114 100644 --- a/aerospike-core/src/commands/query_command.rs +++ b/aerospike-core/src/commands/query_command.rs @@ -97,7 +97,7 @@ impl Command for QueryCommand<'_> { fn command_type(&self) -> crate::metrics::CommandType { // A statement with secondary-index filters is a query; otherwise a scan. - if self.statement.filters.is_some() { + if self.statement.filter().is_some() { crate::metrics::CommandType::Query } else { crate::metrics::CommandType::Scan diff --git a/aerospike-core/src/query/statement.rs b/aerospike-core/src/query/statement.rs index 21c951e2..84226754 100644 --- a/aerospike-core/src/query/statement.rs +++ b/aerospike-core/src/query/statement.rs @@ -117,6 +117,12 @@ impl Statement { } } + /// The secondary-index filter this statement queries by, or `None` for a + /// scan. An empty `filters` list is a scan, the same as `None`. + pub(crate) fn filter(&self) -> Option<&Filter> { + self.filters.as_ref().and_then(|filters| filters.first()) + } + /// Set Lua aggregation function parameters. pub fn set_aggregate_function( &mut self, diff --git a/tests/src/query.rs b/tests/src/query.rs index bcf20f9b..37652dbf 100644 --- a/tests/src/query.rs +++ b/tests/src/query.rs @@ -178,6 +178,32 @@ async fn query_single_consumer() { client.close().await.unwrap(); } +#[aerospike_macro::test] +async fn query_empty_filter_list_scans() { + let client = common::client().await; + let namespace = common::namespace(); + let set_name = create_test_set(&client, 20).await; + let qpolicy = QueryPolicy::default(); + + let mut statement = Statement::new(namespace, &set_name, Bins::All); + statement.filters = Some(vec![]); + let rs = client + .query(&qpolicy, PartitionFilter::all(), statement) + .await + .unwrap(); + let mut count = 0; + let mut rs = rs.into_stream(); + while let Some(res) = rs.next().await { + match res { + Ok(_) => count += 1, + Err(err) => panic!("{:?}", err), + } + } + assert_eq!(count, 20); + + client.close().await.unwrap(); +} + #[aerospike_macro::test] async fn query_single_consumer_with_cursor() { let client = common::client().await;