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

Method rows

src/environmentd/src/http/sql.rs:611–696  ·  view source on GitHub ↗

Convert adapter Row results into the web row result format. Error if the row format does not match the expected descriptor. TODO(aljoscha): Bail when max_result_size is exceeded.

(
        sender: &mut S,
        client: &mut SessionClient,
        mut rows_stream: RecordFirstRowStream,
        max_query_result_size: usize,
        desc: &RelationDesc,
    )

Source from the content-addressed store, hash-verified

609 /// match the expected descriptor.
610 // TODO(aljoscha): Bail when max_result_size is exceeded.
611 async fn rows<S>(
612 sender: &mut S,
613 client: &mut SessionClient,
614 mut rows_stream: RecordFirstRowStream,
615 max_query_result_size: usize,
616 desc: &RelationDesc,
617 ) -> Result<SqlResult, Error>
618 where
619 S: ResultSender,
620 {
621 let mut rows: Vec<Vec<serde_json::Value>> = vec![];
622 let mut datum_vec = mz_repr::DatumVec::new();
623 let types = &desc.typ().column_types;
624
625 let mut query_result_size = 0;
626
627 loop {
628 let peek_response = tokio::select! {
629 notice = client.session().recv_notice(), if S::SUPPORTS_STREAMING_NOTICES => {
630 sender.emit_streaming_notices(vec![notice]).await?;
631 continue;
632 }
633 e = sender.connection_error() => return Err(e),
634 r = rows_stream.recv() => {
635 match r {
636 Some(r) => r,
637 None => break,
638 }
639 },
640 };
641
642 let mut sql_rows = match peek_response {
643 PeekResponseUnary::Rows(rows) => rows,
644 PeekResponseUnary::Error(e) => {
645 return Ok(SqlResult::err(client, Error::Unstructured(anyhow!(e))));
646 }
647 PeekResponseUnary::DependencyDropped(dep) => {
648 return Ok(SqlResult::err(client, dep.to_concurrent_dependency_drop()));
649 }
650 PeekResponseUnary::Canceled => {
651 return Ok(SqlResult::err(client, AdapterError::Canceled));
652 }
653 };
654
655 if let Err(err) = verify_datum_desc(desc, &mut sql_rows) {
656 return Ok(SqlResult::Err {
657 error: err.into(),
658 notices: make_notices(client),
659 });
660 }
661
662 while let Some(row) = sql_rows.next() {
663 query_result_size += row.byte_len();
664 if query_result_size > max_query_result_size {
665 use bytesize::ByteSize;
666 return Ok(SqlResult::err(
667 client,
668 AdapterError::ResultSize(format!(

Callers 1

handle_rows_eventFunction · 0.80

Calls 14

verify_datum_descFunction · 0.85
make_noticesFunction · 0.85
borrow_withMethod · 0.80
enumerateMethod · 0.80
errFunction · 0.50
typMethod · 0.45
nextMethod · 0.45
byte_lenMethod · 0.45
pushMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected