Skip to content

Commit dbeb90c

Browse files
authored
Merge pull request #69 from axiomhq/arne/expose-table
Fix: Expose datasets::model::table::*
2 parents 87fb3c2 + 31a8b4f commit dbeb90c

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "axiom-rs"
3-
version = "0.11.0"
3+
version = "0.11.1"
44
authors = ["Arne Bahlo <arne@axiom.co>"]
55
edition = "2018"
66
rust-version = "1.60"

src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub struct Client {
6060

6161
impl Client {
6262
/// Creates a new client. If you want to configure it, use [`Client::builder`].
63-
///
63+
///
6464
/// # Errors
6565
/// If the client can not be created
6666
pub fn new() -> Result<Self> {
@@ -326,7 +326,7 @@ impl Builder {
326326
let mut org_id = self.org_id.unwrap_or_default();
327327
if org_id.is_empty() && env_fallback {
328328
org_id = env::var("AXIOM_ORG_ID").unwrap_or_default();
329-
};
329+
}
330330

331331
// On Cloud you need an Org ID for Personal Tokens.
332332
if url == API_URL && org_id.is_empty() && is_personal_token(&token) {

src/datasets/model.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use std::{
1313
ops::Add,
1414
str::FromStr,
1515
};
16-
use table::Field;
16+
17+
pub use table::*;
1718

1819
use crate::serde::deserialize_null_default;
1920

src/datasets/model/table.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl AsRef<str> for FieldType {
4040
}
4141
}
4242

43+
/// An aggregation.
4344
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
4445
pub struct Agg {
4546
// Name of the aggregation
@@ -267,18 +268,29 @@ impl Table {
267268
&self.columns
268269
}
269270

271+
/// Returns true if the first column is empty.
272+
#[must_use]
273+
pub fn is_empty(&self) -> bool {
274+
self.len() == 0
275+
}
276+
270277
/// Returns the maximum length of the first column
271278
pub fn len(&self) -> usize {
272279
self.columns.first().map(Vec::len).unwrap_or_default()
273280
}
274281

282+
/// Returns a single row from the table.
283+
#[must_use]
275284
pub fn get_row(&self, row: usize) -> Option<Row> {
276285
if self.len() > row {
277286
Some(Row { table: self, row })
278287
} else {
279288
None
280289
}
281290
}
291+
292+
/// Returns an iterator over the rows.
293+
#[must_use]
282294
pub fn iter(&self) -> RowIter {
283295
RowIter {
284296
table: self,
@@ -287,6 +299,14 @@ impl Table {
287299
}
288300
}
289301

302+
impl<'table> IntoIterator for &'table Table {
303+
type Item = Row<'table>;
304+
type IntoIter = RowIter<'table>;
305+
fn into_iter(self) -> Self::IntoIter {
306+
self.iter()
307+
}
308+
}
309+
290310
/// Iterator over the rows of a table.
291311
pub struct RowIter<'table> {
292312
table: &'table Table,
@@ -317,10 +337,10 @@ impl<'table> Iterator for RowIter<'table> {
317337
where
318338
Self: Sized,
319339
{
320-
if self.table.len() > 0 {
321-
self.table.get_row(self.table.len() - 1)
322-
} else {
340+
if self.table.is_empty() {
323341
None
342+
} else {
343+
self.table.get_row(self.table.len() - 1)
324344
}
325345
}
326346
}
@@ -333,6 +353,7 @@ pub struct Row<'table> {
333353

334354
impl<'table> Row<'table> {
335355
/// Returns the value of the row by name
356+
#[must_use]
336357
pub fn get_field(&self, field: &str) -> Option<&JsonValue> {
337358
let mut index = None;
338359

@@ -346,6 +367,7 @@ impl<'table> Row<'table> {
346367
self.get(index?)
347368
}
348369
/// Returns the value of the row.
370+
#[must_use]
349371
pub fn get(&self, column: usize) -> Option<&JsonValue> {
350372
self.table.columns.get(column).and_then(|c| c.get(self.row))
351373
}
@@ -365,6 +387,14 @@ impl<'table> Row<'table> {
365387
}
366388
}
367389

390+
impl<'table> IntoIterator for &Row<'table> {
391+
type Item = Option<&'table JsonValue>;
392+
type IntoIter = FieldIter<'table>;
393+
fn into_iter(self) -> Self::IntoIter {
394+
self.iter()
395+
}
396+
}
397+
368398
/// Iterator over the fields of a row.
369399
pub struct FieldIter<'table> {
370400
table: &'table Table,

0 commit comments

Comments
 (0)