MCPcopy Create free account
hub / github.com/apache/paimon-rust / parse_number_datum

Function parse_number_datum

crates/integrations/datafusion/src/sql_context.rs:1882–1923  ·  view source on GitHub ↗
(n: &str, data_type: &PaimonDataType, negate: bool)

Source from the content-addressed store, hash-verified

1880}
1881
1882fn parse_number_datum(n: &str, data_type: &PaimonDataType, negate: bool) -> DFResult<Datum> {
1883 let s: String = if negate {
1884 format!("-{n}")
1885 } else {
1886 n.to_string()
1887 };
1888 match data_type {
1889 PaimonDataType::TinyInt(_) => {
1890 Ok(Datum::TinyInt(s.parse::<i8>().map_err(|e| {
1891 DataFusionError::Plan(format!("Invalid TINYINT: {e}"))
1892 })?))
1893 }
1894 PaimonDataType::SmallInt(_) => {
1895 Ok(Datum::SmallInt(s.parse::<i16>().map_err(|e| {
1896 DataFusionError::Plan(format!("Invalid SMALLINT: {e}"))
1897 })?))
1898 }
1899 PaimonDataType::Int(_) => {
1900 Ok(Datum::Int(s.parse::<i32>().map_err(|e| {
1901 DataFusionError::Plan(format!("Invalid INT: {e}"))
1902 })?))
1903 }
1904 PaimonDataType::BigInt(_) => {
1905 Ok(Datum::Long(s.parse::<i64>().map_err(|e| {
1906 DataFusionError::Plan(format!("Invalid BIGINT: {e}"))
1907 })?))
1908 }
1909 PaimonDataType::Float(_) => {
1910 Ok(Datum::Float(s.parse::<f32>().map_err(|e| {
1911 DataFusionError::Plan(format!("Invalid FLOAT: {e}"))
1912 })?))
1913 }
1914 PaimonDataType::Double(_) => {
1915 Ok(Datum::Double(s.parse::<f64>().map_err(|e| {
1916 DataFusionError::Plan(format!("Invalid DOUBLE: {e}"))
1917 })?))
1918 }
1919 _ => Err(DataFusionError::Plan(format!(
1920 "Cannot convert {n} to {data_type:?}"
1921 ))),
1922 }
1923}
1924
1925/// Append static partition columns to a RecordBatch.
1926fn append_partition_columns(

Callers 1

sql_expr_to_datumFunction · 0.85

Calls 1

PlanClass · 0.50

Tested by

no test coverage detected