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

trait ReadColumn, to read a single column from a RowRef #789

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

gefjon
Copy link
Contributor

@gefjon gefjon commented Feb 5, 2024

Description of Changes

This commit defines trait ReadColumn, which is implemented for types that can be stored in a table column and can be read out of said table column.

Its interesting method is read_column(row: RowRef<'_>, idx: usize) -> Result<Self, TypeError>, which attempts to read the idxth column of row as a value of type Self, returning a TypeError if the row in question does not have the appropriate types.

ReadColumn is implemented for Rust equivalents of all non-compound AlgebraicTypes, i.e. integers, floats, bool and String. It is also implemented for all SATS value types, including those which represent values of compound types, i.e. AlgebraicValue, ProductValue, SumValue, ArrayValue and MapValue.

Note that this commit does not use the ReadColumn interface anywhere, except in tests. Follow-ups will use ReadColumn in various places, including:

  • Interacting with system table rows in the datastore.
  • Filtering rows in datastore iterators.
  • Filtering rows in the VM.
  • Inserting into indexes.

API and ABI breaking changes

None.

Expected complexity level and risk

3: non-trivial uses of unsafe; new uses of existing bflatn_from serialization.

This commit defines `trait ReadColumn`,
which is implemented for types that can be stored in a table column
and can be read out of said table column.

Its interesting method is
`read_column(row: RowRef<'_>, idx: usize) -> Result<Self, TypeError>`,
which attempts to read the `idx`th column of `row` as a value of type `Self`,
returning a `TypeError` if the row in question does not have the appropriate types.

`ReadColumn` is implemented for Rust equivalents of all non-compound `AlgebraicType`s,
i.e. integers, floats, `bool` and `String`.
It is also implemented for all SATS value types,
including those which represent values of compound types,
i.e. `AlgebraicValue`, `ProductValue`, `SumValue`, `ArrayValue` and `MapValue`.
@gefjon gefjon requested a review from kazimuth February 5, 2024 15:30
@gefjon
Copy link
Contributor Author

gefjon commented Feb 5, 2024

Also note that I ran the read_column tests under Miri, except:

  • I changed the ProptestConfig to only 16 cases.
  • I disabled read_column_long_string, since large blobs require blake3, which uses SIMD intrinsics and therefore doesn't work on Miri.

Other than that, the Miri tests passed (after about half an hour).

assert_wrong_type_error::<f32>(row_ref, idx, &col_ty.algebraic_type, AlgebraicType::F32)?;
assert_wrong_type_error::<f64>(row_ref, idx, &col_ty.algebraic_type, AlgebraicType::F64)?;
assert_wrong_type_error::<bool>(row_ref, idx, &col_ty.algebraic_type, AlgebraicType::Bool)?;
assert_wrong_type_error::<String>(row_ref, idx, &col_ty.algebraic_type, AlgebraicType::String)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's an entertaining pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell I miss Common Lisp having types at runtime?

Copy link
Contributor

@kazimuth kazimuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, clean tests and macros.

This is one of those things that seems particularly jittable. That ProductTypeElementLayout could be a compile time parameter.

@gefjon gefjon added this pull request to the merge queue Feb 5, 2024
Merged via the queue into master with commit cf6aa6d Feb 5, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants