Skip to content

Commit d7237c6

Browse files
committed
Revert "remove unnecessary methods"
This reverts commit e79251b.
1 parent be99eca commit d7237c6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/common/src/array/stream_record.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::convert::Infallible;
16+
1517
use auto_enums::auto_enum;
1618

1719
use super::StreamChunk;
@@ -76,6 +78,28 @@ impl<R> Record<R> {
7678
Record::Update { old_row, new_row } => Record::Update { old_row, new_row },
7779
}
7880
}
81+
82+
/// Try mapping the row in the record to another row, returning error if any of the mapping fails.
83+
pub fn try_map<R2, E>(self, f: impl Fn(R) -> Result<R2, E>) -> Result<Record<R2>, E> {
84+
Ok(match self {
85+
Record::Insert { new_row } => Record::Insert {
86+
new_row: f(new_row)?,
87+
},
88+
Record::Delete { old_row } => Record::Delete {
89+
old_row: f(old_row)?,
90+
},
91+
Record::Update { old_row, new_row } => Record::Update {
92+
old_row: f(old_row)?,
93+
new_row: f(new_row)?,
94+
},
95+
})
96+
}
97+
98+
/// Map the row in the record to another row.
99+
pub fn map<R2>(self, f: impl Fn(R) -> R2) -> Record<R2> {
100+
let Ok(record) = self.try_map::<R2, Infallible>(|row| Ok(f(row)));
101+
record
102+
}
79103
}
80104

81105
impl<R: Row> Record<R> {

0 commit comments

Comments
 (0)