save-buffer commented on a change in pull request #12537:
URL: https://github.com/apache/arrow/pull/12537#discussion_r829348174



##########
File path: cpp/src/arrow/compute/exec/tpch_node.cc
##########
@@ -0,0 +1,3431 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/compute/exec/tpch_node.h"
+#include "arrow/util/future.h"
+#include "arrow/util/make_unique.h"
+#include "arrow/util/unreachable.h"
+
+#include <algorithm>
+#include <bitset>
+#include <cstring>
+#include <memory>
+#include <mutex>
+#include <queue>
+#include <random>
+#include <unordered_set>
+#include <vector>
+
+namespace arrow {
+using internal::checked_cast;
+
+namespace compute {
+const char* NameParts[] = {
+    "almond",    "antique",    "aquamarine", "azure",     "beige",    "bisque",
+    "black",     "blanched",   "blue",       "blush",     "brown",    
"burlywood",
+    "burnished", "chartreuse", "chiffon",    "chocolate", "coral",    
"cornflower",
+    "cornsilk",  "cream",      "cyan",       "dark",      "deep",     "dim",
+    "dodger",    "drab",       "firebrick",  "floral",    "forest",   
"frosted",
+    "gainsboro", "ghost",      "goldenrod",  "green",     "grey",     
"honeydew",
+    "hot",       "indian",     "ivory",      "khaki",     "lace",     
"lavender",
+    "lawn",      "lemon",      "light",      "lime",      "linen",    
"magenta",
+    "maroon",    "medium",     "metallic",   "midnight",  "mint",     "misty",
+    "moccasin",  "navajo",     "navy",       "olive",     "orange",   "orchid",
+    "pale",      "papaya",     "peach",      "peru",      "pink",     "plum",
+    "powder",    "puff",       "purple",     "red",       "rose",     "rosy",
+    "royal",     "saddle",     "salmon",     "sandy",     "seashell", "sienna",
+    "sky",       "slate",      "smoke",      "snow",      "spring",   "steel",
+    "tan",       "thistle",    "tomato",     "turquoise", "violet",   "wheat",
+    "white",     "yellow",
+};
+static constexpr size_t kNumNameParts = sizeof(NameParts) / 
sizeof(NameParts[0]);
+
+const char* Types_1[] = {
+    "STANDARD ", "SMALL ", "MEDIUM ", "LARGE ", "ECONOMY ", "PROMO ",
+};
+static constexpr size_t kNumTypes_1 = sizeof(Types_1) / sizeof(Types_1[0]);
+
+const char* Types_2[] = {
+    "ANODIZED ", "BURNISHED ", "PLATED ", "POLISHED ", "BRUSHED ",
+};
+static constexpr size_t kNumTypes_2 = sizeof(Types_2) / sizeof(Types_2[0]);
+
+const char* Types_3[] = {
+    "TIN", "NICKEL", "BRASS", "STEEL", "COPPER",
+};
+static constexpr size_t kNumTypes_3 = sizeof(Types_3) / sizeof(Types_3[0]);
+
+const char* Containers_1[] = {
+    "SM ", "LG ", "MD ", "JUMBO ", "WRAP ",
+};
+static constexpr size_t kNumContainers_1 = sizeof(Containers_1) / 
sizeof(Containers_1[0]);
+
+const char* Containers_2[] = {
+    "CASE", "BOX", "BAG", "JAR", "PKG", "PACK", "CAN", "DRUM",
+};
+static constexpr size_t kNumContainers_2 = sizeof(Containers_2) / 
sizeof(Containers_2[0]);
+
+const char* Segments[] = {
+    "AUTOMOBILE", "BUILDING", "FURNITURE", "MACHINERY", "HOUSEHOLD",
+};
+static constexpr size_t kNumSegments = sizeof(Segments) / sizeof(Segments[0]);
+
+const char* Priorities[] = {
+    "1-URGENT", "2-HIGH", "3-MEDIUM", "4-NOT SPECIFIED", "5-LOW",
+};
+static constexpr size_t kNumPriorities = sizeof(Priorities) / 
sizeof(Priorities[0]);
+
+const char* Instructions[] = {
+    "DELIVER IN PERSON",
+    "COLLECT COD",
+    "NONE",
+    "TAKE BACK RETURN",
+};
+static constexpr size_t kNumInstructions = sizeof(Instructions) / 
sizeof(Instructions[0]);
+
+const char* Modes[] = {
+    "REG AIR", "AIR", "RAIL", "SHIP", "TRUCK", "MAIL", "FOB",
+};
+static constexpr size_t kNumModes = sizeof(Modes) / sizeof(Modes[0]);
+
+const char* Nouns[] = {
+    "foxes ",        "ideas ",       "theodolites ",    "pinto beans ", 
"instructions ",
+    "dependencies ", "excuses ",     "platelets ",      "asymptotes ",  
"courts ",
+    "dolphins ",     "multipliers ", "sautemes ",       "warthogs ",    "frets 
",
+    "dinos ",        "attainments ", "somas ",          "Tiresias '",   
"patterns ",
+    "forges ",       "braids ",      "hockey players ", "frays ",       
"warhorses ",
+    "dugouts ",      "notomis ",     "epitaphs ",       "pearls ",      
"tithes ",
+    "waters ",       "orbits ",      "gifts ",          "sheaves ",     
"depths ",
+    "sentiments ",   "decoys ",      "realms ",         "pains ",       
"grouches ",
+    "escapades ",
+};
+static constexpr size_t kNumNouns = sizeof(Nouns) / sizeof(Nouns[0]);
+
+const char* Verbs[] = {
+    "sleep ",  "wake ",    "are ",    "cajole ",    "haggle ",   "nag ",     
"use ",
+    "boost ",  "affix ",   "detect ", "integrate ", "maintain ", "nod ",     
"was ",
+    "lose ",   "sublate ", "solve ",  "thrash ",    "promise ",  "engage ",  
"hinder ",
+    "print ",  "x-ray ",   "breach ", "eat ",       "grow ",     "impress ", 
"mold ",
+    "poach ",  "serve ",   "run ",    "dazzle ",    "snooze ",   "doze ",    
"unwind ",
+    "kindle ", "play ",    "hang ",   "believe ",   "doubt ",
+};
+static constexpr size_t kNumVerbs = sizeof(Verbs) / sizeof(Verbs[0]);
+
+const char* Adjectives[] = {
+    "furious ",  "sly ",       "careful ",  "blithe ", "quick ",  "fluffy ",  
"slow ",
+    "quiet ",    "ruthless ",  "thin ",     "close ",  "dogged ", "daring ",  
"brave ",
+    "stealthy ", "permanent ", "enticing ", "idle ",   "busy ",   "regular ", 
"final ",
+    "ironic ",   "even ",      "bold ",     "silent ",
+};
+static constexpr size_t kNumAdjectives = sizeof(Adjectives) / 
sizeof(Adjectives[0]);
+
+const char* Adverbs[] = {
+    "sometimes ",   "always ",     "never ",    "furiously ", "slyly ",     
"carefully ",
+    "blithely ",    "quickly ",    "fluffily ", "slowly ",    "quietly ",   
"ruthlessly ",
+    "thinly ",      "closely ",    "doggedly ", "daringly ",  "bravely ",   
"stealthily ",
+    "permanently ", "enticingly ", "idly ",     "busily ",    "regularly ", 
"finally ",
+    "ironically ",  "evenly ",     "boldly ",   "silently ",
+};
+static constexpr size_t kNumAdverbs = sizeof(Adverbs) / sizeof(Adverbs[0]);
+
+const char* Prepositions[] = {
+    "about ",  "above ",        "according to ", "across ",  "after ",      
"against ",
+    "along ",  "alongside of ", "among ",        "around ",  "at ",         
"atop ",
+    "before ", "behind ",       "beneath ",      "beside ",  "besides ",    
"between ",
+    "beyond ", "beyond ",       "by ",           "despite ", "during ",     
"except ",
+    "for ",    "from ",         "in place of ",  "inside ",  "instead of ", 
"into ",
+    "near ",   "of ",           "on ",           "outside ", "over ",       
"past ",
+    "since ",  "through ",      "throughout ",   "to ",      "toward ",     
"under ",
+    "until ",  "up ",           "upon ",         "without ", "with ",       
"within ",
+};
+static constexpr size_t kNumPrepositions = sizeof(Prepositions) / 
sizeof(Prepositions[0]);
+
+const char* Auxiliaries[] = {
+    "do ",
+    "may ",
+    "might ",
+    "shall ",
+    "will ",
+    "would ",
+    "can ",
+    "could ",
+    "should ",
+    "ought to ",
+    "must ",
+    "will have to ",
+    "shall have to ",
+    "could have to ",
+    "should have to ",
+    "must have to ",
+    "need to ",
+    "try to ",
+};
+static constexpr size_t kNumAuxiliaries = sizeof(Auxiliaries) / 
sizeof(Auxiliaries[0]);
+
+const char* Terminators[] = {
+    ".", ";", ":", "?", "!", "--",
+};
+static constexpr size_t kNumTerminators = sizeof(Terminators) / 
sizeof(Terminators[0]);
+
+// The spec says to generate a 300 MB string according to a grammar. This is a
+// concurrent implementation of the generator. Each thread generates the text 
in
+// (up to) 8KB chunks of text. The generator maintains a cursor into the
+// 300 MB buffer. After generating the chunk, the cursor is incremented
+// to reserve space, and the chunk is memcpy-d in.
+// This text is used to generate the COMMENT columns. To generate a comment, 
the spec
+// says to pick a random length and a random offset into the 300 MB buffer (it 
does
+// not specify it should be word/sentence aligned), and that slice of text 
becomes
+// the comment.
+class TpchPseudotext {
+ public:
+  Status EnsureInitialized(random::pcg32_fast& rng);
+  Result<Datum> GenerateComments(size_t num_comments, size_t min_length,
+                                 size_t max_length, random::pcg32_fast& rng);
+
+ private:
+  bool GenerateWord(int64_t& offset, random::pcg32_fast& rng, char* arr,
+                    const char** words, size_t num_choices);
+  bool GenerateNoun(int64_t& offset, random::pcg32_fast& rng, char* arr);
+  bool GenerateVerb(int64_t& offset, random::pcg32_fast& rng, char* arr);
+  bool GenerateAdjective(int64_t& offset, random::pcg32_fast& rng, char* arr);
+  bool GenerateAdverb(int64_t& offset, random::pcg32_fast& rng, char* arr);
+  bool GeneratePreposition(int64_t& offset, random::pcg32_fast& rng, char* 
arr);
+  bool GenerateAuxiliary(int64_t& offset, random::pcg32_fast& rng, char* arr);
+  bool GenerateTerminator(int64_t& offset, random::pcg32_fast& rng, char* arr);
+
+  bool GenerateNounPhrase(int64_t& offset, random::pcg32_fast& rng, char* arr);
+  bool GenerateVerbPhrase(int64_t& offset, random::pcg32_fast& rng, char* arr);
+  bool GeneratePrepositionalPhrase(int64_t& offset, random::pcg32_fast& rng, 
char* arr);
+
+  bool GenerateSentence(int64_t& offset, random::pcg32_fast& rng, char* arr);
+
+  std::atomic<bool> done_ = {false};
+  int64_t generated_offset_{0};
+  std::mutex text_guard_;
+  std::unique_ptr<Buffer> text_;
+  static constexpr int64_t kChunkSize = 8192;
+  static constexpr int64_t kTextBytes = 300 * 1024 * 1024;  // 300 MB
+};
+
+static TpchPseudotext g_text;

Review comment:
       this pseudotext is 300 MB big, and its generation is fairly expensive. 
i'd like to make it generated once per process. 




-- 
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: github-unsubscr...@arrow.apache.org

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


Reply via email to