Skip to content

Commit

Permalink
Merge pull request #33 from hasura/kc/remove-composite-types-code
Browse files Browse the repository at this point in the history
Remove all the composite types code
  • Loading branch information
codingkarthik authored Oct 8, 2024
2 parents 9af2eed + c2534bb commit cbaae7c
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 614 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ nonempty = "0.10"
percent-encoding = "2"
prometheus = "0.13"
ref-cast = "1"
reqwest = "0.11"
reqwest = { version = "0.11", default-features = false }
schemars = "0.8"
serde = "1"
serde_derive = "^1.0"
Expand Down
1 change: 0 additions & 1 deletion crates/configuration/src/to_runtime_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ fn convert_nullable(nullable: &metadata::Nullable) -> query_engine_metadata::met
fn convert_type(r#type: metadata::Type) -> query_engine_metadata::metadata::Type {
match r#type {
metadata::Type::ScalarType(t) => query_engine_metadata::metadata::Type::ScalarType(t),
metadata::Type::CompositeType(t) => query_engine_metadata::metadata::Type::CompositeType(t),
metadata::Type::ArrayType(t) => {
query_engine_metadata::metadata::Type::ArrayType(Box::new(convert_type(*t)))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/connectors/ndc-bigquery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ axum-test-helper = { workspace = true }
insta = { workspace = true, features = ["json"] }
env_logger = { workspace = true }
hyper = { workspace = true, features = ["tcp"] }
reqwest = { workspace = true, default-features = false, features = ["rustls-tls"] }
reqwest = { workspace = true, features = ["rustls-tls"] }
similar-asserts = { workspace = true }
url = { workspace = true }
1 change: 0 additions & 1 deletion crates/connectors/ndc-bigquery/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,5 @@ pub fn type_to_type(typ: &metadata::Type) -> models::Type {
metadata::Type::ScalarType(scalar_type) => models::Type::Named {
name: scalar_type.as_str().into(),
},
metadata::Type::CompositeType(t) => models::Type::Named { name: t.clone() },
}
}
22 changes: 0 additions & 22 deletions crates/query-engine/metadata/src/metadata/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub struct ScalarTypeTypeName(pub String);
#[serde(rename_all = "camelCase")]
pub enum Type {
ScalarType(models::ScalarTypeName),
CompositeType(models::TypeName),
ArrayType(Box<Type>),
}

Expand Down Expand Up @@ -44,27 +43,6 @@ pub struct ScalarType {
pub type_representation: Option<TypeRepresentation>,
}

/// Map of all known composite types.
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct CompositeTypes(pub BTreeMap<models::TypeName, CompositeType>);

impl CompositeTypes {
pub fn empty() -> Self {
CompositeTypes(BTreeMap::new())
}
}

/// Information about a composite type. These are very similar to tables, but with the crucial
/// difference that composite types do not support constraints (such as NOT NULL).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct CompositeType {
pub type_name: String,
pub schema_name: Option<String>,
pub fields: BTreeMap<models::FieldName, FieldInfo>,
pub description: Option<String>,
}

/// The complete list of supported binary operators for scalar types.
/// Not all of these are supported for every type.
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)]
Expand Down
2 changes: 0 additions & 2 deletions crates/query-engine/sql/src/sql/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ pub enum SelectList {
SelectStar,
SelectStarFrom(TableReference),
Select1,
SelectStarComposite(Expression),
SelectListComposite(Box<SelectList>, Box<SelectList>),
}

