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

Function snapshot_size

src/sql-server-util/src/inspect.rs:875–903  ·  view source on GitHub ↗

Returns the total number of rows present in the specified table.

(
    client: &mut Client,
    schema: &str,
    table: &str,
)

Source from the content-addressed store, hash-verified

873
874/// Returns the total number of rows present in the specified table.
875pub async fn snapshot_size(
876 client: &mut Client,
877 schema: &str,
878 table: &str,
879) -> Result<usize, SqlServerError> {
880 let query = format!(
881 "SELECT COUNT(*) FROM {schema_name}.{table_name};",
882 schema_name = quote_identifier(schema),
883 table_name = quote_identifier(table)
884 );
885 let result = client.query(query, &[]).await?;
886
887 match &result[..] {
888 [row] => match row.try_get::<i32, _>(0)? {
889 Some(count @ 0..) => Ok(usize::try_from(count).expect("known to fit")),
890 Some(negative) => Err(SqlServerError::InvalidData {
891 column_name: "count".to_string(),
892 error: format!("found negative count: {negative}"),
893 }),
894 None => Err(SqlServerError::InvalidData {
895 column_name: "count".to_string(),
896 error: "expected a value found NULL".to_string(),
897 }),
898 },
899 other => Err(SqlServerError::InvariantViolated(format!(
900 "expected one row, got {other:?}"
901 ))),
902 }
903}
904
905/// Helper function to parse an expected result from a "system" query.
906fn check_system_result<'a, T>(

Callers 1

renderFunction · 0.85

Calls 3

expectMethod · 0.80
queryMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected