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

Function cell_from_token

src/clusterd-test-driver/src/script.rs:236–261  ·  view source on GitHub ↗

Type a raw row-value token against its column into an owned [`Cell`]. The bare token `null` is SQL `NULL` (only in a nullable column); quote it (`"null"`) for the literal string. Numeric and boolean tokens go through [`mz_repr::strconv`] — the canonical PostgreSQL-compatible text parser the rest of the codebase uses — so the accepted syntax matches `mz_pgrepr`'s text decode. `string`/`bytes` colu

(token: &str, col: &SqlColumnType)

Source from the content-addressed store, hash-verified

234/// `string`/`bytes` columns take the (unquoted) token verbatim; `bytes` is its
235/// UTF-8 encoding.
236fn cell_from_token(token: &str, col: &SqlColumnType) -> anyhow::Result<Cell> {
237 if token == "null" {
238 anyhow::ensure!(col.nullable, "null value in non-nullable column");
239 return Ok(Cell::Null);
240 }
241 let parse =
242 |kind: &str, e: strconv::ParseError| anyhow::anyhow!("parsing {token:?} as {kind}: {e}");
243 let cell = match col.scalar_type {
244 SqlScalarType::Int16 => {
245 Cell::Int16(strconv::parse_int16(token).map_err(|e| parse("int16", e))?)
246 }
247 SqlScalarType::Int32 => {
248 Cell::Int32(strconv::parse_int32(token).map_err(|e| parse("int32", e))?)
249 }
250 SqlScalarType::Int64 => {
251 Cell::Int64(strconv::parse_int64(token).map_err(|e| parse("int64", e))?)
252 }
253 SqlScalarType::Bool => {
254 Cell::Bool(strconv::parse_bool(token).map_err(|e| parse("bool", e))?)
255 }
256 SqlScalarType::String => Cell::Str(unquote(token).to_string()),
257 SqlScalarType::Bytes => Cell::Bytes(unquote(token).as_bytes().to_vec()),
258 ref other => anyhow::bail!("unsupported column type {other:?}"),
259 };
260 Ok(cell)
261}
262
263/// Pack explicit row tokens against `desc`, validating arity per row.
264fn rows_from_tokens(desc: &RelationDesc, rows: &[Vec<String>]) -> anyhow::Result<Vec<Row>> {

Callers 1

rows_from_tokensFunction · 0.85

Calls 9

parse_int16Function · 0.85
parse_int32Function · 0.85
parse_int64Function · 0.85
parse_boolFunction · 0.85
to_vecMethod · 0.80
unquoteFunction · 0.70
parseFunction · 0.50
to_stringMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected