Skip to content

Commit

Permalink
query result - remove exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
py committed Nov 26, 2024
1 parent 138675f commit a2d0d6b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 65 deletions.
57 changes: 25 additions & 32 deletions crates/configuration/src/version1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,24 @@ pub async fn introspect(
None, // Expiration (None for non-expiring)
"my-provider", // Provider name
);

// Configure AWS SDK with explicit credentials
let config = Config::builder()
.region(aws_config::Region::new(region.to_string()))
.credentials_provider(credentials)
.build();

// To use localhost url
// let config = aws_config::defaults(aws_config::BehaviorVersion::latest())
// .test_credentials()
// .region(aws_config::Region::new("us-west-2"))
// // DynamoDB run locally uses port 8000 by default.
// .endpoint_url("http://localhost:8085")
// .load()
// .await;

// Configure AWS SDK with explicit credentials
let config = Config::builder()
.region(aws_config::Region::new(region.to_string()))
.credentials_provider(credentials)
.build();
// let dynamodb_local_config = aws_sdk_dynamodb::config::Builder::from(&config).build();

let client = aws_sdk_dynamodb::Client::from_conf(config);
// let endpoint = Endpoint::immutable("http://localhost:8054".parse().unwrap());
// let client = aws_sdk_dynamodb::Client::from_conf(
// Builder::from(&config)
// .endpoint_resolver(endpoint)
// .region(Region::new("us-west-2"))
// .build()
// );
// let client = aws_sdk_dynamodb::Client::new(&config);
let tables_result = client.list_tables().send().await;
// dbg!(&tables_result);
let tables = tables_result.map_err(|op| {
Expand All @@ -141,9 +136,6 @@ pub async fn introspect(
// dbg!(&tables);
let table_names = tables.table_names.unwrap_or_default();
let mut scalars_list: BTreeSet<ScalarTypeName> = BTreeSet::new();
// let foo = aws_sdk_dynamodb::Config::builder().build();
// // let bar = aws_config::credential_process::CredentialProcessProvider::new(command);
// let shared_config = aws_sdk_dynamodb::
let mut tables_info: BTreeMap<CollectionName, metadata::TableInfo> = BTreeMap::new();
for table_name in table_names {
let table_result = client.describe_table().table_name(table_name).send().await;
Expand Down Expand Up @@ -183,7 +175,7 @@ pub async fn introspect(
}

//get non key attributes
let mut row_1 = client
let mut result = client
.execute_statement()
.statement(
format!(
Expand All @@ -194,23 +186,24 @@ pub async fn introspect(
.set_parameters(None)
.set_limit(Some(20))
.send()
.await;

let result = match row_1
{
Ok(resp) => {
resp.items.unwrap()
}
Err(e) => {
println!("Got an error querying table:");
println!("{}", e);
exit(1) //fixme
}
};
.await
.unwrap();

// let result = match row_1
// {
// Ok(resp) => {
// resp.items.unwrap()
// }
// Err(e) => {
// println!("Got an error querying table:");
// println!("{}", e);
// exit(1) //fixme
// }
// };
// dbg!(&result);

// let row = result.first().unwrap();
for item in result.iter() {
for item in result.items.unwrap().iter() {
for (key, attribute_value) in item {
let column_name = FieldName::new(key.clone().into());
// dbg!(&column_name);
Expand Down
14 changes: 0 additions & 14 deletions crates/ndc-dynamodb/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use query_engine_execution::metrics;
pub struct State {
pub metrics: metrics::Metrics,
pub client: aws_sdk_dynamodb::Client,
// pub project_id: String,
// pub dataset_id: String,
}

/// Create a connection pool and wrap it inside a connector State.
Expand Down Expand Up @@ -62,18 +60,6 @@ pub async fn create_state(
// let dynamodb_local_config = aws_sdk_dynamodb::config::Builder::from(&config).build();
let client = aws_sdk_dynamodb::Client::from_conf(config);

// let service_account_key =
// yup_oauth2::parse_service_account_key(configuration.service_key.clone()).unwrap();

// let config = aws_config::load_from_env().await;
// let client = aws_sdk_dynamodb::Client::new(&config);

// // Init BigQuery client
// let client =
// aws_sdk_dynamodb::Client::from_service_account_key(service_account_key, false)
// .await
// .unwrap();

Ok(State {
metrics,
client,
Expand Down
37 changes: 18 additions & 19 deletions crates/query-engine/execution/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::{collections::{hash_map, HashMap}, hash::Hash, process::exit, vec};
use crate::error::Error;
use crate::metrics;
use bytes::{BufMut, Bytes, BytesMut};
// use gcp_bigquery_client::model::query_request::QueryRequest;
// use gcp_bigquery_client::model::{query_parameter, query_parameter_type, query_parameter_value};
use query_engine_sql::sql::string::Param;
use serde_json::{self, to_string, Value};
use aws_sdk_dynamodb::{types::AttributeValue, Client};
Expand Down Expand Up @@ -84,29 +82,30 @@ pub async fn execute(
.set_parameters(temp_param)
.set_limit(query_limit)
.send()
.await;

let result = match rs
{
Ok(resp) => {
resp.items.unwrap()
}
Err(e) => {
println!("Got an error querying table:");
println!("{}", e);
exit(1)
}
};

dbg!(&result);
.await
.unwrap();

// let result = match rs
// {
// Ok(resp) => {
// resp.items.unwrap()
// }
// Err(e) => {
// println!("Got an error querying table:");
// println!("{}", e);
// exit(1)
// }
// };

// dbg!(&result);

let mut res_map: Vec<HashMap<String, String>> = vec![];


for item in result.iter() {
for item in rs.items.unwrap().iter() {
dbg!(item);
let mut hashmap = HashMap::new();
let value_map = for (key, attribute_value) in item.clone(){
for (key, attribute_value) in item.clone(){
if attribute_value.is_s() {
let s = attribute_value.as_s().unwrap().to_string();
println!("String: {}", s);
Expand Down

0 comments on commit a2d0d6b

Please sign in to comment.