Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/catalog/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::hash::{Hash, Hasher};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ColumnType {
Text,
U8,
Integer,
Float,
Boolean,
Expand Down Expand Up @@ -111,6 +112,7 @@ where
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Value {
Text(CompactString),
U8(u8),
Integer(i64),
Float(f64),
Boolean(bool),
Expand All @@ -135,6 +137,7 @@ impl Hash for Value {
self.kind_rank().hash(state);
match self {
Value::Text(v) => v.hash(state),
Value::U8(v) => v.hash(state),
Value::Integer(v) => v.hash(state),
Value::Float(v) => v.to_bits().hash(state),
Value::Boolean(v) => v.hash(state),
Expand Down Expand Up @@ -164,14 +167,15 @@ impl Value {
match self {
Value::Null => 0,
Value::Boolean(_) => 1,
Value::Integer(_) => 2,
Value::U256(_) => 3,
Value::I256(_) => 4,
Value::Timestamp(_) => 5,
Value::Float(_) => 6,
Value::Text(_) => 7,
Value::Json(_) => 8,
Value::Blob(_) => 9,
Value::U8(_) => 2,
Value::Integer(_) => 3,
Value::U256(_) => 4,
Value::I256(_) => 5,
Value::Timestamp(_) => 6,
Value::Float(_) => 7,
Value::Text(_) => 8,
Value::Json(_) => 9,
Value::Blob(_) => 10,
}
}
}
Expand Down Expand Up @@ -200,6 +204,7 @@ impl Ord for Value {
match (self, other) {
(Value::Null, Value::Null) => Ordering::Equal,
(Value::Boolean(a), Value::Boolean(b)) => a.cmp(b),
(Value::U8(a), Value::U8(b)) => a.cmp(b),
(Value::Integer(a), Value::Integer(b)) => a.cmp(b),
(Value::U256(a), Value::U256(b)) => a.cmp(b),
(Value::I256(a), Value::I256(b)) => a.cmp(b),
Expand All @@ -221,6 +226,7 @@ mod tests {
fn arb_value() -> impl Strategy<Value = Value> {
let leaf = prop_oneof![
any::<bool>().prop_map(Value::Boolean),
any::<u8>().prop_map(Value::U8),
any::<i64>().prop_map(Value::Integer),
prop::array::uniform32(any::<u8>()).prop_map(Value::U256),
prop::array::uniform32(any::<u8>()).prop_map(Value::I256),
Expand Down
24 changes: 19 additions & 5 deletions src/commit/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ fn validate_assertion(catalog: &Catalog, assertion: &ReadAssertion) -> Result<()
};
if !matches!(
col.col_type,
ColumnType::Integer | ColumnType::Float | ColumnType::U256 | ColumnType::Timestamp
ColumnType::U8
| ColumnType::Integer
| ColumnType::Float
| ColumnType::U256
| ColumnType::Timestamp
) {
return Err(AedbError::Validation(format!(
"column {column} is not numeric for SumCompare"
Expand Down Expand Up @@ -470,17 +474,25 @@ fn sum_rows_for_column<'a>(
) -> Result<Value, AedbError> {
let col_type = &schema.columns[column_idx].col_type;
match col_type {
ColumnType::Integer | ColumnType::Timestamp => {
ColumnType::U8 | ColumnType::Integer | ColumnType::Timestamp => {
let mut sum: i64 = 0;
for row in rows {
if !match_filter(row, schema, filter)? {
continue;
}
if let Some(Value::Integer(v) | Value::Timestamp(v)) = row.values.get(column_idx) {
sum = sum.checked_add(*v).ok_or(AedbError::Overflow)?;
if let Some(value) = row.values.get(column_idx) {
let addend = match value {
Value::U8(x) => *x as i64,
Value::Integer(x) | Value::Timestamp(x) => *x,
_ => continue,
};
sum = sum.checked_add(addend).ok_or(AedbError::Overflow)?;
}
}
if matches!(col_type, ColumnType::Timestamp) {
if matches!(col_type, ColumnType::U8) {
let as_u8 = u8::try_from(sum).map_err(|_| AedbError::Overflow)?;
Ok(Value::U8(as_u8))
} else if matches!(col_type, ColumnType::Timestamp) {
Ok(Value::Timestamp(sum))
} else {
Ok(Value::Integer(sum))
Expand Down Expand Up @@ -521,6 +533,7 @@ fn sum_rows_for_column<'a>(

fn zero_for_threshold(threshold: &Value) -> Value {
match threshold {
Value::U8(_) => Value::U8(0),
Value::Integer(_) => Value::Integer(0),
Value::Timestamp(_) => Value::Timestamp(0),
Value::Float(_) => Value::Float(0.0),
Expand Down Expand Up @@ -559,6 +572,7 @@ fn value_matches_type(value: &Value, col_type: &ColumnType) -> bool {
matches!(
(value, col_type),
(Value::Text(_), ColumnType::Text)
| (Value::U8(_), ColumnType::U8)
| (Value::Integer(_), ColumnType::Integer)
| (Value::Float(_), ColumnType::Float)
| (Value::Boolean(_), ColumnType::Boolean)
Expand Down
2 changes: 2 additions & 0 deletions src/commit/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ fn value_matches_type(value: &Value, ty: &ColumnType) -> bool {
matches!(
(value, ty),
(Value::Text(_), ColumnType::Text)
| (Value::U8(_), ColumnType::U8)
| (Value::Integer(_), ColumnType::Integer)
| (Value::Float(_), ColumnType::Float)
| (Value::Boolean(_), ColumnType::Boolean)
Expand All @@ -1267,6 +1268,7 @@ fn value_matches_type(value: &Value, ty: &ColumnType) -> bool {
fn value_type_name(value: &Value) -> &'static str {
match value {
Value::Text(_) => "Text",
Value::U8(_) => "U8",
Value::Integer(_) => "Integer",
Value::Float(_) => "Float",
Value::Boolean(_) => "Boolean",
Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,24 @@ pub struct QueryDiagnostics {
pub estimated_scan_rows: u64,
pub max_scan_rows: u64,
pub index_used: Option<String>,
pub selected_indexes: Vec<String>,
pub predicate_evaluation_path: PredicateEvaluationPath,
pub plan_trace: Vec<String>,
pub stages: Vec<ExecutionStage>,
pub bounded_by_limit_or_cursor: bool,
pub has_joins: bool,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PredicateEvaluationPath {
None,
PrimaryKeyEqLookup,
SecondaryIndexLookup,
AsyncIndexProjection,
FullScanFilter,
JoinExecution,
}

#[derive(Debug, Clone)]
pub struct QueryWithDiagnosticsResult {
pub result: QueryResult,
Expand Down
14 changes: 14 additions & 0 deletions src/lib_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ pub(crate) fn explain_query_against_view(
.clone()
.or_else(|| query.use_index.clone());
let bounded_by_limit_or_cursor = query.limit.is_some() || options.cursor.is_some();
let access_path = crate::query::executor::explain_access_path_for_query(
snapshot.as_ref(),
catalog.as_ref(),
project_id,
scope_id,
&query,
options,
)?;
if !query.joins.is_empty() {
let mut estimated = snapshot
.table(project_id, scope_id, &query.table)
Expand Down Expand Up @@ -111,6 +119,9 @@ pub(crate) fn explain_query_against_view(
estimated_scan_rows: estimated,
max_scan_rows: max_scan_rows as u64,
index_used,
selected_indexes: access_path.selected_indexes,
predicate_evaluation_path: access_path.predicate_evaluation_path,
plan_trace: access_path.plan_trace,
stages,
bounded_by_limit_or_cursor,
has_joins: true,
Expand Down Expand Up @@ -141,6 +152,9 @@ pub(crate) fn explain_query_against_view(
estimated_scan_rows,
max_scan_rows: max_scan_rows as u64,
index_used,
selected_indexes: access_path.selected_indexes,
predicate_evaluation_path: access_path.predicate_evaluation_path,
plan_trace: access_path.plan_trace,
stages: planned.stages,
bounded_by_limit_or_cursor,
has_joins: false,
Expand Down
Loading
Loading