feat: Add BaseVector::createFromVariants convenience API#15955
feat: Add BaseVector::createFromVariants convenience API#15955PingLiuPing wants to merge 1 commit intofacebookincubator:mainfrom
Conversation
✅ Deploy Preview for meta-velox ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
bb05df6 to
78bead1
Compare
| /// Creates a vector from a list of Variant values. | ||
| /// Supports all primitive types and complex types (ARRAY, MAP, ROW). | ||
| static VectorPtr createFromConstants( |
There was a problem hiding this comment.
createFromConstants
Let's rename to createFromVariants, add toVariants getter and move next to variantAt. Let's clarify that the result is a flat vector.
Variant variantAt(vector_size_t index) const;
std::vector<Variant> toVariants() const;
static VectorPtr createFromVariants(...);
Supports all primitive types and complex types (ARRAY, MAP, ROW).
This is redundant since it effectively means that the API supports all types.
| auto vector = BaseVector::createFromConstants(type, values, pool()); | ||
|
|
||
| EXPECT_FALSE(vector->isConstantEncoding()); | ||
| EXPECT_EQ(vector->type()->toString(), type->toString()); |
There was a problem hiding this comment.
use VELOX_EXPECT_EQ_TYPES
| void testFromConstants( | ||
| const TypePtr& type, | ||
| const std::vector<Variant>& values, | ||
| const VectorPtr& expected) { |
There was a problem hiding this comment.
const VectorPtr& expected
Seems redundant to provide 'expected' as we can simply verify that values[i] == vector->variantAt(i).
There was a problem hiding this comment.
Thanks, you are right.
| })); | ||
| } | ||
|
|
||
| TEST_F(VariantToVectorTest, createFromConstantsEmpty) { |
There was a problem hiding this comment.
Perhaps, add some negative tests where variants do not have consistent types or do not match the 'type'.
There was a problem hiding this comment.
Thanks, added a case to test type mismatch scenario.
mbasmanova
left a comment
There was a problem hiding this comment.
Curious, where do you want to use this new API.
78bead1 to
20863af
Compare
| }; | ||
| EXPECT_THROW( | ||
| BaseVector::createFromVariants(VARCHAR(), values, pool()), | ||
| std::invalid_argument); |
There was a problem hiding this comment.
Can we make sure to throw VeloxException? and use VELOX_ASSERT_THROW to verify the message?
There was a problem hiding this comment.
Yes, this require some additional change to Variant::throwCheckIsKindError. And I also updatedVariant::throwCheckPtrError. @mbasmanova
mbasmanova
left a comment
There was a problem hiding this comment.
Looks great % small comment re: the exception.
9b5fd3d to
0bc392c
Compare
|
@PingLiuPing it looks like VariantOpaqueTest.opaque is expecting the exception to be of a certain type and is now failing, could you take a look? |
@kevinwilfong Thank you, will check and update. |
0bc392c to
7360ab4
Compare
|
@kevinwilfong Fixed. |
|
@kevinwilfong has imported this pull request. If you are a Meta employee, you can view this in D90518495. |
|
@PingLiuPing could I get you to rebase this one as well on top of #15981 (again, thank you so much for that fix!) |
7360ab4 to
aaf873d
Compare
|
@kevinwilfong merged this pull request in d2c8304. |
Add a new helper function to create a vector from a list of Variant values.
Supports all primitive types and complex types (ARRAY, MAP, ROW).