Skip to content
Open
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
6 changes: 5 additions & 1 deletion lang/cpp/src/dtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ DataType binary(bool nullable) {
return Access::adopt<DataType>(vx_dtype_new_binary(nullable));
}
DataType decimal(uint8_t precision, int8_t scale, bool nullable) {
return Access::adopt<DataType>(vx_dtype_new_decimal(precision, scale, nullable));
const vx_dtype *dtype = vx_dtype_new_decimal(precision, scale, nullable);
if (dtype == nullptr) {
throw VortexException("invalid decimal precision or scale");
}
return Access::adopt<DataType>(dtype);
}
DataType list(DataType element, bool nullable) {
return Access::adopt<DataType>(vx_dtype_new_list(Access::release(std::move(element)), nullable));
Expand Down
6 changes: 5 additions & 1 deletion lang/cpp/src/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ static Expression select_impl(std::span<T> names, const vx_expression *expr) {
for (const auto &name : names) {
raw.push_back(to_view(name));
}
return Access::adopt<Expression>(vx_expression_select(raw.data(), raw.size(), expr));
vx_expression *out = vx_expression_select(raw.data(), raw.size(), expr);
if (out == nullptr) {
throw VortexException("select: field name is not valid UTF-8");
}
return Access::adopt<Expression>(out);
}

Expression Expression::select(std::span<const std::string> names) const {
Expand Down
2 changes: 2 additions & 0 deletions lang/cpp/tests/dtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ TEST_CASE("Decimal dtype", "[dtype]") {

REQUIRE_THROWS_AS(d.fields(), VortexException);
REQUIRE_THROWS_AS(d.list_element(), VortexException);
REQUIRE_THROWS_AS(dtype::decimal(0, 0), VortexException);
REQUIRE_THROWS_AS(dtype::decimal(100, 0), VortexException);
}

TEST_CASE("copy dtype", "[dtype]") {
Expand Down
4 changes: 4 additions & 0 deletions lang/cpp/tests/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ TEST_CASE("Project multiple fields", "[projection]") {
verify_sample_array(session, *array);
}

TEST_CASE("Select invalid UTF-8 field name throws", "[projection]") {
REQUIRE_THROWS_AS(expr::root().select({"\xFF\xFE"}), VortexException);
}

TEST_CASE("Filter age", "[filter]") {
Session session;
TempPath path = write_sample(session);
Expand Down
4 changes: 4 additions & 0 deletions vortex-ffi/cinclude/vortex.h
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ const vx_dtype *vx_dtype_new_struct(vx_struct_fields *struct_dtype, bool is_null

/**
* Create a new decimal data type.
*
* Returns NULL if `precision` or `scale` is invalid.
*/
const vx_dtype *vx_dtype_new_decimal(uint8_t precision, int8_t scale, bool is_nullable);

Expand Down Expand Up @@ -1102,6 +1104,8 @@ vx_expression *vx_expression_literal(const vx_scalar *scalar, vx_error **err);
* vx_array_apply if the child expression doesn't have a specified field.
*
* Returns a DTYPE_STRUCT array with selected fields.
* Returns NULL if `child` is NULL, `names` is NULL with `len > 0`, or any field name is not
* valid UTF-8.
*
* Example:
*
Expand Down
Loading
Loading