mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
add some newtypes to remote_joins::types (#558)
## Description Add some newtype wrappers around existing types in remote joins. Functional no-op. V3_GIT_ORIGIN_REV_ID: dbd11eb30d48fc7aafd30604fc18e124d15b59ba
This commit is contained in:
parent
afa93c6b35
commit
1130e271c7
@ -471,7 +471,7 @@ fn assign_join_id<'s, 'ir>(
|
||||
|
||||
match found {
|
||||
None => {
|
||||
let next_id = state.counter.get_next();
|
||||
let next_id = JoinId(state.counter.get_next());
|
||||
state.remote_joins.push((remote_join, next_id));
|
||||
next_id
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use super::model_selection;
|
||||
use super::relationships;
|
||||
use super::ProcessResponseAs;
|
||||
use crate::execute::ir::selection_set::{FieldSelection, NestedSelection, ResultSelectionSet};
|
||||
use crate::execute::remote_joins::types::SourceFieldAlias;
|
||||
use crate::execute::remote_joins::types::{
|
||||
JoinLocations, JoinNode, LocationKind, MonotonicCounter, RemoteJoinType, TargetField,
|
||||
};
|
||||
@ -243,7 +244,7 @@ fn process_remote_relationship_field_mapping(
|
||||
selection: &ResultSelectionSet<'_>,
|
||||
field: &FieldMapping,
|
||||
ndc_fields: &mut IndexMap<String, ndc_models::Field>,
|
||||
) -> String {
|
||||
) -> SourceFieldAlias {
|
||||
match selection.contains(field) {
|
||||
None => {
|
||||
let internal_alias = make_hasura_phantom_field(&field.column);
|
||||
@ -254,9 +255,9 @@ fn process_remote_relationship_field_mapping(
|
||||
fields: None,
|
||||
},
|
||||
);
|
||||
internal_alias
|
||||
SourceFieldAlias(internal_alias)
|
||||
}
|
||||
Some(field_alias) => field_alias,
|
||||
Some(field_alias) => SourceFieldAlias(field_alias),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,11 @@ where
|
||||
let (join_variables_, _argument_ids): (Vec<_>, Vec<_>) = arguments.into_iter().unzip();
|
||||
let join_variables: Vec<BTreeMap<String, json::Value>> = join_variables_
|
||||
.iter()
|
||||
.map(|bmap| bmap.iter().map(|(k, v)| (k.clone(), v.0.clone())).collect())
|
||||
.map(|bmap| {
|
||||
bmap.iter()
|
||||
.map(|(k, v)| (k.0.clone(), v.0.clone()))
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
join_node.target_ndc_ir.variables = Some(join_variables);
|
||||
|
||||
|
@ -5,20 +5,20 @@
|
||||
//! relationship field mapping.
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use lang_graphql::ast::common::{TypeContainer, TypeName};
|
||||
use ndc_models;
|
||||
use lang_graphql::ast::common as ast;
|
||||
use serde_json as json;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::execute::ndc::FUNCTION_IR_VALUE_COLUMN_NAME;
|
||||
use crate::execute::plan::ProcessResponseAs;
|
||||
use json_ext::ValueExt;
|
||||
use ndc_models;
|
||||
|
||||
use super::error;
|
||||
use super::types::{
|
||||
Argument, Arguments, JoinId, JoinLocations, JoinNode, Location, LocationKind, MonotonicCounter,
|
||||
RemoteJoin, TargetField,
|
||||
Argument, ArgumentId, Arguments, JoinId, JoinLocations, JoinNode, Location, LocationKind,
|
||||
MonotonicCounter, RemoteJoin, SourceFieldAlias, TargetField, VariableName,
|
||||
};
|
||||
use crate::execute::ndc::FUNCTION_IR_VALUE_COLUMN_NAME;
|
||||
use crate::execute::plan::ProcessResponseAs;
|
||||
|
||||
pub(crate) struct CollectArgumentResult<'s, 'ir> {
|
||||
pub(crate) arguments: Arguments,
|
||||
@ -117,7 +117,7 @@ fn collect_argument_from_row<'s, 'ir>(
|
||||
let argument = create_argument(join_node, row);
|
||||
// de-duplicate arguments
|
||||
if let std::collections::hash_map::Entry::Vacant(e) = arguments.entry(argument) {
|
||||
let argument_id = argument_id_counter.get_next();
|
||||
let argument_id = ArgumentId(argument_id_counter.get_next());
|
||||
e.insert(argument_id);
|
||||
}
|
||||
*remote_join = Some(join_node.clone());
|
||||
@ -166,14 +166,14 @@ pub(crate) fn create_argument(
|
||||
let val = get_value(src_alias, row);
|
||||
// use the target field name here to create the variable
|
||||
// name to be used in RHS
|
||||
let variable_name = format!("${}", &field_mapping.column);
|
||||
let variable_name = VariableName(format!("${}", &field_mapping.column));
|
||||
argument.insert(variable_name, ValueExt::from(val.clone()));
|
||||
}
|
||||
TargetField::CommandField(argument_name) => {
|
||||
let val = get_value(src_alias, row);
|
||||
// use the target field name here to create the variable
|
||||
// name to be used in RHS
|
||||
let variable_name = format!("${}", &argument_name);
|
||||
let variable_name = VariableName(format!("${}", &argument_name));
|
||||
argument.insert(variable_name, ValueExt::from(val.clone()));
|
||||
}
|
||||
}
|
||||
@ -223,10 +223,10 @@ fn rows_from_row_field_value(
|
||||
}
|
||||
|
||||
pub(crate) fn get_value<'n>(
|
||||
pick_alias: &String,
|
||||
pick_alias: &SourceFieldAlias,
|
||||
row: &'n IndexMap<String, ndc_models::RowFieldValue>,
|
||||
) -> &'n json::Value {
|
||||
match row.get(pick_alias) {
|
||||
match row.get(&pick_alias.0) {
|
||||
Some(v) => &v.0,
|
||||
None => &json::Value::Null,
|
||||
}
|
||||
@ -235,7 +235,7 @@ pub(crate) fn get_value<'n>(
|
||||
/// resolve/process the command response for remote join execution
|
||||
fn resolve_command_response_row(
|
||||
row: &IndexMap<String, ndc_models::RowFieldValue>,
|
||||
type_container: &TypeContainer<TypeName>,
|
||||
type_container: &ast::TypeContainer<ast::TypeName>,
|
||||
) -> Result<Vec<IndexMap<String, ndc_models::RowFieldValue>>, error::FieldError> {
|
||||
let field_value_result = row.get(FUNCTION_IR_VALUE_COLUMN_NAME).ok_or_else(|| {
|
||||
error::NDCUnexpectedError::BadNDCResponse {
|
||||
|
@ -8,7 +8,7 @@ use std::collections::{BTreeMap, HashMap};
|
||||
use crate::execute::ndc::FUNCTION_IR_VALUE_COLUMN_NAME;
|
||||
use json_ext::ValueExt;
|
||||
|
||||
use super::types::{Argument, JoinId, JoinNode, Location, LocationKind, RemoteJoin};
|
||||
use super::types::{Argument, JoinId, JoinNode, Location, LocationKind, RemoteJoin, VariableName};
|
||||
use super::{collect, error};
|
||||
|
||||
/// Inserts values in the LHS response from values in RHS response, based on the
|
||||
@ -21,7 +21,7 @@ pub(crate) fn join_responses(
|
||||
remote_alias: &str,
|
||||
location: &Location<(RemoteJoin<'_, '_>, JoinId)>,
|
||||
lhs_response: &mut [ndc_models::RowSet],
|
||||
rhs_response: &HashMap<BTreeMap<String, ValueExt>, ndc_models::RowSet>,
|
||||
rhs_response: &HashMap<BTreeMap<VariableName, ValueExt>, ndc_models::RowSet>,
|
||||
) -> Result<(), error::FieldError> {
|
||||
for row_set in lhs_response.iter_mut() {
|
||||
if let Some(rows) = row_set.rows.as_mut() {
|
||||
|
@ -1,15 +1,16 @@
|
||||
//! Join tree and related types for remote joins.
|
||||
//!
|
||||
use indexmap::IndexMap;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use json_ext::ValueExt;
|
||||
use metadata_resolve;
|
||||
use ndc_models;
|
||||
use open_dds;
|
||||
use open_dds::arguments::ArgumentName;
|
||||
use open_dds::types::FieldName;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use crate::execute::plan::ProcessResponseAs;
|
||||
use json_ext::ValueExt;
|
||||
use metadata_resolve;
|
||||
|
||||
/// This tree structure captures all the locations (in the selection set IR) where
|
||||
/// remote joins are found.
|
||||
@ -136,9 +137,16 @@ pub struct RemoteJoin<'s, 'ir> {
|
||||
pub remote_join_type: RemoteJoinType,
|
||||
}
|
||||
|
||||
/// Name of the source field used in the join mapping
|
||||
pub type SourceFieldName = FieldName;
|
||||
pub type SourceFieldAlias = String;
|
||||
|
||||
/// Alias of the source field used in the join mapping. This is basically a NDC
|
||||
/// field alias (which in the NDC IR is `String`). Change this when modifying
|
||||
/// the IR to have a newtype Alias.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SourceFieldAlias(pub String);
|
||||
|
||||
/// Target field used in the join mapping
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum TargetField {
|
||||
ModelField((FieldName, metadata_resolve::NdcColumnForComparison)),
|
||||
@ -152,14 +160,19 @@ pub enum RemoteJoinType {
|
||||
}
|
||||
|
||||
/// For assigning a unique number to each unique join
|
||||
pub type JoinId = i16;
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct JoinId(pub i16);
|
||||
|
||||
/// Name of the variable used in the IR
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||
pub struct VariableName(pub String);
|
||||
|
||||
/// An 'Argument' is a map of variable name to it's value.
|
||||
/// For example, `{"first_name": "John", "last_name": "Doe"}`
|
||||
pub type Argument = BTreeMap<String, ValueExt>;
|
||||
pub type Argument = BTreeMap<VariableName, ValueExt>;
|
||||
|
||||
/// For assigning a unique number to each argument
|
||||
pub type ArgumentId = i16;
|
||||
pub struct ArgumentId(pub i16);
|
||||
|
||||
/// A map of each argument to its argument id
|
||||
pub type Arguments = HashMap<Argument, ArgumentId>;
|
||||
|
Loading…
Reference in New Issue
Block a user