@@ -29,7 +29,7 @@ use crate::schema::{DataType, SchemaRef, StructField, StructType, ToSchema as _}
2929use crate :: utils:: require;
3030use crate :: {
3131 DeltaResult , Engine , Error , Expression , FileMeta , Predicate , PredicateRef , RowVisitor ,
32- StorageHandler , Version , PRE_COMMIT_VERSION ,
32+ StorageHandler , Version ,
3333} ;
3434
3535mod domain_metadata_replay;
@@ -153,20 +153,45 @@ fn schema_to_is_not_null_predicate(schema: &StructType) -> Option<PredicateRef>
153153}
154154
155155impl LogSegment {
156- /// Creates a synthetic LogSegment for pre-commit transactions (e.g., create-table).
157- /// The sentinel version PRE_COMMIT_VERSION indicates no version exists yet on disk.
158- /// This is used to construct a pre-commit snapshot that provides table configuration
159- /// (protocol, metadata, schema) for operations like CTAS.
160- #[ allow( dead_code) ] // Used by create_table module
161- pub ( crate ) fn for_pre_commit ( log_root : Url ) -> Self {
162- use crate :: PRE_COMMIT_VERSION ;
163- Self {
164- end_version : PRE_COMMIT_VERSION ,
156+ /// Creates a LogSegment for a newly created table at version 0 from a single commit file.
157+ ///
158+ /// Normal log segments are built by listing files from storage and replaying them. For CREATE
159+ /// TABLE, the table has no prior log. We construct the segment directly from the just created
160+ /// commit file.
161+ ///
162+ /// # Errors
163+ ///
164+ /// Returns an `internal_error` if `commit_file` is not version 0 or not a commit file type.
165+ pub ( crate ) fn new_for_version_zero (
166+ log_root : Url ,
167+ commit_file : ParsedLogPath ,
168+ ) -> DeltaResult < Self > {
169+ require ! (
170+ commit_file. version == 0 ,
171+ crate :: Error :: internal_error( format!(
172+ "new_for_version_zero called with version {}" ,
173+ commit_file. version
174+ ) )
175+ ) ;
176+ require ! (
177+ commit_file. is_commit( ) ,
178+ crate :: Error :: internal_error( format!(
179+ "new_for_version_zero called with non-commit file type: {:?}" ,
180+ commit_file. file_type
181+ ) )
182+ ) ;
183+ Ok ( Self {
184+ end_version : commit_file. version ,
165185 checkpoint_version : None ,
166186 log_root,
167187 last_checkpoint_metadata : None ,
168- listed : LogSegmentFiles :: default ( ) ,
169- }
188+ listed : LogSegmentFiles {
189+ max_published_version : Some ( commit_file. version ) ,
190+ latest_commit_file : Some ( commit_file. clone ( ) ) ,
191+ ascending_commit_files : vec ! [ commit_file] ,
192+ ..Default :: default ( )
193+ } ,
194+ } )
170195 }
171196
172197 #[ internal_api]
@@ -1104,11 +1129,7 @@ impl LogSegment {
11041129 }
11051130
11061131 /// How many commits since a checkpoint, according to this log segment.
1107- /// Returns 0 for pre-commit snapshots (where end_version is PRE_COMMIT_VERSION).
11081132 pub ( crate ) fn commits_since_checkpoint ( & self ) -> u64 {
1109- if self . end_version == PRE_COMMIT_VERSION {
1110- return 0 ;
1111- }
11121133 // we can use 0 as the checkpoint version if there is no checkpoint since `end_version - 0`
11131134 // is the correct number of commits since a checkpoint if there are no checkpoints
11141135 let checkpoint_version = self . checkpoint_version . unwrap_or ( 0 ) ;
@@ -1117,11 +1138,7 @@ impl LogSegment {
11171138 }
11181139
11191140 /// How many commits since a log-compaction or checkpoint, according to this log segment.
1120- /// Returns 0 for pre-commit snapshots (where end_version is PRE_COMMIT_VERSION).
11211141 pub ( crate ) fn commits_since_log_compaction_or_checkpoint ( & self ) -> u64 {
1122- if self . end_version == PRE_COMMIT_VERSION {
1123- return 0 ;
1124- }
11251142 // Annoyingly we have to search all the compaction files to determine this, because we only
11261143 // sort by start version, so technically the max end version could be anywhere in the vec.
11271144 // We can return 0 in the case there is no compaction since end_version - 0 is the correct
0 commit comments