traject_sequel_writer 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/traject/sequel_writer.rb +24 -2
- data/lib/traject_sequel_writer/version.rb +1 -1
- data/test/test_helper.rb +1 -2
- data/test/test_traject_sequel_writer.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e73f97cb0e4558e71b2960c0d42accad74041758
|
4
|
+
data.tar.gz: 1e0e5f6ddacfef11a408e503ee987a7dc8f0ba35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc2945a7cd9457e4a287e00948bd069bc6c9b081aac8686addb3ebeef6d8076ddf2bbb9b717385c575b0098f092f6c87735545abdd25b2b2c6cd9c33d37dc0f
|
7
|
+
data.tar.gz: 0ef683cf6ee481e62ad600d088919fd537817459793d49d3645e954291e546a95145dc32133e377bd50cfa52e0b2e15595aa24d18228d354005b50224b5fce82
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@ The writer can be used as standard, as the destination of your indexing pipeline
|
|
9
9
|
|
10
10
|
It was actually written for a use case where it's used as a "side effect" in a traject `each_record`, writing different data out to an rdbms on the side, while the main indexing is to Solr. This ends up a bit hacky at present but works.
|
11
11
|
|
12
|
+
Currently has a pre-1.0 release number, as it has not seen wide use, and may have some oddities.
|
12
13
|
|
13
14
|
## Installation
|
14
15
|
|
@@ -140,11 +140,33 @@ module Traject
|
|
140
140
|
|
141
141
|
def hash_to_array(column_names, hash)
|
142
142
|
column_names.collect do |c|
|
143
|
-
|
144
|
-
v.kind_of?(Array) ? v.join(@internal_delimiter) : v
|
143
|
+
output_value_to_column_value(hash[c.to_s])
|
145
144
|
end
|
146
145
|
end
|
147
146
|
|
147
|
+
# Traject context.output_hash values are arrays.
|
148
|
+
# turn them into good column values, joining strings if needed.
|
149
|
+
#
|
150
|
+
# Single values also accepted, even though not traject standard, they
|
151
|
+
# will be passed through unchanged.
|
152
|
+
def output_value_to_column_value(v)
|
153
|
+
if v.kind_of?(Array)
|
154
|
+
if v.length == 0
|
155
|
+
nil
|
156
|
+
elsif v.length == 1
|
157
|
+
v.first
|
158
|
+
elsif v.first.kind_of?(String)
|
159
|
+
v.join(@internal_delimiter)
|
160
|
+
else
|
161
|
+
# Not a string? Um, raise for now?
|
162
|
+
raise ArgumentError.new("Traject::SequelWriter, multiple non-String values provided: #{v}")
|
163
|
+
end
|
164
|
+
else
|
165
|
+
v
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
|
148
170
|
def after_send_batch(&block)
|
149
171
|
@after_send_batch_callbacks << block
|
150
172
|
end
|
data/test/test_helper.rb
CHANGED
@@ -41,6 +41,19 @@ describe "Traject::SequelWriter" do
|
|
41
41
|
assert @writer.db_table.where(:string_a => "String_One,String_Two", :string_b => "String_B_One").count == 1, "Expected written row with expected values"
|
42
42
|
end
|
43
43
|
|
44
|
+
it "complains about multiple non-string values" do
|
45
|
+
@writer = self.writer
|
46
|
+
|
47
|
+
context = Traject::Indexer::Context.new
|
48
|
+
context.output_hash.merge!(
|
49
|
+
"int_a" => [1001, 1002]
|
50
|
+
)
|
51
|
+
assert_raises(ArgumentError) do
|
52
|
+
@writer.put context
|
53
|
+
@writer.close
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
44
57
|
after do
|
45
58
|
@writer.db_table.delete
|
46
59
|
end
|