/// A FROM clause
Expand Down
10 changes: 0 additions & 10 deletions crates/query-engine/sql/src/sql/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,9 @@ impl SelectList {
table_reference.to_sql(sql);
sql.append_syntax(".*");
}
SelectList::SelectStarComposite(expr) => {
sql.append_syntax("(");
expr.to_sql(sql);
sql.append_syntax(").*");
}
SelectList::Select1 => {
sql.append_syntax("1");
}
SelectList::SelectListComposite(select_list1, select_list2) => {
select_list1.to_sql(sql);
sql.append_syntax(", ");
select_list2.to_sql(sql);
}
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions crates/query-engine/sql/src/sql/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,6 @@ pub fn make_column_alias(name: String) -> ColumnAlias {

// SELECTs //

/// Build a simple 'SELECT (exp).*'
pub fn select_composite(exp: Expression) -> Select {
Select {
with: empty_with(),
select_list: SelectList::SelectStarComposite(exp),
from: None,
joins: vec![],
where_: Where(empty_where()),
group_by: empty_group_by(),
order_by: empty_order_by(),
limit: empty_limit(),
}
}

/// Build a simple select with a select list and the rest are empty.
pub fn simple_select(select_list: Vec<(ColumnAlias, Expression)>) -> Select {
Select {
Expand Down
9 changes: 0 additions & 9 deletions crates/query-engine/sql/src/sql/rewrites/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,9 @@ pub fn normalize_select(mut select: Select) -> Select {
/// Normalize all expressions in a select list.
pub fn normalize_select_list(select_list: SelectList) -> SelectList {
match select_list {
SelectList::SelectListComposite(select_list1, select_list2) => {
SelectList::SelectListComposite(
Box::new(normalize_select_list(*select_list1)),
Box::new(normalize_select_list(*select_list2)),
)
}
SelectList::SelectStar => SelectList::SelectStar,
SelectList::SelectStarFrom(table) => SelectList::SelectStarFrom(table),
SelectList::Select1 => SelectList::Select1,
SelectList::SelectStarComposite(exp) => {
SelectList::SelectStarComposite(normalize_expr(exp))
}
SelectList::SelectList(vec) => SelectList::SelectList(
vec.into_iter()
.map(|(alias, expr)| (alias, normalize_expr(expr)))
Expand Down
108 changes: 0 additions & 108 deletions crates/query-engine/translation/src/translation/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ pub enum CollectionInfo<'env> {
},
}

#[derive(Debug)]
/// Metadata information about a composite type. This includes both tables (and views) and
/// dedicated composite types.
pub enum CompositeTypeInfo<'env> {
Table {
name: models::CollectionName,
info: &'env metadata::TableInfo,
},
CompositeType {
name: models::TypeName,
info: &'env metadata::CompositeType,
},
}

#[derive(Debug)]
/// Metadata information about any object that can have fields
pub enum FieldsInfo<'env> {
Expand All @@ -115,22 +101,6 @@ pub enum FieldsInfo<'env> {
name: &'env models::CollectionName,
info: &'env metadata::NativeQueryInfo,
},
CompositeType {
name: models::TypeName,
info: &'env metadata::CompositeType,
},
}

impl<'a> From<&'a CompositeTypeInfo<'a>> for FieldsInfo<'a> {
fn from(value: &'a CompositeTypeInfo<'a>) -> Self {
match value {
CompositeTypeInfo::Table { name, info } => FieldsInfo::Table { name, info },
CompositeTypeInfo::CompositeType { name, info } => FieldsInfo::CompositeType {
name: name.clone(),
info,
},
}
}
}

impl<'a> From<&'a CollectionInfo<'a>> for FieldsInfo<'a> {
Expand Down Expand Up @@ -233,41 +203,6 @@ impl<'request> Env<'request> {
info.ok_or(Error::CollectionNotFound(type_name.as_str().into()))
}

/// Lookup a metadata object which can be described by a Composite Type. This can be any of
/// Tables and Composite Types themselves.
///
/// This does not include Native Queries, since the fields of a Native Query is an ad-hoc
/// construct of the NDC, and not a named type that Postgres knows about.
///
/// Therefore, being a `CompositeTypeInfo` is a stronger property than being a `FieldsInfo`.
///
/// This is used in the elaboration of nested fields that are not fully specified, and in the
/// translation of input values and variables of composite type.
pub fn lookup_composite_type(
&self,
type_name: &'request models::TypeName,
) -> Result<CompositeTypeInfo<'request>, Error> {
let info =
self.metadata
.tables
.0
.get(type_name.as_str())
.map(|t| CompositeTypeInfo::Table {
name: type_name.as_str().into(),
info: t,
});
// .or_else(|| {
// self.metadata.composite_types.0.get(type_name).map(|t| {
// CompositeTypeInfo::CompositeType {
// name: t.type_name.as_str().into(),
// info: t,
// }
// })
// });

info.ok_or(Error::CollectionNotFound(type_name.as_str().into()))
}

/// Lookup a collection's information in the metadata.
pub fn lookup_collection(
&self,
Expand Down Expand Up @@ -411,16 +346,6 @@ impl FieldsInfo<'_> {
.ok_or_else(|| {
Error::ColumnNotFoundInCollection(column_name.clone(), name.as_str().into())
}),
FieldsInfo::CompositeType { name, info } => info
.fields
.get(column_name)
.map(|field_info| ColumnInfo {
name: sql::ast::ColumnName(field_info.field_name.clone()),
r#type: field_info.r#type.clone(),
})
.ok_or_else(|| {
Error::ColumnNotFoundInCollection(column_name.clone(), name.as_str().into())
}),
}
}
}
Expand All @@ -432,39 +357,6 @@ impl CollectionInfo<'_> {
}
}

impl CompositeTypeInfo<'_> {
pub fn type_name(&self) -> &str {
match self {
CompositeTypeInfo::Table { name, .. } => name.as_str(),
CompositeTypeInfo::CompositeType { name, .. } => name.as_str(),
}
}

pub fn schema_name(&self) -> Option<&String> {
match self {
CompositeTypeInfo::Table { info, .. } => Some(&info.schema_name),
CompositeTypeInfo::CompositeType { info, .. } => info.schema_name.as_ref(),
}
}

/// Fetch all the field names (external, internal) of a composite type.
pub fn fields(&self) -> Vec<(String, &String)> {
match self {
CompositeTypeInfo::CompositeType { name: _, info } => info
.fields
.iter()
.map(|(name, field)| (name.clone().into(), &field.field_name))
.collect::<Vec<_>>(),

CompositeTypeInfo::Table { name: _, info } => info
.columns
.iter()
.map(|(name, column)| (name.clone().into(), &column.name))
.collect::<Vec<_>>(),
}
}
}

impl Default for State {
fn default() -> State {
State {
Expand Down
Loading

0 comments on commit cbaae7c

Please sign in to comment.