Skip to content

Add rvalue vector ctors for ColumnDate, ColumnDate32 and ColumnIPv4 #332

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

Merged
merged 4 commits into from
Sep 30, 2023

Conversation

bduminiuc
Copy link
Contributor

These constructors can be valuable for enhancing performance in scenarios where a user knows the row count and can preallocate memory.

I also considered adding a similar constructor for ColumnDateTime, but its public interface exclusively utilizes time_t, while uint32_t is an implementation detail. I'm unsure if extending the interface with implementation details would be a good idea.

Copy link
Contributor

@Enmk Enmk left a comment

Choose a reason for hiding this comment

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

Hi @bduminiuc, thanks for your contibution!

As for ColumnDateTime -- feel free to add constructor that takes vector<uint32_t> &&, the underlying storage type is not going to be changed in the foreseeable future.

Also, please consider adding unit-tests that verify the added constructors.

@bduminiuc
Copy link
Contributor Author

Hi, @Enmk,

The constructor for ColumnDateTime and the unit tests mentioned earlier were added.

@@ -528,6 +562,23 @@ TEST(ColumnsCase, ColumnIPv4_construct_from_data)
EXPECT_ANY_THROW(ColumnIPv4(ColumnRef(std::make_shared<ColumnString>())));
}

TEST(ColumnsCase, ColumnIPv4_construct_from_rvalue_data) {
std::vector<uint32_t> data = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use MakeIPv4s, unless you have a good reason not to.

Copy link
Contributor Author

@bduminiuc bduminiuc Sep 28, 2023

Choose a reason for hiding this comment

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

The newly added constructor for ColumnIPv4 accepts a vector of raw values std::vector<uint32_t>&&, while MakeIPv4 returns in_addr. It seems that the MakeIPv4 function cannot be used to provide test coverage for ColumnIPv4(std::vector<uint32_t>&&).

Should something specific be done for the case?

Comment on lines 231 to 235
ASSERT_EQ(col1->Size(), expected.size());
for (size_t i = 0; i < expected.size(); ++i) {
ASSERT_EQ(col1->At(i), static_cast<std::time_t>(expected[i]));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use a single check instead of for-loop here:

EXPECT_TRUE(CompareRecursive(*col1, expected));

Takes care of size checks, value checks, and forms a pretty explanation message if comparison fails.


ASSERT_EQ(col1->Size(), expected.size());
for (size_t i = 0; i < expected.size(); ++i) {
ASSERT_EQ(col1->RawAt(i), expected[i]);
Copy link
Contributor

@Enmk Enmk Sep 27, 2023

Choose a reason for hiding this comment

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

(note in regards of https://github.com/ClickHouse/clickhouse-cpp/pull/332/files#r1338877216)
CompareRecursive isn't going to work here due to value transformation by ColumnDate, same for DateTime32.

Methods returning bogus time_t values is the hard legacy we need to get rid of, but I haven't decided how to make a smooth transition for the users...

Copy link
Contributor

@Enmk Enmk left a comment

Choose a reason for hiding this comment

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

Please address minor things in the unit tests and it is going to be good to merge.

Copy link
Contributor

@Enmk Enmk left a comment

Choose a reason for hiding this comment

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

LGTM, will be merged after #336

@Enmk Enmk merged commit 5cec31a into ClickHouse:master Sep 30, 2023
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