@@ -43,15 +43,15 @@ pub fn extract_primary_key(
4343#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Default ) ]
4444pub enum SourceVersionKind {
4545 #[ default]
46- NonExistent ,
46+ UnknownLogic ,
4747 DifferentLogic ,
4848 CurrentLogic ,
49- Deleted ,
49+ NonExistence ,
5050}
5151
5252#[ derive( Debug , Clone , Default ) ]
5353pub struct SourceVersion {
54- pub ordinal : Option < Ordinal > ,
54+ pub ordinal : Ordinal ,
5555 pub kind : SourceVersionKind ,
5656}
5757
@@ -62,7 +62,7 @@ impl SourceVersion {
6262 curr_fp : Fingerprint ,
6363 ) -> Self {
6464 Self {
65- ordinal : stored_ordinal . map ( Ordinal ) ,
65+ ordinal : Ordinal ( stored_ordinal ) ,
6666 kind : match & stored_fp {
6767 Some ( stored_fp) => {
6868 if stored_fp. as_slice ( ) == curr_fp. 0 . as_slice ( ) {
@@ -71,22 +71,26 @@ impl SourceVersion {
7171 SourceVersionKind :: DifferentLogic
7272 }
7373 }
74- None => SourceVersionKind :: NonExistent ,
74+ None => SourceVersionKind :: UnknownLogic ,
7575 } ,
7676 }
7777 }
7878
79- pub fn from_current ( ordinal : Option < Ordinal > ) -> Self {
79+ pub fn from_current ( ordinal : Ordinal ) -> Self {
8080 Self {
8181 ordinal,
8282 kind : SourceVersionKind :: CurrentLogic ,
8383 }
8484 }
8585
86- pub fn for_deletion ( & self ) -> Self {
86+ pub fn from_current_data ( data : & interface:: SourceData ) -> Self {
87+ let kind = match & data. value {
88+ interface:: SourceValue :: Existence ( _) => SourceVersionKind :: CurrentLogic ,
89+ interface:: SourceValue :: NonExistence => SourceVersionKind :: NonExistence ,
90+ } ;
8791 Self {
88- ordinal : self . ordinal ,
89- kind : SourceVersionKind :: Deleted ,
92+ ordinal : data . ordinal ,
93+ kind,
9094 }
9195 }
9296
@@ -95,7 +99,7 @@ impl SourceVersion {
9599 target : & SourceVersion ,
96100 update_stats : Option < & stats:: UpdateStats > ,
97101 ) -> bool {
98- let should_skip = match ( self . ordinal , target. ordinal ) {
102+ let should_skip = match ( self . ordinal . 0 , target. ordinal . 0 ) {
99103 ( Some ( orginal) , Some ( target_ordinal) ) => {
100104 orginal > target_ordinal || ( orginal == target_ordinal && self . kind >= target. kind )
101105 }
@@ -418,7 +422,7 @@ async fn commit_source_tracking_info(
418422 source_id,
419423 source_key_json,
420424 cleaned_staging_target_keys,
421- source_version. ordinal . map ( |o| o . into ( ) ) ,
425+ source_version. ordinal . into ( ) ,
422426 logic_fingerprint,
423427 precommit_metadata. process_ordinal ,
424428 process_timestamp. timestamp_micros ( ) ,
@@ -460,7 +464,7 @@ pub async fn evaluate_source_entry_with_memory(
460464 None
461465 } ;
462466 let memory = EvaluationMemory :: new ( chrono:: Utc :: now ( ) , stored_info, options) ;
463- let source_value = match src_eval_ctx
467+ let source_value = src_eval_ctx
464468 . import_op
465469 . executor
466470 . get_value (
@@ -471,19 +475,20 @@ pub async fn evaluate_source_entry_with_memory(
471475 } ,
472476 )
473477 . await ?
474- {
475- Some ( d) => d
476- . value
477- . ok_or_else ( || anyhow:: anyhow!( "value not returned" ) ) ?,
478- None => return Ok ( None ) ,
478+ . value
479+ . ok_or_else ( || anyhow:: anyhow!( "value not returned" ) ) ?;
480+ let output = match source_value {
481+ interface:: SourceValue :: Existence ( source_value) => {
482+ Some ( evaluate_source_entry ( src_eval_ctx, source_value, & memory) . await ?)
483+ }
484+ interface:: SourceValue :: NonExistence => None ,
479485 } ;
480- let output = evaluate_source_entry ( src_eval_ctx, source_value, & memory) . await ?;
481- Ok ( Some ( output) )
486+ Ok ( output)
482487}
483488
484489pub async fn update_source_row (
485490 src_eval_ctx : & SourceRowEvaluationContext < ' _ > ,
486- source_value : Option < FieldValues > ,
491+ source_value : interface :: SourceValue ,
487492 source_version : & SourceVersion ,
488493 pool : & PgPool ,
489494 update_stats : & stats:: UpdateStats ,
@@ -517,7 +522,7 @@ pub async fn update_source_row(
517522 None => Default :: default ( ) ,
518523 } ;
519524 let ( output, stored_mem_info) = match source_value {
520- Some ( source_value) => {
525+ interface :: SourceValue :: Existence ( source_value) => {
521526 let evaluation_memory = EvaluationMemory :: new (
522527 process_time,
523528 memoization_info,
@@ -530,7 +535,7 @@ pub async fn update_source_row(
530535 evaluate_source_entry ( src_eval_ctx, source_value, & evaluation_memory) . await ?;
531536 ( Some ( output) , evaluation_memory. into_stored ( ) ?)
532537 }
533- None => Default :: default ( ) ,
538+ interface :: SourceValue :: NonExistence => Default :: default ( ) ,
534539 } ;
535540
536541 // Phase 2 (precommit): Update with the memoization info and stage target keys.
@@ -601,7 +606,7 @@ pub async fn update_source_row(
601606
602607 if let Some ( existing_version) = existing_version {
603608 if output. is_some ( ) {
604- if source_version. ordinal . is_none ( )
609+ if ! source_version. ordinal . is_available ( )
605610 || source_version. ordinal != existing_version. ordinal
606611 {
607612 update_stats. num_updates . inc ( 1 ) ;
0 commit comments