@@ -20,9 +20,11 @@ import java.util.{Arrays, Collections, Optional}
20
20
import scala .collection .JavaConverters ._
21
21
import scala .reflect .ClassTag
22
22
23
- import io .delta .kernel .data .{ColumnVector , ColumnarBatch }
23
+ import io .delta .kernel .data .{ColumnarBatch , ColumnVector }
24
+ import io .delta .kernel .exceptions .InvalidTableException
24
25
import io .delta .kernel .expressions .Predicate
25
26
import io .delta .kernel .internal .checkpoints .{CheckpointInstance , SidecarFile }
27
+ import io .delta .kernel .internal .fs .Path
26
28
import io .delta .kernel .internal .snapshot .{LogSegment , SnapshotManager }
27
29
import io .delta .kernel .internal .util .{FileNames , Utils }
28
30
import io .delta .kernel .test .{BaseMockJsonHandler , BaseMockParquetHandler , MockFileSystemClientUtils , VectorTestUtils }
@@ -37,70 +39,82 @@ class SnapshotManagerSuite extends AnyFunSuite with MockFileSystemClientUtils {
37
39
SnapshotManager .verifyDeltaVersions(
38
40
Collections .emptyList(),
39
41
Optional .empty(),
40
- Optional .empty())
42
+ Optional .empty(),
43
+ new Path (" /path/to/table" ))
41
44
// contiguous versions
42
45
SnapshotManager .verifyDeltaVersions(
43
46
Arrays .asList(1 , 2 , 3 ),
44
47
Optional .empty(),
45
- Optional .empty())
48
+ Optional .empty(),
49
+ new Path (" /path/to/table" ))
46
50
// contiguous versions with correct `expectedStartVersion` and `expectedStartVersion`
47
51
SnapshotManager .verifyDeltaVersions(
48
52
Arrays .asList(1 , 2 , 3 ),
49
53
Optional .empty(),
50
- Optional .of(3 ))
54
+ Optional .of(3 ),
55
+ new Path (" /path/to/table" ))
51
56
SnapshotManager .verifyDeltaVersions(
52
57
Arrays .asList(1 , 2 , 3 ),
53
58
Optional .of(1 ),
54
- Optional .empty())
59
+ Optional .empty(),
60
+ new Path (" /path/to/table" ))
55
61
SnapshotManager .verifyDeltaVersions(
56
62
Arrays .asList(1 , 2 , 3 ),
57
63
Optional .of(1 ),
58
- Optional .of(3 ))
64
+ Optional .of(3 ),
65
+ new Path (" /path/to/table" ))
59
66
// `expectedStartVersion` or `expectedEndVersion` doesn't match
60
67
intercept[IllegalArgumentException ] {
61
68
SnapshotManager .verifyDeltaVersions(
62
69
Arrays .asList(1 , 2 ),
63
70
Optional .of(0 ),
64
- Optional .empty())
71
+ Optional .empty(),
72
+ new Path (" /path/to/table" ))
65
73
}
66
74
intercept[IllegalArgumentException ] {
67
75
SnapshotManager .verifyDeltaVersions(
68
76
Arrays .asList(1 , 2 ),
69
77
Optional .empty(),
70
- Optional .of(3 ))
78
+ Optional .of(3 ),
79
+ new Path (" /path/to/table" ))
71
80
}
72
81
intercept[IllegalArgumentException ] {
73
82
SnapshotManager .verifyDeltaVersions(
74
83
Collections .emptyList(),
75
84
Optional .of(0 ),
76
- Optional .empty())
85
+ Optional .empty(),
86
+ new Path (" /path/to/table" ))
77
87
}
78
88
intercept[IllegalArgumentException ] {
79
89
SnapshotManager .verifyDeltaVersions(
80
90
Collections .emptyList(),
81
91
Optional .empty(),
82
- Optional .of(3 ))
92
+ Optional .of(3 ),
93
+ new Path (" /path/to/table" ))
83
94
}
84
95
// non contiguous versions
85
- intercept[IllegalStateException ] {
96
+ intercept[InvalidTableException ] {
86
97
SnapshotManager .verifyDeltaVersions(
87
98
Arrays .asList(1 , 3 ),
88
99
Optional .empty(),
89
- Optional .empty())
100
+ Optional .empty(),
101
+ new Path (" /path/to/table" ))
90
102
}
91
103
// duplicates in versions
92
- intercept[IllegalStateException ] {
104
+ intercept[InvalidTableException ] {
93
105
SnapshotManager .verifyDeltaVersions(
94
106
Arrays .asList(1 , 2 , 2 , 3 ),
95
107
Optional .empty(),
96
- Optional .empty())
108
+ Optional .empty(),
109
+ new Path (" /path/to/table" ))
97
110
}
98
111
// unsorted versions
99
- intercept[IllegalStateException ] {
112
+ intercept[InvalidTableException ] {
100
113
SnapshotManager .verifyDeltaVersions(
101
114
Arrays .asList(3 , 2 , 1 ),
102
115
Optional .empty(),
103
- Optional .empty())
116
+ Optional .empty(),
117
+ new Path (" /path/to/table" ))
104
118
}
105
119
}
106
120
@@ -631,11 +645,11 @@ class SnapshotManagerSuite extends AnyFunSuite with MockFileSystemClientUtils {
631
645
Seq (Optional .empty(), Optional .of(10L )): Seq [Optional [java.lang.Long ]]) {
632
646
for (startCheckpoint <-
633
647
Seq (Optional .empty(), Optional .of(10L )): Seq [Optional [java.lang.Long ]]) {
634
- testExpectedError[IllegalStateException ](
648
+ testExpectedError[InvalidTableException ](
635
649
files = singularCheckpointFileStatuses(Seq (10L )),
636
650
startCheckpoint = startCheckpoint,
637
651
versionToLoad = versionToLoad,
638
- expectedErrorMessageContains = " Could not find any delta files for version 10"
652
+ expectedErrorMessageContains = " Missing delta file for version 10"
639
653
)
640
654
}
641
655
}
@@ -645,60 +659,47 @@ class SnapshotManagerSuite extends AnyFunSuite with MockFileSystemClientUtils {
645
659
// checkpoint(10), 010.json, 011.json, 013.json
646
660
val fileList = deltaFileStatuses(Seq (10L , 11L )) ++ deltaFileStatuses(Seq (13L )) ++
647
661
singularCheckpointFileStatuses(Seq (10L ))
648
- testExpectedError[RuntimeException ](
662
+ testExpectedError[InvalidTableException ](
649
663
fileList,
650
- expectedErrorMessageContains = " Versions ([11, 13]) are not continuous "
664
+ expectedErrorMessageContains = " versions are not continuous: ([11, 13])"
651
665
)
652
- testExpectedError[RuntimeException ](
666
+ testExpectedError[InvalidTableException ](
653
667
fileList,
654
668
startCheckpoint = Optional .of(10 ),
655
- expectedErrorMessageContains = " Versions ([11, 13]) are not continuous "
669
+ expectedErrorMessageContains = " versions are not continuous: ([11, 13])"
656
670
)
657
- testExpectedError[RuntimeException ](
671
+ testExpectedError[InvalidTableException ](
658
672
fileList,
659
673
versionToLoad = Optional .of(13 ),
660
- expectedErrorMessageContains = " Versions ([11, 13]) are not continuous "
674
+ expectedErrorMessageContains = " versions are not continuous: ([11, 13])"
661
675
)
662
676
}
663
677
664
- // TODO address the inconsistent behaviors and throw better error messages for corrupt listings?
665
- // (delta-io/delta#2283)
666
678
test(" getLogSegmentForVersion: corrupt listing 000.json...009.json + checkpoint(10)" ) {
667
679
val fileList = deltaFileStatuses((0L until 10L )) ++ singularCheckpointFileStatuses(Seq (10L ))
668
680
669
681
/* ---------- version to load is 15 (greater than latest checkpoint/delta file) ---------- */
670
- testExpectedError[RuntimeException ](
682
+ testExpectedError[InvalidTableException ](
671
683
fileList,
672
684
versionToLoad = Optional .of(15 ),
673
- expectedErrorMessageContains = " Could not find any delta files for version 10"
685
+ expectedErrorMessageContains = " Missing delta file for version 10"
674
686
)
675
- testExpectedError[IllegalStateException ](
687
+ testExpectedError[InvalidTableException ](
676
688
fileList,
677
689
startCheckpoint = Optional .of(10 ),
678
690
versionToLoad = Optional .of(15 ),
679
- expectedErrorMessageContains = " Could not find any delta files for version 10"
691
+ expectedErrorMessageContains = " Missing delta file for version 10"
680
692
)
681
693
682
694
/* ---------- versionToLoad is latest (10) ---------- */
683
- // (?) fails when startCheckpoint is provided, passes when it's not
684
- testExpectedError[IllegalStateException ](
695
+ testExpectedError[InvalidTableException ](
685
696
fileList,
686
697
startCheckpoint = Optional .of(10 ),
687
- expectedErrorMessageContains = " Could not find any delta files for version 10"
688
- )
689
- val logSegment = snapshotManager.getLogSegmentForVersion(
690
- createMockFSListFromEngine(fileList),
691
- Optional .empty(),
692
- Optional .empty()
698
+ expectedErrorMessageContains = " Missing delta file for version 10"
693
699
)
694
- assert(logSegment.isPresent())
695
- checkLogSegment(
696
- logSegment.get(),
697
- 10 ,
698
- Seq .empty,
699
- singularCheckpointFileStatuses(Seq (10L )),
700
- Some (10 ),
701
- 90 // is the last available delta file
700
+ testExpectedError[InvalidTableException ](
701
+ fileList,
702
+ expectedErrorMessageContains = " Missing delta file for version 10"
702
703
)
703
704
}
704
705
@@ -718,41 +719,36 @@ class SnapshotManagerSuite extends AnyFunSuite with MockFileSystemClientUtils {
718
719
)
719
720
/* ---------- versionToLoad is 10 ---------- */
720
721
// (?) throws an error
721
- testExpectedError[IllegalStateException ](
722
+ testExpectedError[InvalidTableException ](
722
723
fileList,
723
724
versionToLoad = Optional .of(10 ),
724
- expectedErrorMessageContains = " Could not find any delta files for version 10"
725
+ expectedErrorMessageContains = " Missing delta file for version 10"
725
726
)
726
- testExpectedError[IllegalStateException ](
727
+ testExpectedError[InvalidTableException ](
727
728
fileList,
728
729
startCheckpoint = Optional .of(10 ),
729
730
versionToLoad = Optional .of(10 ),
730
- expectedErrorMessageContains = " Could not find any delta files for version 10"
731
+ expectedErrorMessageContains = " Missing delta file for version 10"
731
732
)
732
733
}
733
734
734
735
test(" getLogSegmentForVersion: corrupted log missing json files / no way to construct history" ) {
735
- def expectedErrorMessage (v : Int ): String = {
736
- s """ |Log file not found.
737
- |Expected: ${FileNames .deltaFile(logPath, 0 )}
738
- |Found: ${FileNames .deltaFile(logPath, v)}""" .stripMargin
739
- }
740
- testExpectedError[RuntimeException ](
736
+ testExpectedError[InvalidTableException ](
741
737
deltaFileStatuses(1L until 10L ),
742
- expectedErrorMessageContains = expectedErrorMessage( 1 )
738
+ expectedErrorMessageContains = " missing log file for version 0 "
743
739
)
744
- testExpectedError[RuntimeException ](
740
+ testExpectedError[InvalidTableException ](
745
741
deltaFileStatuses(15L until 25L ) ++ singularCheckpointFileStatuses(Seq (20L )),
746
742
versionToLoad = Optional .of(17 ),
747
- expectedErrorMessageContains = expectedErrorMessage( 15 )
743
+ expectedErrorMessageContains = " missing log file for version 0 "
748
744
)
749
- testExpectedError[RuntimeException ](
745
+ testExpectedError[InvalidTableException ](
750
746
deltaFileStatuses(15L until 25L ) ++ singularCheckpointFileStatuses(Seq (20L )),
751
747
startCheckpoint = Optional .of(20 ),
752
748
versionToLoad = Optional .of(17 ),
753
- expectedErrorMessageContains = expectedErrorMessage( 15 )
749
+ expectedErrorMessageContains = " missing log file for version 0 "
754
750
)
755
- testExpectedError[RuntimeException ](
751
+ testExpectedError[InvalidTableException ](
756
752
deltaFileStatuses((0L until 5L ) ++ (6L until 9L )),
757
753
expectedErrorMessageContains = " are not continuous"
758
754
)
@@ -761,11 +757,11 @@ class SnapshotManagerSuite extends AnyFunSuite with MockFileSystemClientUtils {
761
757
.map(p => FileStatus .of(p.toString, 10 , 10 ))
762
758
.take(4 )
763
759
val deltas = deltaFileStatuses(10L to 13L )
764
- testExpectedError[RuntimeException ](
760
+ testExpectedError[InvalidTableException ](
765
761
corruptedCheckpointStatuses ++ deltas,
766
762
Optional .empty(),
767
763
Optional .empty(),
768
- expectedErrorMessageContains = expectedErrorMessage( 10 )
764
+ expectedErrorMessageContains = " missing log file for version 0 "
769
765
)
770
766
}
771
767
0 commit comments