springql_core/api/
spring_sink_row.rs

1// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details.
2
3use crate::{
4    api::{
5        error::{Result, SpringError},
6        spring_source_row::SpringSourceRow,
7    },
8    stream_engine::{autonomous_executor::SchemalessRow, SpringValue, SqlValue},
9};
10
11/// Row object from an in memory sink queue.
12#[derive(Debug)]
13pub struct SpringSinkRow(SchemalessRow);
14
15impl SpringSinkRow {
16    pub(crate) fn new(row: SchemalessRow) -> Self {
17        SpringSinkRow(row)
18    }
19
20    /// Get a i-th column value from the row.
21    ///
22    /// # Failure
23    ///
24    /// - [SpringError::Sql](crate::api::error::SpringError::Sql) when:
25    ///   - Column index out of range
26    /// - [SpringError::Null](crate::api::error::SpringError::Null) when:
27    ///   - Column value is NULL
28    pub fn get_not_null_by_index<T>(&self, i_col: usize) -> Result<T>
29    where
30        T: SpringValue,
31    {
32        let sql_value = self.0.get_by_index(i_col)?;
33
34        match sql_value {
35            SqlValue::Null => Err(SpringError::Null { i_col }),
36            SqlValue::NotNull(nn_sql_value) => nn_sql_value.unpack(),
37        }
38    }
39}
40
41impl From<SpringSinkRow> for SpringSourceRow {
42    fn from(sink_row: SpringSinkRow) -> Self {
43        SpringSourceRow::new(sink_row.0)
44    }
45}