MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / array_to_decoder

Function array_to_decoder

src/repr/src/row/encode.rs:1538–1753  ·  view source on GitHub ↗

Small helper function to downcast from an array to a [`DatumColumnDecoder`]. Note: it is _super_ important that we downcast as few times as possible. Datum encoding is a very hot path and downcasting is relatively slow

(
    array: &Arc<dyn Array>,
    col_ty: &SqlScalarType,
)

Source from the content-addressed store, hash-verified

1536/// Note: it is _super_ important that we downcast as few times as possible. Datum encoding is a
1537/// very hot path and downcasting is relatively slow
1538fn array_to_decoder(
1539 array: &Arc<dyn Array>,
1540 col_ty: &SqlScalarType,
1541) -> Result<DatumColumnDecoder, anyhow::Error> {
1542 let decoder = match (array.data_type(), col_ty) {
1543 (DataType::Boolean, SqlScalarType::Bool) => {
1544 let array = downcast_array::<BooleanArray>(array)?;
1545 DatumColumnDecoder::Bool(array.clone())
1546 }
1547 (DataType::UInt8, SqlScalarType::PgLegacyChar) => {
1548 let array = downcast_array::<UInt8Array>(array)?;
1549 DatumColumnDecoder::U8(array.clone())
1550 }
1551 (DataType::UInt16, SqlScalarType::UInt16) => {
1552 let array = downcast_array::<UInt16Array>(array)?;
1553 DatumColumnDecoder::U16(array.clone())
1554 }
1555 (
1556 DataType::UInt32,
1557 SqlScalarType::UInt32
1558 | SqlScalarType::Oid
1559 | SqlScalarType::RegClass
1560 | SqlScalarType::RegProc
1561 | SqlScalarType::RegType,
1562 ) => {
1563 let array = downcast_array::<UInt32Array>(array)?;
1564 DatumColumnDecoder::U32(array.clone())
1565 }
1566 (DataType::UInt64, SqlScalarType::UInt64) => {
1567 let array = downcast_array::<UInt64Array>(array)?;
1568 DatumColumnDecoder::U64(array.clone())
1569 }
1570 (DataType::Int16, SqlScalarType::Int16) => {
1571 let array = downcast_array::<Int16Array>(array)?;
1572 DatumColumnDecoder::I16(array.clone())
1573 }
1574 (DataType::Int32, SqlScalarType::Int32) => {
1575 let array = downcast_array::<Int32Array>(array)?;
1576 DatumColumnDecoder::I32(array.clone())
1577 }
1578 (DataType::Int64, SqlScalarType::Int64) => {
1579 let array = downcast_array::<Int64Array>(array)?;
1580 DatumColumnDecoder::I64(array.clone())
1581 }
1582 (DataType::Float32, SqlScalarType::Float32) => {
1583 let array = downcast_array::<Float32Array>(array)?;
1584 DatumColumnDecoder::F32(array.clone())
1585 }
1586 (DataType::Float64, SqlScalarType::Float64) => {
1587 let array = downcast_array::<Float64Array>(array)?;
1588 DatumColumnDecoder::F64(array.clone())
1589 }
1590 (DataType::Struct(_), SqlScalarType::Numeric { .. }) => {
1591 let array = downcast_array::<StructArray>(array)?;
1592 // Note: We only use the approx column for sorting, and ignore it
1593 // when decoding.
1594 let binary_values = array
1595 .column_by_name("binary")

Callers 1

newMethod · 0.85

Calls 15

StringClass · 0.85
TimestampTzClass · 0.85
data_typeMethod · 0.80
expectMethod · 0.80
enumerateMethod · 0.80
downcast_arrayFunction · 0.70
mask_nullsFunction · 0.70
NumericClass · 0.50
DateClass · 0.50
TimeClass · 0.50
TimestampClass · 0.50
MzTimestampInterface · 0.50

Tested by

no test coverage detected