Skip to content

Commit

Permalink
type representation
Browse files Browse the repository at this point in the history
  • Loading branch information
py committed Dec 3, 2024
1 parent 9e301ce commit 7c54d65
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 176 deletions.
142 changes: 0 additions & 142 deletions crates/configuration/src/to_runtime_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ fn convert_scalar_types(
type_name: scalar_type.type_name,
// schema_name: (scalar_type.schema_name),
description: scalar_type.description,
aggregate_functions: scalar_type
.aggregate_functions
.into_iter()
.map(|(k, v)| (k, convert_aggregate_function(v)))
.collect(),
comparison_operators: scalar_type
.comparison_operators
.into_iter()
Expand All @@ -103,63 +98,6 @@ fn convert_scalar_types(
)
}

fn convert_aggregate_function(
aggregate_function: metadata::AggregateFunction,
) -> query_engine_metadata::metadata::AggregateFunction {
query_engine_metadata::metadata::AggregateFunction {
return_type: aggregate_function.return_type,
}
}

// fn convert_native_operations(
// native_operations: metadata::NativeOperations,
// ) -> query_engine_metadata::metadata::NativeOperations {
// let mut queries = BTreeMap::new();
// let mut mutations = BTreeMap::new();

// for (name, query) in native_operations.queries.0 {
// queries.insert(name, convert_native_query_info(query));
// }
// for (name, mutation) in native_operations.mutations.0 {
// mutations.insert(name, convert_native_query_info(mutation));
// }

// query_engine_metadata::metadata::NativeOperations {
// queries: query_engine_metadata::metadata::NativeQueries(queries),
// mutations: query_engine_metadata::metadata::NativeMutations(mutations),
// }
// }

// fn convert_native_query_info(
// native_query_info: metadata::NativeQueryInfo,
// ) -> query_engine_metadata::metadata::NativeQueryInfo {
// query_engine_metadata::metadata::NativeQueryInfo {
// sql: convert_native_query_sql_either(native_query_info.sql),
// columns: native_query_info
// .columns
// .into_iter()
// .map(|(k, v)| (k, convert_read_only_column_info(v)))
// .collect(),
// arguments: native_query_info
// .arguments
// .into_iter()
// .map(|(k, v)| (k, convert_read_only_column_info(v)))
// .collect(),
// description: native_query_info.description,
// }
// }

// fn convert_read_only_column_info(
// read_only_column_info: metadata::ReadOnlyColumnInfo,
// ) -> query_engine_metadata::metadata::ReadOnlyColumnInfo {
// query_engine_metadata::metadata::ReadOnlyColumnInfo {
// name: read_only_column_info.name,
// r#type: convert_type(read_only_column_info.r#type),
// nullable: convert_nullable(&read_only_column_info.nullable),
// description: read_only_column_info.description,
// }
// }

