You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@orc.apache.org by "taiyang-li (via GitHub)" <gi...@apache.org> on 2024/08/22 02:05:26 UTC

[PR] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

taiyang-li opened a new pull request, #2010:
URL: https://github.com/apache/orc/pull/2010

   
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If there is a discussion in the mailing list, please add the link.
   --> 
   
   Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter. 
   Performance is tested in https://github.com/ClickHouse/orc/pull/15
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   --> 
   original tests. 
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2309459294

   I added a benchmark (https://github.com/ClickHouse/ClickHouse/blob/1011f8ef9c2511654937c96b7bea7693a4c9715f/src/Common/benchmarks/orc_string_dictionary.cpp) to measure performance changes after this pr. Here is the result: 
   
   ```
   $ ./build_gcc/src/Common/benchmarks/orc_string_dictionary 
   2024-08-26T14:43:53+08:00
   Running ./build_gcc/src/Common/benchmarks/orc_string_dictionary
   Run on (32 X 2100 MHz CPU s)
   CPU Caches:
     L1 Data 32 KiB (x16)
     L1 Instruction 32 KiB (x16)
     L2 Unified 1024 KiB (x16)
     L3 Unified 11264 KiB (x2)
   Load Average: 5.79, 5.70, 5.88
   ----------------------------------------------------------------------------------------------
   Benchmark                                                    Time             CPU   Iterations
   ----------------------------------------------------------------------------------------------
   BM_writeStringDictionary<OldSortedStringDictionary>  148905832 ns    148900910 ns            5
   BM_writeStringDictionary<NewSortedStringDictionary>   86750854 ns     86747873 ns            8
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1726686314


##########
c++/src/ColumnWriter.cc:
##########
@@ -922,8 +931,8 @@ namespace orc {
       }
     };
 
-    std::map<DictEntry, size_t, LessThan> dict_;
-    std::vector<std::vector<char>> data_;
+    mutable std::vector<DictEntryWithIndex> flat_dict;

Review Comment:
   I'll fix it. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1726598323


##########
c++/src/ColumnWriter.cc:
##########
@@ -922,8 +931,8 @@ namespace orc {
       }
     };
 
-    std::map<DictEntry, size_t, LessThan> dict_;
-    std::vector<std::vector<char>> data_;
+    mutable std::vector<DictEntryWithIndex> flat_dict;

Review Comment:
   Please follow the naming style.
   [The format check didn't fail as expected.](https://github.com/apache/orc/actions/runs/10503087327/job/29095780106?pr=2010#step:4:66)



##########
c++/src/ColumnWriter.cc:
##########
@@ -1103,6 +1115,12 @@ namespace orc {
       throw InvalidArgument("Failed to cast to StringVectorBatch");
     }
 
+    EncodedStringVectorBatch* encoded_string_batch =
+        dynamic_cast<EncodedStringVectorBatch*>(&rowBatch);
+    if (encoded_string_batch) {

Review Comment:
   Maybe let the caller call calculateDataAndLength() is better?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1730821959


##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +249,15 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void calculateDataAndLength();
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+    std::atomic<bool> calculated{false};

Review Comment:
   Should we replace it with `std::call_once`?



##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +249,15 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void calculateDataAndLength();

Review Comment:
   BTW, should we move it to the parent `ColumnVectorBatch` class so we can decode dictionaries in a single shot and do not bother with multiple `dynamic_cast` calls in the writer implementation?



##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +249,15 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void calculateDataAndLength();

Review Comment:
   What about renaming it into `decodeDictionary()`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1732088536


##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +249,15 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void calculateDataAndLength();
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+    std::atomic<bool> calculated{false};

Review Comment:
   I think they are equivalent.. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "luffy-zh (via GitHub)" <gi...@apache.org>.
luffy-zh commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1734068573


##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +249,15 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void calculateDataAndLength();
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+    std::atomic<bool> calculated{false};

Review Comment:
   Sorry for the late comment. All members of the ColumnVectorBatch class are non-atomic. It is assumed that the ColumnVectorBatch object will not be shared or reused across multiple threads. Could you share the code in ClickHouse that invokes decodeDictionary()?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2316931461

   > Thanks for opening a PR! Could you please create a JIRA for it?
   
   https://issues.apache.org/jira/browse/ORC-1767 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1726994715


##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +249,15 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void calculateDataAndLength();
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+    std::atomic<bool> calculated{false};

Review Comment:
   It is needed to avoid duplicated invokes from caller. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1735842791


##########
c++/src/Vector.cc:
##########
@@ -88,6 +88,20 @@ namespace orc {
     }
   }
 
+  void EncodedStringVectorBatch::decodeDictionary() {
+    if (dictionaryDecoded) return;

Review Comment:
   I had removed `std::atomic` 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2304039555

   @taiyang-li Hi, thank you for opening a PR! 
   It seems that the time complexity not changed. Do writing cost a lot on sorting? After all, the size of dictionary shouldn't be large when we try to use dictionary encoding.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1734062467


##########
c++/include/orc/Vector.hh:
##########
@@ -251,13 +256,14 @@ namespace orc {
     void resize(uint64_t capacity) override;
 
     // Calculate data and length in StringVectorBatch from dictionary and index
-    void calculateDataAndLength();
+    void decodeDictionary() override;
 
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
-    std::atomic<bool> calculated{false};
+
+    std::atomic<bool> dictionary_encoded{false};

Review Comment:
   ```suggestion
       std::atomic<bool> dictionaryDecoded{false};
   ```



##########
c++/src/ColumnWriter.cc:
##########
@@ -931,8 +933,8 @@ namespace orc {
       }
     };
 
-    mutable std::vector<DictEntryWithIndex> flat_dict;
-    std::unordered_map<std::string, size_t> key_to_index;
+    mutable std::vector<DictEntryWithIndex> flatDict_;
+    std::unordered_map<std::string, size_t> keyToIndex;

Review Comment:
   ```suggestion
       std::unordered_map<std::string, size_t> keyToIndex_;
   ```



##########
c++/src/ColumnWriter.cc:
##########
@@ -952,9 +959,12 @@ namespace orc {
   // write dictionary data & length to output buffer
   void SortedStringDictionary::flush(AppendOnlyBufferedStream* dataStream,
                                      RleEncoder* lengthEncoder) const {
-    for (auto it = dict_.cbegin(); it != dict_.cend(); ++it) {
-      dataStream->write(it->first.data, it->first.length);
-      lengthEncoder->write(static_cast<int64_t>(it->first.length));
+    std::sort(flatDict_.begin(), flatDict_.end(), LessThan());
+
+    for (const auto& entry_with_index : flatDict_) {

Review Comment:
   ```suggestion
       for (const auto& entryWithIndex : flatDict_) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1735750976


##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +254,16 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void decodeDictionary() override;
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+
+    std::atomic<bool> dictionaryDecoded{false};

Review Comment:
   Anyway, I'll remove it to keep code simple. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs closed pull request #2010: ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter
URL: https://github.com/apache/orc/pull/2010


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2303783606

   cc @ffacs @luffy-zh 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1726685375


##########
c++/src/ColumnWriter.cc:
##########
@@ -1103,6 +1115,12 @@ namespace orc {
       throw InvalidArgument("Failed to cast to StringVectorBatch");
     }
 
+    EncodedStringVectorBatch* encoded_string_batch =
+        dynamic_cast<EncodedStringVectorBatch*>(&rowBatch);
+    if (encoded_string_batch) {

Review Comment:
   I'm afrait it will increase user's mental burden. Do you think make it transparent for user is ok? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1734109964


##########
c++/include/orc/Vector.hh:
##########
@@ -263,7 +263,7 @@ namespace orc {
     // index for dictionary entry
     DataBuffer<int64_t> index;
 
-    std::atomic<bool> dictionary_encoded{false};
+    std::atomic<bool> dictionaryEncoded{false};

Review Comment:
   Ain't this should be `dictionaryDecoded`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1735760757


##########
c++/src/Vector.cc:
##########
@@ -88,6 +88,20 @@ namespace orc {
     }
   }
 
+  void EncodedStringVectorBatch::decodeDictionary() {
+    if (dictionaryDecoded) return;
+
+    size_t n = index.size();
+    resize(n);
+
+    for (size_t i = 0; i < n; ++i) {
+      if (!hasNulls || notNull[i]) {
+        dictionary->getValueByIndex(index[i], data[i], length[i]);
+      }
+    }
+    dictionaryDecoded = true;

Review Comment:
   ```suggestion
   ```



##########
c++/src/Vector.cc:
##########
@@ -88,6 +88,20 @@ namespace orc {
     }
   }
 
+  void EncodedStringVectorBatch::decodeDictionary() {
+    if (dictionaryDecoded) return;

Review Comment:
   ```suggestion
       if (dictionaryDecoded.exchange(true)) return;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2303635593

   Thanks for opening a PR! Could you please create a JIRA for it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2303988650

   @wgtmac could you help review this pr, thanks very much 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2304198383

   > > @taiyang-li Hi, thank you for opening a PR! It seems that the time complexity not changed. Do writing cost a lot on sorting? After all, the size of dictionary shouldn't be large when we try to use dictionary encoding.
   > 
   > @ffacs I had measured about this. From flamegraph we could see that `std::map::insert` takes most of time. Notice that `std::map::insert` is executed even if key is duplicated.
   
   Oh yes, std::map takes $$O(n \ \log(key))$$, but sort takes only $$O(n + key\ \log(Key))$$


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2304179393

   > @taiyang-li Hi, thank you for opening a PR! It seems that the time complexity not changed. Do writing cost a lot on sorting? After all, the size of dictionary shouldn't be large when we try to use dictionary encoding.
   
   @ffacs I had measured about this. From flamegraph we could see that `std::map::insert` takes most of time. Notice that `std::map::insert` is executed even if key is duplicated. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "luffy-zh (via GitHub)" <gi...@apache.org>.
luffy-zh commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1726992106


##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +249,15 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void calculateDataAndLength();
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+    std::atomic<bool> calculated{false};

Review Comment:
   Do we need atomic type here?
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1735741811


##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +254,16 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void decodeDictionary() override;
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+
+    std::atomic<bool> dictionaryDecoded{false};

Review Comment:
   It's a personal coding habit in case there might be a multi-threaded call scenario in the future. Besides, `std::atomic<bool>` is so trivial that it would not influence the performance. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1735845299


##########
c++/src/Vector.cc:
##########
@@ -88,6 +88,20 @@ namespace orc {
     }
   }
 
+  void EncodedStringVectorBatch::decodeDictionary() {
+    if (dictionaryDecoded) return;
+
+    size_t n = index.size();
+    resize(n);
+
+    for (size_t i = 0; i < n; ++i) {
+      if (!hasNulls || notNull[i]) {
+        dictionary->getValueByIndex(index[i], data[i], length[i]);
+      }
+    }
+    dictionaryDecoded = true;

Review Comment:
   dictionaryDecoded had been moved to `ColumnVectorBatch`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2323930932

   @ffacs any new requested changes ?  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1740398654


##########
c++/include/orc/Vector.hh:
##########
@@ -57,6 +57,8 @@ namespace orc {
     bool hasNulls;
     // whether the vector batch is encoded
     bool isEncoded;
+    // whther the dictionary is decoded into vector batch

Review Comment:
   whether



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ORC-1767: [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1735741811


##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +254,16 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void decodeDictionary() override;
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+
+    std::atomic<bool> dictionaryDecoded{false};

Review Comment:
   It's a personal coding habit in case there might be a multi-threaded call scenario in the future. Besides, `std::atomic<bool>` is so trivial and not frequently invoked, it would not influence the performance. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1734620806


##########
c++/include/orc/Vector.hh:
##########
@@ -263,7 +263,7 @@ namespace orc {
     // index for dictionary entry
     DataBuffer<int64_t> index;
 
-    std::atomic<bool> dictionary_encoded{false};
+    std::atomic<bool> dictionaryEncoded{false};

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #2010:
URL: https://github.com/apache/orc/pull/2010#discussion_r1734869053


##########
c++/include/orc/Vector.hh:
##########
@@ -88,6 +89,11 @@ namespace orc {
      */
     virtual bool hasVariableLength();
 
+    /**
+     * Decode dictionary into vector batch.
+     */
+    virtual void decodeDictionary() {}

Review Comment:
   We need to implement this for struct, map, list and union type by calling it recursively.



##########
c++/src/ColumnWriter.cc:
##########
@@ -130,6 +130,8 @@ namespace orc {
         hasNullValue = true;
       }
     }
+
+    batch.decodeDictionary();

Review Comment:
   My intention to add `decodeDictionary()` is that caller should call `decodeDictionary()` before calling `ColumnWriter::add()`. This can make the implementation of `ColumnWriter ` simpler.



##########
c++/include/orc/Vector.hh:
##########
@@ -248,10 +254,16 @@ namespace orc {
     ~EncodedStringVectorBatch() override;
     std::string toString() const override;
     void resize(uint64_t capacity) override;
+
+    // Calculate data and length in StringVectorBatch from dictionary and index
+    void decodeDictionary() override;
+
     std::shared_ptr<StringDictionary> dictionary;
 
     // index for dictionary entry
     DataBuffer<int64_t> index;
+
+    std::atomic<bool> dictionaryDecoded{false};

Review Comment:
   I think it is an overkill to use atomic here. It should be a misuse to call member functions of ColumnVectorBatch concurrently.



##########
c++/include/orc/Vector.hh:
##########
@@ -88,6 +89,11 @@ namespace orc {
      */
     virtual bool hasVariableLength();
 
+    /**
+     * Decode dictionary into vector batch.
+     */
+    virtual void decodeDictionary() {}

Review Comment:
   BTW, please add a test case to make sure it works as expected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "ffacs (via GitHub)" <gi...@apache.org>.
ffacs commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2309222520

   > @ffacs do you know where can I add google benchmark in orc ?
   
   There are no C++ benchmark currently. FYI. https://github.com/apache/orc/issues/1658


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [C++] Improve writing performance of encoded string column and support EncodedStringVectorBatch for StringColumnWriter [orc]

Posted by "taiyang-li (via GitHub)" <gi...@apache.org>.
taiyang-li commented on PR #2010:
URL: https://github.com/apache/orc/pull/2010#issuecomment-2309212343

   @ffacs do you know where can I add google benchmark  in orc ? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org