@@ -38,6 +38,21 @@ import org.apache.spark.sql.delta.storage.dv.HadoopFileSystemDVStore
3838import org .apache .spark .sql .sources ._
3939
4040object RapidsDeletionVectors extends Logging {
41+ private def dvDescAndFilterType (
42+ dvDescriptorOpt : Option [String ],
43+ filterTypeOpt : Option [RowIndexFilterType ])
44+ : Option [(DeletionVectorDescriptor , RowIndexFilterType )] = {
45+ (dvDescriptorOpt, filterTypeOpt) match {
46+ case (Some (dvDescriptor), Some (filterType)) =>
47+ Some ((DeletionVectorDescriptor .deserializeFromBase64(dvDescriptor), filterType))
48+ case (None , None ) =>
49+ None
50+ case (Some (_), None ) | (None , Some (_)) =>
51+ throw new IllegalStateException (
52+ " Both dvDescriptorOpt and filterTypeOpt must be defined together or both absent." )
53+ }
54+ }
55+
4156 /**
4257 * Translates the filter to use physical column names instead of logical column names.
4358 * This is needed when the column mapping mode is set to `NameMapping` or `IdMapping`
@@ -111,26 +126,22 @@ object RapidsDeletionVectors extends Logging {
111126 dvDescriptorOpt : Option [String ],
112127 filterTypeOpt : Option [RowIndexFilterType ],
113128 tablePath : String ): HostMemoryBuffer = {
114- if (dvDescriptorOpt.isDefined && filterTypeOpt.isDefined) {
115- val dvDesc = DeletionVectorDescriptor .deserializeFromBase64(dvDescriptorOpt.get)
116-
117- // The bitmap represents marked row indexes. The filter type determines whether those
118- // rows are removed or retained.
119- // See [[RowIndexFilterType]] for more details.
120- filterTypeOpt.get match {
121- case RowIndexFilterType .IF_CONTAINED | RowIndexFilterType .IF_NOT_CONTAINED =>
122- val storedBitmap = RapidsDeletionVectorStoredBitmap (dvDesc, new Path (tablePath))
123- storedBitmap.load(fileIO)
124- case unexpectedFilterType => throw new IllegalStateException (
125- s " Unexpected row index filter type for Deletion Vectors. " +
126- s " Expected: ${RowIndexFilterType .IF_CONTAINED } or " +
127- s " ${RowIndexFilterType .IF_NOT_CONTAINED }; Actual: ${unexpectedFilterType}" )
128- }
129- } else if (dvDescriptorOpt.isDefined || filterTypeOpt.isDefined) {
130- throw new IllegalStateException (
131- " Both dvDescriptorOpt and filterTypeOpt must be defined together or both absent." )
132- } else {
133- RapidsDeletionVectorStoredBitmap .serializedEmptyBitmap()
129+ dvDescAndFilterType(dvDescriptorOpt, filterTypeOpt) match {
130+ case Some ((dvDesc, filterType)) =>
131+ // The bitmap represents marked row indexes. The filter type determines whether those
132+ // rows are removed or retained.
133+ // See [[RowIndexFilterType]] for more details.
134+ filterType match {
135+ case RowIndexFilterType .IF_CONTAINED | RowIndexFilterType .IF_NOT_CONTAINED =>
136+ val storedBitmap = RapidsDeletionVectorStoredBitmap (dvDesc, new Path (tablePath))
137+ storedBitmap.load(fileIO)
138+ case unexpectedFilterType => throw new IllegalStateException (
139+ s " Unexpected row index filter type for Deletion Vectors. " +
140+ s " Expected: ${RowIndexFilterType .IF_CONTAINED } or " +
141+ s " ${RowIndexFilterType .IF_NOT_CONTAINED }; Actual: ${unexpectedFilterType}" )
142+ }
143+ case None =>
144+ RapidsDeletionVectorStoredBitmap .serializedEmptyBitmap()
134145 }
135146 }
136147
@@ -151,26 +162,22 @@ object RapidsDeletionVectors extends Logging {
151162 dvDescriptorOpt : Option [String ],
152163 filterTypeOpt : Option [RowIndexFilterType ],
153164 tablePath : String ): RoaringBitmapArray = {
154- if (dvDescriptorOpt.isDefined && filterTypeOpt.isDefined) {
155- val dvDesc = DeletionVectorDescriptor .deserializeFromBase64(dvDescriptorOpt.get)
156-
157- // The bitmap represents marked row indexes. The filter type determines whether those
158- // rows are removed or retained.
159- // See [[RowIndexFilterType]] for more details.
160- filterTypeOpt.get match {
161- case RowIndexFilterType .IF_CONTAINED | RowIndexFilterType .IF_NOT_CONTAINED =>
162- val dvStore = new HadoopFileSystemDVStore (conf)
163- StoredBitmap .create(dvDesc, new Path (tablePath)).load(dvStore)
164- case unexpectedFilterType => throw new IllegalStateException (
165- s " Unexpected row index filter type for Deletion Vectors. " +
166- s " Expected: ${RowIndexFilterType .IF_CONTAINED } or " +
167- s " ${RowIndexFilterType .IF_NOT_CONTAINED }; Actual: ${unexpectedFilterType}" )
168- }
169- } else if (dvDescriptorOpt.isDefined || filterTypeOpt.isDefined) {
170- throw new IllegalStateException (
171- " Both dvDescriptorOpt and filterTypeOpt must be defined together or both absent." )
172- } else {
173- new RoaringBitmapArray ()
165+ dvDescAndFilterType(dvDescriptorOpt, filterTypeOpt) match {
166+ case Some ((dvDesc, filterType)) =>
167+ // The bitmap represents marked row indexes. The filter type determines whether those
168+ // rows are removed or retained.
169+ // See [[RowIndexFilterType]] for more details.
170+ filterType match {
171+ case RowIndexFilterType .IF_CONTAINED | RowIndexFilterType .IF_NOT_CONTAINED =>
172+ val dvStore = new HadoopFileSystemDVStore (conf)
173+ StoredBitmap .create(dvDesc, new Path (tablePath)).load(dvStore)
174+ case unexpectedFilterType => throw new IllegalStateException (
175+ s " Unexpected row index filter type for Deletion Vectors. " +
176+ s " Expected: ${RowIndexFilterType .IF_CONTAINED } or " +
177+ s " ${RowIndexFilterType .IF_NOT_CONTAINED }; Actual: ${unexpectedFilterType}" )
178+ }
179+ case None =>
180+ new RoaringBitmapArray ()
174181 }
175182 }
176183
0 commit comments