Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
py committed Dec 3, 2024
1 parent 3f6989e commit 9d39c0a
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 95 deletions.
11 changes: 0 additions & 11 deletions crates/configuration/src/version1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,18 @@ pub async fn introspect(

let client = aws_sdk_dynamodb::Client::from_conf(config);
let tables_result = client.list_tables().send().await;
// dbg!(&tables_result);
let tables = tables_result
.map_err(|_op| {
ParseConfigurationError::IoErrorButStringified("Failed to list tables:".to_string())
})
.unwrap(); //TODO: handle error
// dbg!(&tables);
let table_names = tables.table_names.unwrap_or_default();
let mut scalars_list: BTreeSet<ScalarTypeName> = BTreeSet::new();
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;
let table = table_result.unwrap(); //TODO: handle error
let table = table.table.unwrap();
// dbg!(&table);
let table_name = table.table_name.unwrap();
let attribute_definitions = table.attribute_definitions.unwrap();
let mut columns_info: BTreeMap<FieldName, ColumnInfo> = BTreeMap::new();
Expand All @@ -146,13 +143,6 @@ pub async fn introspect(
"S" => ScalarTypeName::new("String".into()),
"N" => ScalarTypeName::new("Number".into()),
"B" => ScalarTypeName::new("Binary".into()),
// "SS" => ScalarTypeName::new("StringSet".into()),
// "NS" => ScalarTypeName::new("NumberSet".into()),
// "BS" => ScalarTypeName::new("BinarySet".into()),
// "BOOL" => ScalarTypeName::new("Boolean".into()),
// "NULL" => ScalarTypeName::new("Null".into()),
// "M" => ScalarTypeName::new("Object".into()),
// "L" => ScalarTypeName::new("Array".into()),
_ => ScalarTypeName::new("Any".into()),
};
scalars_list.insert(scalar_type_name.clone());
Expand All @@ -179,7 +169,6 @@ pub async fn introspect(
for item in &result.items.unwrap() {
for (key, attribute_value) in item {
let column_name = FieldName::new(key.clone().into());
// dbg!(&column_name);
let column_type = if attribute_value.is_s() {
let scalar_type_name = ScalarTypeName::new("String".into());
scalars_list.insert(scalar_type_name.clone());
Expand Down
13 changes: 3 additions & 10 deletions crates/ndc-dynamodb/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub async fn query(
query_request_json = serde_json::to_string(&query_request).unwrap(),
query_request = ?query_request
);
// dbg!("got the query request");

let plan = async {
plan_query(configuration, state, query_request).map_err(|err| {
Expand All @@ -46,7 +45,6 @@ pub async fn query(
}
.instrument(info_span!("Plan query"))
.await?;
// dbg!("planned the query");

let result = async {
execute_query(state, plan).await.map_err(|err| {
Expand Down Expand Up @@ -82,13 +80,8 @@ async fn execute_query(
plan: sql::execution_plan::ExecutionPlan<sql::execution_plan::Query>,
) -> Result<JsonResponse<models::QueryResponse>, query_engine_execution::error::Error> {
let timer = state.metrics.time_query_execution();
let result = query_engine_execution::query::execute(
&state.client,
&state.metrics,
// &state.project_id,
plan,
)
.await
.map(JsonResponse::Serialized);
let result = query_engine_execution::query::execute(&state.client, &state.metrics, plan)
.await
.map(JsonResponse::Serialized);
timer.complete_with(result)
}
8 changes: 0 additions & 8 deletions crates/ndc-dynamodb/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ pub async fn create_state(
.credentials_provider(credentials)
.build();

// let config = aws_config::defaults(aws_config::BehaviorVersion::latest())
// .test_credentials()
// .region(Region::new("us-west-2"))
// // DynamoDB run locally uses port 8000 by default.
// .endpoint_url("http://localhost:8085")
// .load()
// .await;
// let dynamodb_local_config = aws_sdk_dynamodb::config::Builder::from(&config).build();
let client = aws_sdk_dynamodb::Client::from_conf(config);

Ok(State { metrics, client })
Expand Down
8 changes: 0 additions & 8 deletions crates/query-engine/execution/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub async fn execute(
match plan.query.variables {
None => {
let query_request = plan.query.query_sql().sql;
dbg!(&query_request);
let query_limit: Option<i32> = plan.query.limit.map(|limit| limit as i32);

// Query
Expand All @@ -41,7 +40,6 @@ pub async fn execute(
let mut res_map: Vec<HashMap<String, String>> = vec![];

for item in &rs.items.unwrap() {
dbg!(item);
let mut hashmap = HashMap::new();
for (key, attribute_value) in item.clone() {
if attribute_value.is_s() {
Expand Down Expand Up @@ -106,19 +104,13 @@ pub async fn execute(
println!("Unknown");
}
}
dbg!(item);
res_map.push(hashmap);
}

dbg!(&res_map);

let mut rows: HashMap<String, Vec<HashMap<String, String>>> = HashMap::new();
rows.insert("rows".into(), res_map);

dbg!(&rows);

let rows_stringified = serde_json::to_string(&rows).unwrap();
dbg!(&rows_stringified);

let row_value: Value = serde_json::from_str(&rows_stringified).unwrap();

Expand Down
41 changes: 3 additions & 38 deletions crates/query-engine/translation/src/translation/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ pub fn translate(
query_request: models::QueryRequest,
) -> Result<sql::execution_plan::ExecutionPlan<sql::execution_plan::Query>, Error> {
let mut state = State::new();
// let variables_from = state.make_variables_table(&query_request.variables);
// let variables_table_ref = variables_from.clone().map(|(_, table_ref)| table_ref);
let env = Env::new(
metadata,
// query_request.collection_relationships,
// Mutations_version: None,
// variables_table_ref,
);
let env = Env::new(metadata);

let collection_string = query_request.collection.as_str();
let collection = if collection_string.contains(':') {
Expand All @@ -37,7 +30,6 @@ pub fn translate(
let collection_name = models::CollectionName::new(split[0].into());
let gsi_name = split[1];
(collection_name, Some(sql::ast::Gsi(gsi_name.to_string())))
// coll_name =
} else {
(models::CollectionName::new(collection_string.into()), None)
};
Expand All @@ -54,36 +46,9 @@ pub fn translate(
&query_request.query,
)?;

// form a single JSON item shaped `{ rows: [], aggregates: {} }`
// form a single JSON item shaped `{ rows: [] }`
// that matches the models::RowSet type
let json_select = sql::helpers::select_rowset(
// (
// state.make_table_alias("universe".to_string()),
// sql::helpers::make_column_alias("universe".to_string()),
// ),
// (
// state.make_table_alias("rows".to_string()),
// state.make_table_alias("rows_inner".to_string()),
// ),
// (
// state.make_table_alias("aggregates".to_string()),
// state.make_table_alias("aggregates_inner".to_string()),
// ),
// &variables_from,
// &state.make_table_alias("universe_agg".to_string()),
// native queries if there are any
// sql::ast::With {
// common_table_expressions: {
// let (ctes, mut global_table_index) = native_queries::translate(&env, state)?;
// // wrap ctes in another cte to guard against mutations in queries
// ctes.into_iter()
// .map(|cte| native_queries::wrap_cte_in_cte(&mut global_table_index, cte))
// .collect()
// },
// },
select_set,
&returns_field,
);
let json_select = sql::helpers::select_rowset(select_set, &returns_field);

// normalize ast
let json_select = sql::rewrites::constant_folding::normalize_select(json_select);
Expand Down
20 changes: 0 additions & 20 deletions crates/query-engine/translation/src/translation/query/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ pub fn translate_json_value(
Ok(Expression::Value(Value::Float8(lit)))
}
(serde_json::Value::String(str), _) => Ok(Expression::Value(Value::String(str.clone()))),
// Ok(Expression::Cast {
// expression: Box::new(Expression::Value(Value::String(str.clone()))),
// r#type: type_to_ast_scalar_type(env, r#type)?,
// }),
(serde_json::Value::Array(_), database::Type::ArrayType(_)) => {
let value_expression =
sql::ast::Expression::Value(sql::ast::Value::JsonValue(value.clone()));
Expand Down Expand Up @@ -78,22 +74,6 @@ fn type_to_ast_scalar_type_name(
Ok(sql::ast::ScalarTypeName::Unqualified(
scalar_type.type_name.to_string(),
))
// match scalar_type.schema_name.clone() {
// None => Ok(sql::ast::ScalarTypeName::Unqualified(
// scalar_type.type_name.to_string(),
// )),
// Some(_schema_name) =>
// // FIXME(PY): How to use Qualified types. In cast it gives something like Cast(@param1 as hasura-development.chinook_sample.string) when using _in operator for strings
// // Ok(sql::ast::ScalarTypeName::Qualified {
// // schema_name: sql::ast::SchemaName(schema_name),
// // type_name: scalar_type.type_name.to_string(),
// // }),
// {
// Ok(sql::ast::ScalarTypeName::Unqualified(
// scalar_type.type_name.to_string(),
// ))
// }
// }
}
}
}
Expand Down

0 comments on commit 9d39c0a

Please sign in to comment.