Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table API query/get all rewrite #84

Merged
merged 27 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b988c1e
initial draft
MindFlavor Nov 16, 2020
6103908
expanded example
MindFlavor Nov 16, 2020
8aa5d38
fixed examples
MindFlavor Nov 16, 2020
64f4d8c
cleanup
MindFlavor Nov 16, 2020
a92db54
simplified begin query
MindFlavor Nov 16, 2020
f40fd7b
serde for ContinuationToken
MindFlavor Nov 16, 2020
2e08390
Update sdk/storage/src/table/cloud_table.rs
MindFlavor Nov 16, 2020
5057640
Update sdk/storage/src/table/continuation_token.rs
MindFlavor Nov 16, 2020
7e08e23
applied suggestions
MindFlavor Nov 16, 2020
e4cb6fe
Update sdk/storage/src/table/query_result.rs
MindFlavor Nov 16, 2020
1e4b0a6
Merge branch 'issue/83/table_paging' of github.com:Azure/azure-sdk-fo…
MindFlavor Nov 16, 2020
df83eac
continuationtoken rewrite (but not working due to auto encoding)
MindFlavor Nov 17, 2020
6deb45c
fixed path bug
MindFlavor Nov 17, 2020
88d4689
fixed explaination
MindFlavor Nov 17, 2020
012b93b
NextRowKey optional as per https://docs.microsoft.com/en-us/rest/api/…
MindFlavor Nov 18, 2020
da63295
little performance enhancement (no useless string allocations)
MindFlavor Nov 18, 2020
87ef3fa
simplified code with map
MindFlavor Nov 18, 2020
b2136ab
removed dummy URL
MindFlavor Nov 22, 2020
162c09c
Fixed typo in previous_partition_key(&self)
MindFlavor Nov 22, 2020
cf6bdb3
fixed typo in previous_row_key(&self)
MindFlavor Nov 22, 2020
b7a4765
Merge branch 'master' into issue/83/table_paging
MindFlavor Nov 23, 2020
0883860
merged from master
MindFlavor Nov 23, 2020
a917181
fixed merge conflicts
MindFlavor Nov 23, 2020
88c4c75
Renamed QueryResult in PaginatedResponse
MindFlavor Nov 23, 2020
7f653e4
replaced tuple with PerformRequestResponse
MindFlavor Nov 23, 2020
dc112cd
rustfmt
MindFlavor Nov 24, 2020
5bf5c96
check_status_extract_headers_and_body as member function of PerformRe…
MindFlavor Nov 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [
"sdk/*",
"services/mgmt/*",
#"services/mgmt/*",
]
1 change: 1 addition & 0 deletions sdk/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
newline_style = "Unix"
edition = "2018"
22 changes: 9 additions & 13 deletions sdk/storage/examples/cloud_table.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[macro_use]
extern crate serde_derive;

use azure_storage::table::{Batch, CloudTable, Continuation, TableClient};
use azure_storage::table::{Batch, CloudTable, TableClient};
use std::error::Error;
use std::mem;

Expand Down Expand Up @@ -51,20 +51,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
.await?;
println!("entity(value): {:?}", entity);

