Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Add TinyInt / i8 type #190

Merged
merged 32 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f41827d
feat: Add TinyInt / i8 type (WIP)
Ashu999 Sep 27, 2024
593c8a1
added a branch for handling TinyInt everywhere
Ashu999 Sep 27, 2024
fa1bfd3
handled more tinyInt,i8 cases and added tests (wip)
Ashu999 Sep 27, 2024
e57e1ad
handled all tinyInt cases and added tests
Ashu999 Sep 27, 2024
4c0e6ef
feat: Add TinyInt / i8 type (WIP)
Ashu999 Sep 27, 2024
67e84c7
added a branch for handling TinyInt everywhere
Ashu999 Sep 27, 2024
7fef8d8
handled more tinyInt,i8 cases and added tests (wip)
Ashu999 Sep 27, 2024
4ab705f
handled all tinyInt cases and added tests
Ashu999 Sep 27, 2024
f51d4e7
Merge branch 'main' of https://github.com/spaceandtimelabs/sxt-proof-…
Ashu999 Sep 28, 2024
7c3cda7
Merge branch 'main-TinyInt' of https://github.com/Ashu999/sxt-proof-o…
Ashu999 Sep 28, 2024
995c518
clippy, test passing
Ashu999 Sep 28, 2024
f46cc4b
added test and clippy fixes
Ashu999 Sep 28, 2024
5ba8f7e
Merge branch 'main' of https://github.com/spaceandtimelabs/sxt-proof-…
Ashu999 Sep 28, 2024
a313774
Merge branch 'main' of https://github.com/spaceandtimelabs/sxt-proof-…
Ashu999 Sep 29, 2024
e65dd9f
Merge branch 'main' into main-TinyInt
Dustin-Ray Oct 1, 2024
9cf76b0
test: added integration test for tinyint
Ashu999 Oct 2, 2024
a47ea02
Merge branch 'main-TinyInt' of https://github.com/Ashu999/sxt-proof-o…
Ashu999 Oct 2, 2024
172d510
spell fix
Ashu999 Oct 2, 2024
e6b8d7c
Merge branch 'main' into main-TinyInt
Dustin-Ray Oct 2, 2024
c93bfe6
Merge branch 'main' of https://github.com/spaceandtimelabs/sxt-proof-…
Ashu999 Oct 3, 2024
d3cd252
test fix
Ashu999 Oct 3, 2024
2b6ab8e
Merge branch 'main' into main-TinyInt
JayWhite2357 Oct 3, 2024
e65b2c1
Merge branch 'main' into main-TinyInt
Dustin-Ray Oct 3, 2024
ad31614
Update crates/proof-of-sql/tests/integration_tests.rs
Ashu999 Oct 3, 2024
7336fd3
Merge branch 'main' into main-TinyInt
Dustin-Ray Oct 3, 2024
861b52c
Merge branch 'main' into main-TinyInt
Dustin-Ray Oct 3, 2024
41644cc
Merge branch 'main' into main-TinyInt
Dustin-Ray Oct 4, 2024
af02964
Merge branch 'main' of https://github.com/spaceandtimelabs/sxt-proof-…
Ashu999 Oct 5, 2024
f8eb5fe
fix: clippy fix
Ashu999 Oct 5, 2024
9a25a18
Merge branch 'main-TinyInt' of https://github.com/Ashu999/sxt-proof-o…
Ashu999 Oct 5, 2024
8c83e7a
Merge branch 'main' into main-TinyInt
JayWhite2357 Oct 5, 2024
1eb4752
fixup! Merge branch 'main' into main-TinyInt
JayWhite2357 Oct 5, 2024
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
4 changes: 3 additions & 1 deletion crates/proof-of-sql/benches/bench_append_rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use proof_of_sql::{
database::{
owned_table_utility::{
bigint, boolean, decimal75, int, int128, owned_table, scalar, smallint,
timestamptz, varchar,
timestamptz, tinyint, varchar,
},
OwnedTable,
},
Expand Down Expand Up @@ -79,6 +79,7 @@ pub fn generate_random_owned_table<S: Scalar>(
"scalar",
"varchar",
"decimal75",
"tinyint",
"smallint",
"int",
"timestamptz",
Expand Down Expand Up @@ -111,6 +112,7 @@ pub fn generate_random_owned_table<S: Scalar>(
2,
vec![generate_random_u64_array(); num_rows],
)),
"tinyint" => columns.push(tinyint(identifier.deref(), vec![rng.gen::<i8>(); num_rows])),
"smallint" => columns.push(smallint(
identifier.deref(),
vec![rng.gen::<i16>(); num_rows],
Expand Down
34 changes: 34 additions & 0 deletions crates/proof-of-sql/src/base/commitment/column_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ pub struct ColumnBoundsMismatch {
pub enum ColumnBounds {
/// Column does not have order.
NoOrder,
/// The bounds of a TinyInt column.
TinyInt(Bounds<i8>),
/// The bounds of a SmallInt column.
SmallInt(Bounds<i16>),
/// The bounds of an Int column.
Expand All @@ -224,6 +226,7 @@ impl ColumnBounds {
#[must_use]
pub fn from_column(column: &CommittableColumn) -> ColumnBounds {
match column {
CommittableColumn::TinyInt(ints) => ColumnBounds::TinyInt(Bounds::from_iter(*ints)),
CommittableColumn::SmallInt(ints) => ColumnBounds::SmallInt(Bounds::from_iter(*ints)),
CommittableColumn::Int(ints) => ColumnBounds::Int(Bounds::from_iter(*ints)),
CommittableColumn::BigInt(ints) => ColumnBounds::BigInt(Bounds::from_iter(*ints)),
Expand All @@ -245,6 +248,9 @@ impl ColumnBounds {
pub fn try_union(self, other: Self) -> Result<Self, ColumnBoundsMismatch> {
match (self, other) {
(ColumnBounds::NoOrder, ColumnBounds::NoOrder) => Ok(ColumnBounds::NoOrder),
(ColumnBounds::TinyInt(bounds_a), ColumnBounds::TinyInt(bounds_b)) => {
Ok(ColumnBounds::TinyInt(bounds_a.union(bounds_b)))
}
(ColumnBounds::SmallInt(bounds_a), ColumnBounds::SmallInt(bounds_b)) => {
Ok(ColumnBounds::SmallInt(bounds_a.union(bounds_b)))
}
Expand Down Expand Up @@ -274,6 +280,9 @@ impl ColumnBounds {
pub fn try_difference(self, other: Self) -> Result<Self, ColumnBoundsMismatch> {
match (self, other) {
(ColumnBounds::NoOrder, ColumnBounds::NoOrder) => Ok(self),
(ColumnBounds::TinyInt(bounds_a), ColumnBounds::TinyInt(bounds_b)) => {
Ok(ColumnBounds::TinyInt(bounds_a.difference(bounds_b)))
}
(ColumnBounds::SmallInt(bounds_a), ColumnBounds::SmallInt(bounds_b)) => {
Ok(ColumnBounds::SmallInt(bounds_a.difference(bounds_b)))
}
Expand Down Expand Up @@ -499,6 +508,14 @@ mod tests {
let varchar_column_bounds = ColumnBounds::from_column(&committable_varchar_column);
assert_eq!(varchar_column_bounds, ColumnBounds::NoOrder);

let tinyint_column = OwnedColumn::<Curve25519Scalar>::TinyInt([1, 2, 3, 1, 0].to_vec());
let committable_tinyint_column = CommittableColumn::from(&tinyint_column);
let tinyint_column_bounds = ColumnBounds::from_column(&committable_tinyint_column);
assert_eq!(
tinyint_column_bounds,
ColumnBounds::TinyInt(Bounds::Sharp(BoundsInner { min: 0, max: 3 }))
);

let smallint_column = OwnedColumn::<Curve25519Scalar>::SmallInt([1, 2, 3, 1, 0].to_vec());
let committable_smallint_column = CommittableColumn::from(&smallint_column);
let smallint_column_bounds = ColumnBounds::from_column(&committable_smallint_column);
Expand Down Expand Up @@ -562,6 +579,13 @@ mod tests {
let no_order = ColumnBounds::NoOrder;
assert_eq!(no_order.try_union(no_order).unwrap(), no_order);

let tinyint_a = ColumnBounds::TinyInt(Bounds::Sharp(BoundsInner { min: 1, max: 3 }));
let tinyint_b = ColumnBounds::TinyInt(Bounds::Sharp(BoundsInner { min: 4, max: 6 }));
assert_eq!(
tinyint_a.try_union(tinyint_b).unwrap(),
ColumnBounds::TinyInt(Bounds::Sharp(BoundsInner { min: 1, max: 6 }))
);

let smallint_a = ColumnBounds::SmallInt(Bounds::Sharp(BoundsInner { min: 1, max: 3 }));
let smallint_b = ColumnBounds::SmallInt(Bounds::Sharp(BoundsInner { min: 4, max: 6 }));
assert_eq!(
Expand Down Expand Up @@ -609,6 +633,7 @@ mod tests {
#[test]
fn we_cannot_union_mismatched_column_bounds() {
let no_order = ColumnBounds::NoOrder;
let tinyint = ColumnBounds::TinyInt(Bounds::Sharp(BoundsInner { min: -3, max: 3 }));
let smallint = ColumnBounds::SmallInt(Bounds::Sharp(BoundsInner { min: -5, max: 5 }));
let int = ColumnBounds::Int(Bounds::Sharp(BoundsInner { min: -10, max: 10 }));
let bigint = ColumnBounds::BigInt(Bounds::Sharp(BoundsInner { min: 1, max: 3 }));
Expand All @@ -617,6 +642,7 @@ mod tests {

let bounds = [
(no_order, "NoOrder"),
(tinyint, "TinyInt"),
(smallint, "SmallInt"),
(int, "Int"),
(bigint, "BigInt"),
Expand Down Expand Up @@ -645,6 +671,10 @@ mod tests {
let no_order = ColumnBounds::NoOrder;
assert_eq!(no_order.try_difference(no_order).unwrap(), no_order);

let tinyint_a = ColumnBounds::TinyInt(Bounds::Sharp(BoundsInner { min: 1, max: 3 }));
let tinyint_b = ColumnBounds::TinyInt(Bounds::Empty);
assert_eq!(tinyint_a.try_difference(tinyint_b).unwrap(), tinyint_a);

let smallint_a = ColumnBounds::SmallInt(Bounds::Sharp(BoundsInner { min: 1, max: 3 }));
let smallint_b = ColumnBounds::SmallInt(Bounds::Empty);
assert_eq!(smallint_a.try_difference(smallint_b).unwrap(), smallint_a);
Expand Down Expand Up @@ -678,6 +708,7 @@ mod tests {
let bigint = ColumnBounds::BigInt(Bounds::Sharp(BoundsInner { min: 1, max: 3 }));
let int128 = ColumnBounds::Int128(Bounds::Sharp(BoundsInner { min: 4, max: 6 }));
let timestamp = ColumnBounds::TimestampTZ(Bounds::Sharp(BoundsInner { min: 4, max: 6 }));
let tinyint = ColumnBounds::TinyInt(Bounds::Sharp(BoundsInner { min: 1, max: 3 }));
let smallint = ColumnBounds::SmallInt(Bounds::Sharp(BoundsInner { min: 1, max: 3 }));

assert!(no_order.try_difference(bigint).is_err());
Expand All @@ -689,6 +720,9 @@ mod tests {
assert!(bigint.try_difference(int128).is_err());
assert!(int128.try_difference(bigint).is_err());

assert!(tinyint.try_difference(timestamp).is_err());
assert!(timestamp.try_difference(tinyint).is_err());

assert!(smallint.try_difference(timestamp).is_err());
assert!(timestamp.try_difference(smallint).is_err());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl ColumnCommitmentMetadata {
bounds: ColumnBounds,
) -> Result<ColumnCommitmentMetadata, InvalidColumnCommitmentMetadata> {
match (column_type, bounds) {
(ColumnType::SmallInt, ColumnBounds::SmallInt(_))
(ColumnType::TinyInt, ColumnBounds::TinyInt(_))
| (ColumnType::SmallInt, ColumnBounds::SmallInt(_))
| (ColumnType::Int, ColumnBounds::Int(_))
| (ColumnType::BigInt, ColumnBounds::BigInt(_))
| (ColumnType::Int128, ColumnBounds::Int128(_))
Expand Down Expand Up @@ -186,6 +187,18 @@ mod tests {

#[test]
fn we_can_construct_metadata() {
assert_eq!(
ColumnCommitmentMetadata::try_new(
ColumnType::TinyInt,
ColumnBounds::TinyInt(Bounds::Empty)
)
.unwrap(),
ColumnCommitmentMetadata {
column_type: ColumnType::TinyInt,
bounds: ColumnBounds::TinyInt(Bounds::Empty)
}
);

assert_eq!(
ColumnCommitmentMetadata::try_new(
ColumnType::SmallInt,
Expand Down Expand Up @@ -433,6 +446,17 @@ mod tests {
panic!("Bounds constructed from nonempty BigInt column should be ColumnBounds::Int(Bounds::Sharp(_))");
}

let tinyint_column = OwnedColumn::<Curve25519Scalar>::TinyInt([1, 2, 3, 1, 0].to_vec());
let committable_tinyint_column = CommittableColumn::from(&tinyint_column);
let tinyint_metadata = ColumnCommitmentMetadata::from_column(&committable_tinyint_column);
assert_eq!(tinyint_metadata.column_type(), &ColumnType::TinyInt);
if let ColumnBounds::TinyInt(Bounds::Sharp(bounds)) = tinyint_metadata.bounds() {
assert_eq!(bounds.min(), &0);
assert_eq!(bounds.max(), &3);
} else {
panic!("Bounds constructed from nonempty BigInt column should be ColumnBounds::TinyInt(Bounds::Sharp(_))");
}

let smallint_column = OwnedColumn::<Curve25519Scalar>::SmallInt([1, 2, 3, 1, 0].to_vec());
let committable_smallint_column = CommittableColumn::from(&smallint_column);
let smallint_metadata = ColumnCommitmentMetadata::from_column(&committable_smallint_column);
Expand Down Expand Up @@ -501,6 +525,18 @@ mod tests {
);

// Ordered case
let ints = [1, 2, 3, 1, 0];
let tinyint_column_a = CommittableColumn::TinyInt(&ints[..2]);
let tinyint_metadata_a = ColumnCommitmentMetadata::from_column(&tinyint_column_a);
let tinyint_column_b = CommittableColumn::TinyInt(&ints[2..]);
let tinyint_metadata_b = ColumnCommitmentMetadata::from_column(&tinyint_column_b);
let tinyint_column_c = CommittableColumn::TinyInt(&ints);
let tinyint_metadata_c = ColumnCommitmentMetadata::from_column(&tinyint_column_c);
assert_eq!(
tinyint_metadata_a.try_union(tinyint_metadata_b).unwrap(),
tinyint_metadata_c
);

let ints = [1, 2, 3, 1, 0];
let smallint_column_a = CommittableColumn::SmallInt(&ints[..2]);
let smallint_metadata_a = ColumnCommitmentMetadata::from_column(&smallint_column_a);
Expand Down Expand Up @@ -647,6 +683,43 @@ mod tests {
);
}

#[test]
fn we_can_difference_tinyint_matching_metadata() {
// Ordered case
let tinyints = [1, 2, 3, 1, 0];
let tinyint_column_a = CommittableColumn::TinyInt(&tinyints[..2]);
let tinyint_metadata_a = ColumnCommitmentMetadata::from_column(&tinyint_column_a);
let tinyint_column_b = CommittableColumn::TinyInt(&tinyints);
let tinyint_metadata_b = ColumnCommitmentMetadata::from_column(&tinyint_column_b);

let b_difference_a = tinyint_metadata_b
.try_difference(tinyint_metadata_a)
.unwrap();
assert_eq!(b_difference_a.column_type, ColumnType::TinyInt);
if let ColumnBounds::TinyInt(Bounds::Bounded(bounds)) = b_difference_a.bounds() {
assert_eq!(bounds.min(), &0);
assert_eq!(bounds.max(), &3);
} else {
panic!("difference of overlapping bounds should be Bounded");
}

let tinyint_column_empty = CommittableColumn::TinyInt(&[]);
let tinyint_metadata_empty = ColumnCommitmentMetadata::from_column(&tinyint_column_empty);

assert_eq!(
tinyint_metadata_b
.try_difference(tinyint_metadata_empty)
.unwrap(),
tinyint_metadata_b
);
assert_eq!(
tinyint_metadata_empty
.try_difference(tinyint_metadata_b)
.unwrap(),
tinyint_metadata_empty
);
}

#[test]
fn we_can_difference_smallint_matching_metadata() {
// Ordered case
Expand Down Expand Up @@ -729,6 +802,10 @@ mod tests {
column_type: ColumnType::Scalar,
bounds: ColumnBounds::NoOrder,
};
let tinyint_metadata = ColumnCommitmentMetadata {
iajoiner marked this conversation as resolved.
Show resolved Hide resolved
column_type: ColumnType::TinyInt,
bounds: ColumnBounds::TinyInt(Bounds::Empty),
};
let smallint_metadata = ColumnCommitmentMetadata {
column_type: ColumnType::SmallInt,
bounds: ColumnBounds::SmallInt(Bounds::Empty),
Expand All @@ -750,6 +827,18 @@ mod tests {
bounds: ColumnBounds::Int128(Bounds::Empty),
};

assert!(tinyint_metadata.try_union(scalar_metadata).is_err());
assert!(scalar_metadata.try_union(tinyint_metadata).is_err());

assert!(tinyint_metadata.try_union(decimal75_metadata).is_err());
assert!(decimal75_metadata.try_union(tinyint_metadata).is_err());

assert!(tinyint_metadata.try_union(varchar_metadata).is_err());
assert!(varchar_metadata.try_union(tinyint_metadata).is_err());

assert!(tinyint_metadata.try_union(boolean_metadata).is_err());
assert!(boolean_metadata.try_union(tinyint_metadata).is_err());

assert!(smallint_metadata.try_union(scalar_metadata).is_err());
assert!(scalar_metadata.try_union(smallint_metadata).is_err());

Expand Down
Loading
Loading