Skip to content

Commit

Permalink
Cleanup error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
davisp committed Oct 4, 2024
1 parent 906d507 commit 905e5c5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 101 deletions.
27 changes: 7 additions & 20 deletions tiledb/api/examples/multi_range_subarray_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use tiledb::array::{
SchemaData, TileOrder,
};
use tiledb::context::Context;
use tiledb::error::Error as TileDBError;
use tiledb::query_arrow::{QueryBuilder, QueryLayout, QueryStatus, QueryType};
use tiledb::query_arrow::{QueryBuilder, QueryLayout, QueryType};
use tiledb::Result as TileDBResult;
use tiledb::{Datatype, Factory};

Expand Down Expand Up @@ -68,20 +67,12 @@ fn main() -> TileDBResult<()> {
.add_range("rows", &[4, 4])
.add_range("cols", &[1, 4])
.end_subarray()
.build()
.map_err(|e| TileDBError::Other(format!("{e}")))?;
.build()?;

let status = query
.submit()
.map_err(|e| TileDBError::Other(format!("{e}")))?;
let status = query.submit()?;
assert!(status.is_complete());

if !matches!(status, QueryStatus::Completed) {
return Err(TileDBError::Other("Make this better.".to_string()));
}

let buffers = query
.buffers()
.map_err(|e| TileDBError::Other(format!("{e}")))?;
let buffers = query.buffers()?;

let rows = buffers.get::<aa::Int32Array>("rows").unwrap();
let cols = buffers.get::<aa::Int32Array>("cols").unwrap();
Expand Down Expand Up @@ -142,13 +133,9 @@ fn write_array(ctx: &Context) -> TileDBResult<()> {
.start_fields()
.field_with_buffer("a", data)
.end_fields()
.build()
.map_err(|e| TileDBError::Other(format!("{e}")))?;
.build()?;

let (_, _) = query
.submit()
.and_then(|_| query.finalize())
.map_err(|e| TileDBError::Other(format!("{e}")))?;
let (_, _) = query.submit().and_then(|_| query.finalize())?;

Ok(())
}
27 changes: 6 additions & 21 deletions tiledb/api/examples/query_condition_dense_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use tiledb::array::{
Array, ArrayType, AttributeBuilder, DimensionBuilder, DomainBuilder,
SchemaBuilder,
};
use tiledb::error::Error as TileDBError;
use tiledb::query::conditions::QueryConditionExpr as QC;
use tiledb::query_arrow::{QueryBuilder, QueryLayout, QueryType};
use tiledb::{Context, Datatype, Result as TileDBResult};
Expand Down Expand Up @@ -86,22 +85,12 @@ fn read_array(ctx: &Context, qc: Option<QC>) -> TileDBResult<()> {
query
};

let mut query = query
.build()
.map_err(|e| TileDBError::Other(format!("{e}")))?;
let mut query = query.build()?;

let status = query
.submit()
.map_err(|e| TileDBError::Other(format!("{e}")))?;

if !status.is_complete() {
return Err(TileDBError::Other("Query incomplete.".to_string()));
}

let buffers = query.buffers().map_err(|e| {
TileDBError::Other(format!("Error getting buffers: {e}"))
})?;
let status = query.submit()?;
assert!(status.is_complete());

let buffers = query.buffers()?;
let index = buffers.get::<aa::Int32Array>("index").unwrap();
let a = buffers.get::<aa::Int32Array>("a").unwrap();
let b = buffers.get::<aa::LargeStringArray>("b").unwrap();
Expand Down Expand Up @@ -230,13 +219,9 @@ fn write_array(ctx: &Context) -> TileDBResult<()> {
.start_subarray()
.add_range("index", &[0i32, NUM_ELEMS - 1])
.end_subarray()
.build()
.map_err(|e| TileDBError::Other(format!("{e}")))?;
.build()?;

query
.submit()
.and_then(|_| query.finalize())
.map_err(|e| TileDBError::Other(format!("{e}")))?;
query.submit().and_then(|_| query.finalize())?;

Ok(())
}
7 changes: 1 addition & 6 deletions tiledb/api/examples/query_condition_sparse_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use tiledb::array::{
Array, ArrayType, AttributeBuilder, CellOrder, DimensionBuilder,
DomainBuilder, SchemaBuilder,
};
use tiledb::error::Error as TileDBError;
use tiledb::query::conditions::QueryConditionExpr as QC;
use tiledb::query_arrow::{QueryBuilder, QueryLayout, QueryType};
use tiledb::{Context, Datatype, Result as TileDBResult};
Expand Down Expand Up @@ -88,13 +87,9 @@ fn read_array(ctx: &Context, qc: Option<QC>) -> TileDBResult<()> {

let mut query = query.build()?;
let status = query.submit()?;

if !status.is_complete() {
return Err(TileDBError::Other("Query did not complete.".to_string()));
}
assert!(status.is_complete());

let buffers = query.buffers()?;

let index = buffers.get::<aa::Int32Array>("index").unwrap();
let a = buffers.get::<aa::Int32Array>("a").unwrap();
let b = buffers.get::<aa::LargeStringArray>("b").unwrap();
Expand Down
36 changes: 10 additions & 26 deletions tiledb/api/examples/quickstart_dense_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use tiledb::array::{
DomainBuilder, Mode as ArrayMode, SchemaBuilder,
};
use tiledb::context::Context;
use tiledb::error::Error as TileDBError;
use tiledb::query_arrow::{QueryBuilder, QueryLayout, QueryStatus, QueryType};
use tiledb::query_arrow::{QueryBuilder, QueryLayout, QueryType};
use tiledb::Datatype;
use tiledb::Result as TileDBResult;

Expand Down Expand Up @@ -95,18 +94,11 @@ fn write_array() -> TileDBResult<()> {
.start_fields()
.field_with_buffer(QUICKSTART_ATTRIBUTE_NAME, data)
.end_fields()
.build()
// TODO: Make this not suck
.map_err(|e| TileDBError::Other(format!("{}", e)))?;

let status = query
.submit()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;
if matches!(status, QueryStatus::Completed) {
return Ok(());
} else {
return Err(TileDBError::Other("Something better here.".to_string()));
}
.build()?;

query.submit().and_then(|_| query.finalize())?;

Ok(())
}

/// Query back a slice of our array and print the results to stdout.
Expand All @@ -133,20 +125,12 @@ fn read_array() -> TileDBResult<()> {
.add_range("rows", &[1i32, 2])
.add_range("columns", &[2i32, 4])
.end_subarray()
.build()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;

let status = query
.submit()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;
.build()?;

if !matches!(status, QueryStatus::Completed) {
return Err(TileDBError::Other("Make this better.".to_string()));
}
let status = query.submit()?;
assert!(status.is_complete());

let buffers = query
.buffers()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;
let buffers = query.buffers()?;
let rows = buffers.get::<Int32Array>("rows").unwrap();
let cols = buffers.get::<Int32Array>("columns").unwrap();
let attrs = buffers
Expand Down
35 changes: 7 additions & 28 deletions tiledb/api/examples/quickstart_sparse_string_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use tiledb::array::{
SchemaData, TileOrder,
};
use tiledb::context::Context;
use tiledb::error::Error as TileDBError;
use tiledb::query_arrow::{QueryBuilder, QueryLayout, QueryStatus, QueryType};
use tiledb::query_arrow::{QueryBuilder, QueryLayout, QueryType};
use tiledb::Result as TileDBResult;
use tiledb::{Datatype, Factory};

Expand Down Expand Up @@ -44,21 +43,12 @@ fn main() -> TileDBResult<()> {
.add_range("rows", &["a", "c"])
.add_range("cols", &[2, 4])
.end_subarray()
.build()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;
.build()?;

let status = query
.submit()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;

if !matches!(status, QueryStatus::Completed) {
return Err(TileDBError::Other("Make this better.".to_string()));
}

let buffers = query
.buffers()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;
let status = query.submit()?;
assert!(status.is_complete());

let buffers = query.buffers()?;
let rows = buffers.get::<aa::LargeStringArray>("rows").unwrap();
let cols = buffers.get::<aa::Int32Array>("cols").unwrap();
let attr = buffers.get::<aa::Int32Array>("a").unwrap();
Expand Down Expand Up @@ -120,20 +110,9 @@ fn write_array(ctx: &Context) -> TileDBResult<()> {
.field_with_buffer("cols", col_data)
.field_with_buffer("a", a_data)
.end_fields()
.build()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;

let status = query
.submit()
.map_err(|e| TileDBError::Other(format!("{}", e)))?;

if !matches!(status, QueryStatus::Completed) {
return Err(TileDBError::Other("Make this better.".to_string()));
}
.build()?;

let (_, _) = query
.finalize()
.map_err(|e| TileDBError::Other(format!("{e}")))?;
query.submit().and_then(|_| query.finalize())?;

Ok(())
}

0 comments on commit 905e5c5

Please sign in to comment.