let mut cont = Continuation::start();
while let Some(entities) = cloud_table
.execute_query::<MyEntity>(None, &mut cont)
.await?
{
println!("segment: {:?}", entities.first());
let mut response = cloud_table.begin_get_all::<MyEntity>().await?;
while let Some(continuation_token) = response.continuation_token {
response = cloud_table.continue_execution(continuation_token).await?;
println!("segment: {:?}", response.entities.first());
}

let mut cont = Continuation::start();
while let Some(entities) = cloud_table
.execute_query::<serde_json::Value>(None, &mut cont)
.await?
{
println!("segment(value): {:?}", entities.first());
let mut response = cloud_table.begin_get_all::<serde_json::Value>().await?;
while let Some(continuation_token) = response.continuation_token {
response = cloud_table.continue_execution(continuation_token).await?;
println!("segment: {:?}", response.entities.first());
}

let mut batch = Batch::new("big2".to_owned());
Expand Down
9 changes: 5 additions & 4 deletions sdk/storage/examples/copy_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ async fn main() -> Result<(), Box<dyn Error>> {

let mut count: u32 = 0;

let mut stream = Box::pin(from_table.stream_query::<MyEntity>(None));
let mut stream = Box::pin(from_table.stream_get_all::<MyEntity>());

while let Some(Ok(entities)) = stream.next().await {
println!("segemnt len: {}", entities.len());
for entity in entities {
while let Some(query_result) = stream.next().await {
let query_result = query_result?;
println!("segemnt len: {}", query_result.entities.len());
for entity in query_result.entities {
count += 1;
println!("before {:?}", entity);
let entity = to_table.insert_entity(entity).await?;
Expand Down
27 changes: 26 additions & 1 deletion sdk/storage/examples/tables.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use azure_storage::table::TableClient;
use azure_storage::table::*;
use serde::Deserialize;
use std::error::Error;

#[derive(Debug, Clone, Deserialize)]
struct MyEntity {
my_value: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// First we retrieve the account name and master key from environment variables.
Expand All @@ -16,5 +22,24 @@ async fn main() -> Result<(), Box<dyn Error>> {
for ref table in tables {
println!("{}", table);
}

let table_client = CloudTable::new(client, "example");

let response = table_client.begin_get_all::<MyEntity>().await?;
println!("{:?}", response.entities);
println!("{:?}", response.continuation_token);

let mut response = table_client.begin_query::<MyEntity>("$top=2").await?;
println!("{:?}", response.entities);
println!("{:?}", response.continuation_token);

while let Some(continuation_token) = response.continuation_token {
println!("we have more data!");

response = table_client.continue_execution(continuation_token).await?;
println!("{:?}", response.entities);
println!("{:?}", response.continuation_token);
}

Ok(())
}
24 changes: 10 additions & 14 deletions sdk/storage/src/table/batch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{entity_path, TableEntity};
use serde::Serialize;
use serde_json;

const BATCH_MAX_SIZE: usize = 100;

Expand Down Expand Up @@ -40,9 +39,9 @@ pub enum BatchOperation {
}

impl BatchOperation {
fn into_payload(&self, uri_prefix: &str, table: &str, partition_key: &str, body: &mut String) {
fn into_payload(self, uri_prefix: &str, table: &str, partition_key: &str, body: &mut String) {
// todo: consider using the cloud_table request builder to generate payloads
match *self {
match self {
BatchOperation::Insert { ref payload, .. } => {
body.push_str("POST ");
body.push_str(uri_prefix);
Expand All @@ -51,7 +50,7 @@ impl BatchOperation {
body.push_str("Accept: application/json;odata=nometadata\n");
body.push_str("Content-Type: application/json\n\n");
body.push_str(&payload);
body.push_str("\n");
body.push('\n');
}

BatchOperation::Update {
Expand All @@ -73,7 +72,7 @@ impl BatchOperation {
body.push_str("If-Match: *\n\n");
}
body.push_str(&payload);
body.push_str("\n");
body.push('\n');
}

BatchOperation::Delete {
Expand All @@ -93,7 +92,7 @@ impl BatchOperation {
} else {
body.push_str("If-Match: *\n");
}
body.push_str("\n");
body.push('\n');
}
}
}
Expand All @@ -118,7 +117,7 @@ impl Batch {
/// Create a new changeset for the given partition key
pub fn new(partition_key: String) -> Batch {
Batch {
partition_key: partition_key,
partition_key,
items: vec![],
}
}
Expand Down Expand Up @@ -186,9 +185,9 @@ impl Batch {
T: Serialize,
{
self.add_operation(BatchOperation::Update {
row_key: row_key.to_owned(),
row_key,
payload: serde_json::to_string(data)?,
etag: etag,
etag,
})
}

Expand All @@ -210,10 +209,7 @@ impl Batch {
row_key: String,
etag: Option<String>,
) -> Result<&mut Self, BatchError> {
self.add_operation(BatchOperation::Delete {
row_key: row_key.to_owned(),
etag: etag,
})
self.add_operation(BatchOperation::Delete { row_key, etag })
}

/// Add a delete operation using a TableEntitiy
Expand All @@ -238,7 +234,7 @@ impl Batch {
payload.push_str("Content-Type: application/http\n");
payload.push_str("Content-Transfer-Encoding: binary\n\n");
item.into_payload(uri_prefix, table, &self.partition_key, &mut payload);
payload.push_str("\n");
payload.push('\n');
}

payload.push_str("--changeset_8a28b620-b4bb-458c-a177-0959fb14c977--\n");
Expand Down
Loading