amalgalite 1.4.1-x86-mingw32 → 1.7.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +11 -0
- data/HISTORY.md +45 -0
- data/LICENSE +2 -0
- data/Manifest.txt +2 -1
- data/README.md +10 -14
- data/Rakefile +5 -5
- data/examples/fts5.rb +152 -0
- data/ext/amalgalite/c/amalgalite.c +26 -0
- data/ext/amalgalite/c/amalgalite_constants.c +1110 -56
- data/ext/amalgalite/c/amalgalite_database.c +80 -70
- data/ext/amalgalite/c/extconf.rb +31 -4
- data/ext/amalgalite/c/gen_constants.rb +313 -153
- data/ext/amalgalite/c/sqlite3.c +103967 -33836
- data/ext/amalgalite/c/sqlite3.h +5438 -1061
- data/ext/amalgalite/c/sqlite3ext.h +148 -12
- data/lib/amalgalite/2.2/amalgalite.so +0 -0
- data/lib/amalgalite/2.3/amalgalite.so +0 -0
- data/lib/amalgalite/2.4/amalgalite.so +0 -0
- data/lib/amalgalite/2.5/amalgalite.so +0 -0
- data/lib/amalgalite/2.6/amalgalite.so +0 -0
- data/lib/amalgalite/aggregate.rb +6 -0
- data/lib/amalgalite/csv_table_importer.rb +1 -1
- data/lib/amalgalite/database.rb +2 -53
- data/lib/amalgalite/profile_tap.rb +2 -2
- data/lib/amalgalite/statement.rb +5 -2
- data/lib/amalgalite/taps/io.rb +5 -2
- data/lib/amalgalite/trace_tap.rb +1 -1
- data/lib/amalgalite/type_maps/default_map.rb +2 -2
- data/lib/amalgalite/type_maps/storage_map.rb +1 -1
- data/lib/amalgalite/version.rb +1 -1
- data/spec/aggregate_spec.rb +4 -0
- data/spec/database_spec.rb +12 -15
- data/spec/default_map_spec.rb +1 -1
- data/spec/integeration_spec.rb +2 -2
- data/spec/json_spec.rb +24 -0
- data/spec/sqlite3/version_spec.rb +15 -9
- data/spec/storage_map_spec.rb +1 -1
- data/tasks/default.rake +3 -10
- data/tasks/extension.rake +4 -4
- data/tasks/this.rb +7 -5
- metadata +33 -25
- data/examples/fts3.rb +0 -144
- data/lib/amalgalite/1.8/amalgalite.so +0 -0
- data/lib/amalgalite/1.9/amalgalite.so +0 -0
- data/lib/amalgalite/2.0/amalgalite.so +0 -0
- data/lib/amalgalite/2.1/amalgalite.so +0 -0
data/examples/fts3.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'rubygems'
|
3
|
-
require 'amalgalite'
|
4
|
-
require 'benchmark'
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'json'
|
8
|
-
rescue LoadError
|
9
|
-
abort "'gem install json' to run this example"
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
README = <<_
|
14
|
-
This example programs assumes that you have downloaded the 'Tweets During the
|
15
|
-
State of the Union address' dataset from infochimps.com
|
16
|
-
|
17
|
-
http://www.infochimps.com/datasets/tweets-during-state-of-the-union-address
|
18
|
-
|
19
|
-
Please:
|
20
|
-
1) download this dataset
|
21
|
-
2) bunzip + untar this file
|
22
|
-
3) record the location of the 'twitter_stream.txt' file that is in the
|
23
|
-
tarball.
|
24
|
-
4) Pass this file as the first parameter to this script.
|
25
|
-
_
|
26
|
-
|
27
|
-
twitter_stream = ARGV.shift
|
28
|
-
abort README unless twitter_stream and File.readable?( twitter_stream )
|
29
|
-
|
30
|
-
#
|
31
|
-
# Lets create a database that utilizes FTS3 http://www.sqlite.org/fts3.html
|
32
|
-
#
|
33
|
-
#
|
34
|
-
|
35
|
-
#
|
36
|
-
# Create a database, this will create the DB if it doesn't exist
|
37
|
-
#
|
38
|
-
puts "Opening database (version #{Amalgalite::Version})"
|
39
|
-
db = Amalgalite::Database.new("fts3.db")
|
40
|
-
|
41
|
-
#
|
42
|
-
# Create the schema unless it already exists in the table. The meta information
|
43
|
-
# about the database schema is available as the result of the db.schema method
|
44
|
-
#
|
45
|
-
schema = db.schema
|
46
|
-
unless schema.tables['search']
|
47
|
-
puts "Create schema"
|
48
|
-
db.execute_batch <<-SQL
|
49
|
-
CREATE VIRTUAL TABLE search USING fts3(
|
50
|
-
filename VARCHAR(128),
|
51
|
-
content TEXT
|
52
|
-
);
|
53
|
-
|
54
|
-
CREATE TABLE plain (
|
55
|
-
filename VARCHAR(128),
|
56
|
-
content TEXT
|
57
|
-
);
|
58
|
-
SQL
|
59
|
-
db.reload_schema!
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Only load the data if the db is empty
|
64
|
-
#
|
65
|
-
if db.first_value_from( "SELECT count(*) from search" ) == 0 then
|
66
|
-
before = Time.now
|
67
|
-
#
|
68
|
-
# Load the tweets from the file passed on the commandline into the database
|
69
|
-
# We just want the text and the tweet id and insert that into the database.
|
70
|
-
#
|
71
|
-
|
72
|
-
lines = IO.readlines( twitter_stream )
|
73
|
-
idx = 0
|
74
|
-
|
75
|
-
# Inserting bulk rows as a transaction is good practice with SQLite, it is
|
76
|
-
# MUCH faster.
|
77
|
-
db.transaction do |db_in_transaction|
|
78
|
-
lines.each do |line|
|
79
|
-
|
80
|
-
# quick little parse of the tweet
|
81
|
-
json = JSON.parse( line )
|
82
|
-
insert_data = {}
|
83
|
-
insert_data[':fname'] = json['id']
|
84
|
-
insert_data[':content'] = json['text']
|
85
|
-
|
86
|
-
# insert into the FTS3 table
|
87
|
-
db_in_transaction.prepare("INSERT INTO search( filename, content ) VALUES( :fname, :content );") do |stmt|
|
88
|
-
stmt.execute( insert_data )
|
89
|
-
end
|
90
|
-
|
91
|
-
# insert into the normal table for comparison
|
92
|
-
db_in_transaction.prepare("INSERT INTO plain( filename, content ) VALUES( :fname, :content );") do |stmt|
|
93
|
-
stmt.execute( insert_data )
|
94
|
-
end
|
95
|
-
|
96
|
-
idx += 1
|
97
|
-
print "Processed #{idx} of #{lines.size}\r"
|
98
|
-
$stdout.flush
|
99
|
-
end
|
100
|
-
puts "Finalizing..."
|
101
|
-
end
|
102
|
-
puts "Took #{Time.now - before} seconds to insert #{idx} lines of #{lines.size}"
|
103
|
-
puts "Done Inserting"
|
104
|
-
end
|
105
|
-
|
106
|
-
doc_count = db.first_value_from( "SELECT count(*) from search" )
|
107
|
-
|
108
|
-
#
|
109
|
-
# Now lets do some searching for some various words
|
110
|
-
#
|
111
|
-
|
112
|
-
%w[ president salmon thanks ].each do |word|
|
113
|
-
|
114
|
-
count = 100
|
115
|
-
puts
|
116
|
-
puts "Searching for '#{word}' across #{doc_count} tweets"
|
117
|
-
puts "=" * 60
|
118
|
-
|
119
|
-
Benchmark.bm( 15 ) do |x|
|
120
|
-
|
121
|
-
#
|
122
|
-
# search using the fts search to get the cont of tweets with the given word
|
123
|
-
#
|
124
|
-
x.report('fts3: ') do
|
125
|
-
db.prepare( "SELECT count(filename) FROM search WHERE content MATCH '#{word}'" ) do |stmt|
|
126
|
-
count.times do
|
127
|
-
stmt.execute
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
#
|
133
|
-
# search using basic string matching in sqlite.
|
134
|
-
#
|
135
|
-
x.report('plain: ') do
|
136
|
-
db.prepare( "SELECT count(filename) FROM plain WHERE content LIKE '% #{word} %'" ) do |stmt|
|
137
|
-
count.times do
|
138
|
-
stmt.execute
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|