@@ -22,13 +22,16 @@ use crate::bindings::_helpers::compiled_views::compiled_model_view::NativeCompil
2222use crate :: bindings:: _helpers:: compiled_views:: model_input_view:: ModelInputRecord ;
2323use crate :: bindings:: _helpers:: compiled_views:: project_view:: NativeProjectView ;
2424
25+ /// Each model's snapshot node, and the `columns` document: per node key, each column's
26+ /// expression range. The ranges stay out of the node, so they never change a node's identity.
2527pub ( crate ) fn model_nodes (
2628 py : Python < ' _ > ,
2729 project : & NativeProjectView ,
2830 owner : & NativeCompiledProject ,
2931 mut nodes : BTreeMap < String , SnapshotNode > ,
30- ) -> PyResult < BTreeMap < String , SnapshotNode > > {
32+ ) -> PyResult < ( BTreeMap < String , SnapshotNode > , Map < String , Value > ) > {
3133 let dialect: Option < String > = project. sql_analysis_dialect ( ) ;
34+ let mut columns_document: Map < String , Value > = Map :: new ( ) ;
3235 for model in project. models ( py) . bind ( py) . iter ( ) {
3336 let model = model. cast :: < NativeCompiledModel > ( ) ?. get ( ) ;
3437 let ( name, _, _) = model. file_texts ( py) ?;
@@ -39,7 +42,7 @@ pub(crate) fn model_nodes(
3942 "model config cannot be represented in snapshot metadata" ,
4043 ) ) ;
4144 }
42- let mut definition = model. read ( py, |input, _| {
45+ let ( mut definition, ranges ) = model. read ( py, |input, _| {
4346 let record = input
4447 . compiled
4548 . as_ref ( )
@@ -54,7 +57,7 @@ pub(crate) fn model_nodes(
5457 json ! ( { "name" : name, "type" : data_type, "nullability" : nullability} )
5558 } )
5659 . collect ( ) ;
57- let mut definition: Value = json ! ( {
60+ let definition: Value = json ! ( {
5861 "name" : facts. name,
5962 "path" : facts. relative_path,
6063 "config" : facts. config. values,
@@ -67,11 +70,11 @@ pub(crate) fn model_nodes(
6770 ( Some ( dialect) , Some ( lineage) ) => expression_ranges ( dialect, input, facts, lineage) ,
6871 _ => Map :: new ( ) ,
6972 } ;
70- if !ranges. is_empty ( ) {
71- definition[ "expression_ranges" ] = Value :: Object ( ranges) ;
72- }
73- Ok ( definition)
73+ Ok ( ( definition, ranges) )
7474 } ) ?;
75+ if !ranges. is_empty ( ) {
76+ columns_document. insert ( format ! ( "model:{}" , facts. name) , Value :: Object ( ranges) ) ;
77+ }
7578 definition[ "destination" ] = model. read_destination ( py, |value| Ok ( destination ( value) ) ) ?;
7679 nodes = insert_node (
7780 nodes,
@@ -85,11 +88,12 @@ pub(crate) fn model_nodes(
8588 } ,
8689 ) ?;
8790 }
88- Ok ( nodes)
91+ Ok ( ( nodes, columns_document ) )
8992}
9093
91- /// Each output column's defining expression as a `[start, end)` byte range of the compiled SQL
92- /// the node SQL read returns; empty when the analysis SQL cannot be rebuilt exactly.
94+ /// Each output column's defining expression as `{"expression_range": [start, end)}`, byte
95+ /// offsets in the compiled SQL the node SQL read returns; empty when the analysis SQL cannot be
96+ /// rebuilt exactly.
9397fn expression_ranges (
9498 dialect : & str ,
9599 input : & ModelInputRecord ,
@@ -127,7 +131,7 @@ fn expression_ranges(
127131 if let Some ( ( start, end) ) = range {
128132 ranges
129133 . entry ( output_column. clone ( ) )
130- . or_insert_with ( || json ! ( [ start, end] ) ) ;
134+ . or_insert_with ( || json ! ( { "expression_range" : [ start, end] } ) ) ;
131135 }
132136 }
133137 ranges
0 commit comments