fn convert_nullable(nullable: &metadata::Nullable) -> query_engine_metadata::metadata::Nullable {
match nullable {
metadata::Nullable::Nullable => query_engine_metadata::metadata::Nullable::Nullable,
Expand All @@ -176,86 +114,6 @@ fn convert_type(r#type: metadata::Type) -> query_engine_metadata::metadata::Type
}
}

// fn convert_native_query_sql_either(
// sql: metadata::NativeQuerySqlEither,
// ) -> query_engine_metadata::metadata::NativeQuerySqlEither {
// match sql {
// metadata::NativeQuerySqlEither::NativeQuerySql(internal_sql) => {
// query_engine_metadata::metadata::NativeQuerySqlEither::NativeQuerySql(
// convert_native_query_sql_internal(internal_sql),
// )
// }
// metadata::NativeQuerySqlEither::NativeQuerySqlExternal(external_sql) => {
// query_engine_metadata::metadata::NativeQuerySqlEither::NativeQuerySqlExternal(
// convert_native_query_sql_external(external_sql),
// )
// }
// }
// }

// fn convert_native_query_sql_internal(
// internal_sql: metadata::NativeQuerySql,
// ) -> query_engine_metadata::metadata::NativeQuerySql {
// match internal_sql {
// metadata::NativeQuerySql::FromFile { file, sql } => {
// query_engine_metadata::metadata::NativeQuerySql::FromFile {
// file,
// sql: convert_native_query_parts(sql),
// }
// }
// metadata::NativeQuerySql::Inline { sql } => {
// query_engine_metadata::metadata::NativeQuerySql::Inline {
// sql: convert_native_query_parts(sql),
// }
// }
// }
// }

// fn convert_native_query_sql_external(
// external_sql: metadata::NativeQuerySqlExternal,
// ) -> query_engine_metadata::metadata::NativeQuerySqlExternal {
// match external_sql {
// metadata::NativeQuerySqlExternal::File { file } => {
// query_engine_metadata::metadata::NativeQuerySqlExternal::File { file }
// }
// metadata::NativeQuerySqlExternal::Inline { inline } => {
// query_engine_metadata::metadata::NativeQuerySqlExternal::Inline {
// inline: convert_native_query_parts(inline),
// }
// }
// metadata::NativeQuerySqlExternal::InlineUntagged(parts) => {
// query_engine_metadata::metadata::NativeQuerySqlExternal::InlineUntagged(
// convert_native_query_parts(parts),
// )
// }
// }
// }

// fn convert_native_query_parts(
// inline: metadata::NativeQueryParts,
// ) -> query_engine_metadata::metadata::NativeQueryParts {
// query_engine_metadata::metadata::NativeQueryParts(
// inline
// .0
// .into_iter()
// .map(convert_native_query_part)
// .collect(),
// )
// }

// fn convert_native_query_part(
// native_query_part: metadata::NativeQueryPart,
// ) -> query_engine_metadata::metadata::NativeQueryPart {
// match native_query_part {
// metadata::NativeQueryPart::Text(t) => {
// query_engine_metadata::metadata::NativeQueryPart::Text(t)
// }
// metadata::NativeQueryPart::Parameter(p) => {
// query_engine_metadata::metadata::NativeQueryPart::Parameter(p)
// }
// }
// }

fn convert_type_representation(
type_representation: metadata::TypeRepresentation,
) -> query_engine_metadata::metadata::TypeRepresentation {
Expand Down
34 changes: 17 additions & 17 deletions crates/configuration/src/version1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,6 @@ pub async fn introspect(
.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.items.unwrap() {
for (key, attribute_value) in item {
let column_name = FieldName::new(key.clone().into());
Expand All @@ -206,6 +192,16 @@ pub async fn introspect(
let scalar_type_name = ScalarTypeName::new("Boolean".into());
scalars_list.insert(scalar_type_name.clone());
metadata::Type::ScalarType(scalar_type_name)
} else if attribute_value.is_b() {
let scalar_type_name = ScalarTypeName::new("Binary".into());
scalars_list.insert(scalar_type_name.clone());
metadata::Type::ScalarType(scalar_type_name)
} else if attribute_value.is_l() {
let scalar_type_name = ScalarTypeName::new("List".into());
metadata::Type::ScalarType(scalar_type_name)
} else if attribute_value.is_m() {
let scalar_type_name = ScalarTypeName::new("Map".into());
metadata::Type::ScalarType(scalar_type_name)
} else {
metadata::Type::ScalarType(ScalarTypeName::new("Any".into()))
};
Expand Down Expand Up @@ -288,12 +284,17 @@ pub async fn introspect(
// Scalars
let mut scalars: BTreeMap<ScalarTypeName, metadata::ScalarType> = BTreeMap::new();
for scalar in scalars_list {
let type_rep = match scalar.as_str() {
"String" => Some(metadata::TypeRepresentation::String),
"Number" => Some(metadata::TypeRepresentation::Int64),
"Boolean" => Some(metadata::TypeRepresentation::Boolean),
_ => None,
};
let scalar_type = metadata::ScalarType {
type_name: scalar.clone(),
description: None,
aggregate_functions: BTreeMap::new(),
comparison_operators: get_comparison_operators_for_type(&scalar),
type_representation: None,
type_representation: type_rep,
};
scalars.insert(scalar.clone(), scalar_type);
}
Expand All @@ -304,7 +305,6 @@ pub async fn introspect(
secret_access_key: args.connection_settings.secret_access_key.clone(),
// provider_name: args.connection_settings.provider_name.clone(),
region: args.connection_settings.region.clone(),
// connection_placeholder: args.connection_settings.connection_placeholder.clone(),
},
metadata: metadata::Metadata {
tables: TablesInfo(tables_info),
Expand Down
17 changes: 1 addition & 16 deletions crates/ndc-dynamodb/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,7 @@ pub fn get_schema(
.type_representation
.as_ref()
.map(map_type_representation),
aggregate_functions: scalar_type_info
.aggregate_functions
.iter()
.map(|(function_name, function_definition)| {
(
function_name.clone(),
models::AggregateFunctionDefinition {
result_type: models::Type::Nullable {
underlying_type: Box::new(models::Type::Named {
name: function_definition.return_type.clone(),
}),
},
},
)
})
.collect(),
aggregate_functions: BTreeMap::new(),
comparison_operators: scalar_type_info
.comparison_operators
.iter()
Expand Down
1 change: 0 additions & 1 deletion crates/query-engine/metadata/src/metadata/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub struct ScalarType {
pub type_name: ScalarTypeName,
// pub schema_name: Option<String>, // TODO(PY): see what happens when option is removed
pub description: Option<String>,
pub aggregate_functions: BTreeMap<models::AggregateFunctionName, AggregateFunction>,
pub comparison_operators: BTreeMap<models::ComparisonOperatorName, ComparisonOperator>,
pub type_representation: Option<TypeRepresentation>,
}
Expand Down

0 comments on commit 7c54d65

Please sign in to comment.