Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/builder/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ fn add_collector(
struct ExportDataFieldsInfo {
local_collector_ref: AnalyzedLocalCollectorReference,
primary_key_def: AnalyzedPrimaryKeyDef,
primary_key_schema: Vec<FieldSchema>,
primary_key_schema: Box<[FieldSchema]>,
value_fields_idx: Vec<u32>,
value_stable: bool,
}
Expand Down Expand Up @@ -851,8 +851,8 @@ impl AnalyzerContext {

let primary_key_schema = pk_fields_idx
.iter()
.map(|idx| collector_schema.fields[*idx].clone())
.collect::<Vec<_>>();
.map(|idx| collector_schema.fields[*idx].without_attrs())
.collect::<Box<[_]>>();
let mut value_fields_schema: Vec<FieldSchema> = vec![];
let mut value_fields_idx = vec![];
for (idx, field) in collector_schema.fields.iter().enumerate() {
Expand Down Expand Up @@ -911,6 +911,13 @@ impl AnalyzerContext {
setup_key: data_coll_output.setup_key,
desired_setup_state: data_coll_output.desired_setup_state,
setup_by_user: export_op.spec.setup_by_user,
key_type: Some(
data_fields_info
.primary_key_schema
.iter()
.map(|field| field.value_type.typ.clone())
.collect::<Box<[_]>>(),
),
};
targets_analyzed_ss[*idx] = Some(export_op_ss);

Expand Down Expand Up @@ -940,6 +947,7 @@ impl AnalyzerContext {
setup_key,
desired_setup_state,
setup_by_user: false,
key_type: None,
};
declarations_analyzed_ss.push(decl_ss);
}
Expand Down
25 changes: 16 additions & 9 deletions src/builder/exec_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct AnalyzedTargetSetupState {
pub setup_key: serde_json::Value,
pub desired_setup_state: serde_json::Value,
pub setup_by_user: bool,
/// None for declarations.
pub key_type: Option<Box<[schema::ValueType]>>,
}

pub struct AnalyzedSetupState {
Expand Down Expand Up @@ -121,15 +123,19 @@ fn build_target_id(
let mut compatible_target_ids = HashSet::<Option<i32>>::new();
let mut reusable_schema_version_ids = HashSet::<Option<i32>>::new();
for existing_state in existing_target_states.iter().flat_map(|v| v.iter()) {
let compatibility =
if analyzed_target_ss.setup_by_user == existing_state.common.setup_by_user {
target_factory.check_state_compatibility(
&analyzed_target_ss.desired_setup_state,
&existing_state.state,
)?
} else {
SetupStateCompatibility::NotCompatible
};
let compatibility = if let Some(key_type) = &analyzed_target_ss.key_type
&& let Some(existing_key_type) = &existing_state.common.key_type
&& key_type != existing_key_type
{
SetupStateCompatibility::NotCompatible
} else if analyzed_target_ss.setup_by_user != existing_state.common.setup_by_user {
SetupStateCompatibility::NotCompatible
} else {
target_factory.check_state_compatibility(
&analyzed_target_ss.desired_setup_state,
&existing_state.state,
)?
};
let compatible_target_id = if compatibility != SetupStateCompatibility::NotCompatible {
reusable_schema_version_ids.insert(
(compatibility == SetupStateCompatibility::Compatible)
Expand Down Expand Up @@ -184,6 +190,7 @@ fn build_target_id(
schema_version_id,
max_schema_version_id: max_schema_version_id.max(schema_version_id),
setup_by_user: analyzed_target_ss.setup_by_user,
key_type: analyzed_target_ss.key_type.clone(),
},
state: analyzed_target_ss.desired_setup_state.clone(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/builder/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct AnalyzedExportOp {
pub export_target_factory: Arc<dyn TargetFactory + Send + Sync>,
pub export_context: Arc<dyn Any + Send + Sync>,
pub primary_key_def: AnalyzedPrimaryKeyDef,
pub primary_key_schema: Vec<FieldSchema>,
pub primary_key_schema: Box<[FieldSchema]>,
/// idx for value fields - excluding the primary key field.
pub value_fields: Vec<u32>,
/// If true, value is never changed on the same primary key.
Expand Down
2 changes: 1 addition & 1 deletion src/ops/factory_bases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ pub struct TypedExportDataCollectionBuildOutput<F: TargetFactoryBase + ?Sized> {
pub struct TypedExportDataCollectionSpec<F: TargetFactoryBase + ?Sized> {
pub name: String,
pub spec: F::Spec,
pub key_fields_schema: Vec<FieldSchema>,
pub key_fields_schema: Box<[FieldSchema]>,
pub value_fields_schema: Vec<FieldSchema>,
pub index_options: IndexOptions,
}
Expand Down
2 changes: 1 addition & 1 deletion src/ops/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub struct ExportDataCollectionBuildOutput {
pub struct ExportDataCollectionSpec {
pub name: String,
pub spec: serde_json::Value,
pub key_fields_schema: Vec<FieldSchema>,
pub key_fields_schema: Box<[FieldSchema]>,
pub value_fields_schema: Vec<FieldSchema>,
pub index_options: IndexOptions,
}
Expand Down
11 changes: 7 additions & 4 deletions src/ops/py_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,14 @@ impl interface::TargetFactory for PyExportTargetFactory {

fn check_state_compatibility(
&self,
_desired_state: &serde_json::Value,
_existing_state: &serde_json::Value,
desired_state: &serde_json::Value,
existing_state: &serde_json::Value,
) -> Result<SetupStateCompatibility> {
// The Python target connector doesn't support state update yet.
Ok(SetupStateCompatibility::Compatible)
Ok(if desired_state == existing_state {
SetupStateCompatibility::Compatible
} else {
SetupStateCompatibility::PartialCompatible
})
}

fn describe_resource(&self, key: &serde_json::Value) -> Result<String> {
Expand Down
4 changes: 2 additions & 2 deletions src/ops/targets/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn bind_value_field<'arg>(
pub struct ExportContext {
db_ref: Option<spec::AuthEntryReference<DatabaseConnectionSpec>>,
db_pool: PgPool,
key_fields_schema: Vec<FieldSchema>,
key_fields_schema: Box<[FieldSchema]>,
value_fields_schema: Vec<FieldSchema>,
upsert_sql_prefix: String,
upsert_sql_suffix: String,
Expand All @@ -144,7 +144,7 @@ impl ExportContext {
db_ref: Option<spec::AuthEntryReference<DatabaseConnectionSpec>>,
db_pool: PgPool,
table_name: String,
key_fields_schema: Vec<FieldSchema>,
key_fields_schema: Box<[FieldSchema]>,
value_fields_schema: Vec<FieldSchema>,
) -> Result<Self> {
let key_fields = key_fields_schema
Expand Down
6 changes: 3 additions & 3 deletions src/ops/targets/shared/property_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<AuthEntry> std::fmt::Display for GraphElementType<AuthEntry> {

pub struct GraphElementSchema {
pub elem_type: ElementType,
pub key_fields: Vec<schema::FieldSchema>,
pub key_fields: Box<[schema::FieldSchema]>,
pub value_fields: Vec<schema::FieldSchema>,
}

Expand Down Expand Up @@ -256,7 +256,7 @@ impl GraphElementSchemaBuilder {
}
Ok(GraphElementSchema {
elem_type: self.elem_type,
key_fields: self.key_fields,
key_fields: self.key_fields.into(),
value_fields: self.value_fields,
})
}
Expand Down Expand Up @@ -349,7 +349,7 @@ pub struct DataCollectionGraphMappingInput<'a, AuthEntry> {
pub mapping: &'a GraphElementMapping,
pub index_options: &'a spec::IndexOptions,

pub key_fields_schema: Vec<FieldSchema>,
pub key_fields_schema: Box<[FieldSchema]>,
pub value_fields_schema: Vec<FieldSchema>,
}

Expand Down
2 changes: 2 additions & 0 deletions src/setup/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ pub struct TargetSetupStateCommon {
pub max_schema_version_id: i32,
#[serde(default)]
pub setup_by_user: bool,
#[serde(default)]
pub key_type: Option<Box<[schema::ValueType]>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down
Loading