Debian Codegraph @

tools/generate-many-segment-data.rb

raw symbols SCIP
1 #!/usr/bin/env ruby
2 #
3 # Copyright(C) 2019 Kouhei Sutou <[email protected]>
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 require "json"
20 require "optparse"
21
22 n_records = 50_000_000
23 max_code_point = 0xFFFF
24 n_characters_per_record = 100
25 use_section = false
26 use_index_large = false
27 parser = OptionParser.new
28 parser.on("--n-records=N", Integer,
29 "[#{n_records}]") do |n|
30 if n < 0
31 n_records = Float::INFINITY
32 else
33 n_records = n
34 end
35 end
36 parser.on("--[no-]use-section",
37 "[#{use_section}]") do |boolean|
38 use_section = boolean
39 end
40 parser.on("--[no-]use-index-large",
41 "[#{use_index_large}]") do |boolean|
42 use_index_large = boolean
43 end
44 parser.parse!
45
46 if use_section
47 columns = 5.times.collect {|i| "value#{i}"}
48 else
49 columns = ["value"]
50 end
51
52 puts(<<-COMMANDS)
53 table_create Data TABLE_NO_KEY
54 COMMANDS
55 columns.each do |column|
56 puts(<<-COMMANDS)
57 column_create Data #{column} COLUMN_SCALAR|COMPRESS_ZSTD Text
58 COMMANDS
59 end
60
61 index_column_flags = "COLUMN_INDEX|WITH_POSITION"
62 if columns.size > 1
63 index_column_flags += "|WITH_SECTION"
64 end
65 if use_index_large
66 index_column_flags += "|INDEX_LARGE"
67 end
68 puts(<<-COMMANDS)
69 table_create Terms TABLE_HASH_KEY ShortText \
70 --normalizer NormalizerNFKC100 \
71 --default_tokenizer TokenRegexp
72 column_create Terms index #{index_column_flags} Data #{columns.join(",")}
73 COMMANDS
74
75 puts(<<-LOAD)
76 load --table Data
77 [
78 LOAD
79 (1..n_records).each do |id|
80 record = {"_id" => id}
81 columns.each do |column|
82 value = ""
83 n_characters_per_record.times do
84 while true
85 code_point = rand(max_code_point)
86 character = [code_point].pack("U")[0]
87 if character.valid_encoding?
88 value << character
89 break
90 end
91 end
92 end
93 record[column] = value
94 end
95 puts(record.to_json)
96 end
97 puts(<<-LOAD)
98 ]
99 LOAD