Skip to content
This repository was archived by the owner on Dec 13, 2024. It is now read-only.

Commit 785bd71

Browse files
author
thisisaaronland
committed
update vendor deps; add discrete options and callback functions; add -strict-alt-files flag to index tool
1 parent c35a4cf commit 785bd71

File tree

9 files changed

+75
-13
lines changed

9 files changed

+75
-13
lines changed

cmd/wof-sqlite-index-features/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func main() {
3939
live_hard := flag.Bool("live-hard-die-fast", true, "Enable various performance-related pragmas at the expense of possible (unlikely) database corruption")
4040
timings := flag.Bool("timings", false, "Display timings during and after indexing")
4141
optimize := flag.Bool("optimize", true, "Attempt to optimize the database before closing connection")
42-
// liberal := flag.Bool("liberal", false, "Do not trigger errors for records that can not be processed, for whatever reason")
4342

4443
alt_files := flag.Bool("index-alt-files", false, "Index alt geometries")
44+
strict_alt_files := flag.Bool("strict-alt-files", true, "Be strict when indexing alt geometries")
4545

4646
var procs = flag.Int("processes", (runtime.NumCPU() * 2), "The number of concurrent processes to index data with")
4747

@@ -200,7 +200,12 @@ func main() {
200200
logger.Fatal("You forgot to specify which (any) tables to index")
201201
}
202202

203-
idx, err := index.NewDefaultSQLiteFeaturesIndexer(db, to_index)
203+
opts := index.DefaultSQLiteFeaturesIndexerCallbackOptions()
204+
opts.StrictAltFiles = *strict_alt_files
205+
206+
cb := index.SQLiteFeaturesIndexerCallback(opts)
207+
208+
idx, err := index.NewSQLiteFeaturesIndexerWithCallback(db, to_index, cb)
204209

205210
if err != nil {
206211
logger.Fatal("failed to create sqlite indexer because %s", err)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ go 1.12
44

55
require (
66
github.com/whosonfirst/go-whosonfirst-geojson-v2 v0.12.0
7-
github.com/whosonfirst/go-whosonfirst-index v0.2.2
7+
github.com/whosonfirst/go-whosonfirst-index v0.2.3
88
github.com/whosonfirst/go-whosonfirst-index-csv v0.0.0-20191002171239-c6712fe20972
99
github.com/whosonfirst/go-whosonfirst-index-sqlite v0.0.2
1010
github.com/whosonfirst/go-whosonfirst-log v0.1.0
1111
github.com/whosonfirst/go-whosonfirst-sqlite v0.1.4
12-
github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.4
12+
github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.5
1313
github.com/whosonfirst/go-whosonfirst-sqlite-index v0.1.0
1414
github.com/whosonfirst/warning v0.1.0
1515
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ github.com/whosonfirst/go-whosonfirst-index v0.1.2 h1:pm/NY4O21sN7PPrOsZNfuv7kX2
112112
github.com/whosonfirst/go-whosonfirst-index v0.1.2/go.mod h1:SfFN3GjmpS5TQK4mhvEcH+OfTSTWGLY8B6y48SmjLmQ=
113113
github.com/whosonfirst/go-whosonfirst-index v0.2.2 h1:P+dgqipNHgIX8a/u03sT3bHc/rqxopKIUn21mu0c/Bw=
114114
github.com/whosonfirst/go-whosonfirst-index v0.2.2/go.mod h1:n3rY2Hza4+MFtKES9C1sS4AAIkA5va/nagzvt+4ZFBw=
115+
github.com/whosonfirst/go-whosonfirst-index v0.2.3 h1:a+vfmTPp2GkyZExQqXzLTK2VwkjdnOyyKZHRbpMhB00=
116+
github.com/whosonfirst/go-whosonfirst-index v0.2.3/go.mod h1:n3rY2Hza4+MFtKES9C1sS4AAIkA5va/nagzvt+4ZFBw=
115117
github.com/whosonfirst/go-whosonfirst-index-csv v0.0.0-20191002171239-c6712fe20972 h1:xPrg89CfHOG3u7eaW6fa9ke4Px5kErS21D4mBf6usXE=
116118
github.com/whosonfirst/go-whosonfirst-index-csv v0.0.0-20191002171239-c6712fe20972/go.mod h1:TNMdhUDIVyCrcr9WziZRt9UARQAvM/T1x4h69gVkxsA=
117119
github.com/whosonfirst/go-whosonfirst-index-sqlite v0.0.2 h1:rmp0Nm6adNVPEZ7A/LlvNjK8ANHzLm6z03aNR9yQ028=
@@ -143,6 +145,8 @@ github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.3 h1:XqYn6pnl9J63FZ99
143145
github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.3/go.mod h1:zbwNL08/j8uJ6fpYMYrFK8Pb3ZoA/ZcAaNYvvFq5o9U=
144146
github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.4 h1:asuQX5Nj/nKXmxuiVKcfJTdvldEqjnDpm1VwwFB5Mc4=
145147
github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.4/go.mod h1:zbwNL08/j8uJ6fpYMYrFK8Pb3ZoA/ZcAaNYvvFq5o9U=
148+
github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.5 h1:sicGwGk1YK26M9P+s197ZkPiuqG8jv7J9UP0UEBV5+4=
149+
github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.5/go.mod h1:jXNvI/rNqrL9nXkTefSBChmepQuOn9YMb/xK1LDO+jA=
146150
github.com/whosonfirst/go-whosonfirst-sqlite-index v0.0.1 h1:/GuAgxIHn5vZwAEDA4XUSWe7rYWZW30I4HLQRTpBeJY=
147151
github.com/whosonfirst/go-whosonfirst-sqlite-index v0.0.1/go.mod h1:5fY1ikCDhe1u0umawonTOICPzv/2CgfFT9hTAen5nsI=
148152
github.com/whosonfirst/go-whosonfirst-sqlite-index v0.1.0 h1:/tljUy2rchRC9XE4FDteNmYZYhYqxWX2uF4c61WlocU=

index.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@ import (
1111
"github.com/whosonfirst/warning"
1212
"io"
1313
"io/ioutil"
14-
_ "log"
14+
"log"
1515
)
1616

17-
func NewDefaultSQLiteFeaturesIndexer(db sqlite.Database, to_index []sqlite.Table) (*sql_index.SQLiteIndexer, error) {
17+
type SQLiteFeaturesIndexerCallbackOptions struct {
18+
StrictAltFiles bool
19+
}
20+
21+
func DefaultSQLiteFeaturesIndexerCallbackOptions() *SQLiteFeaturesIndexerCallbackOptions {
22+
23+
opts := &SQLiteFeaturesIndexerCallbackOptions{
24+
StrictAltFiles: true,
25+
}
26+
27+
return opts
28+
}
29+
30+
func SQLiteFeaturesIndexerCallback(opts *SQLiteFeaturesIndexerCallbackOptions) sql_index.SQLiteIndexerFunc {
1831

1932
cb := func(ctx context.Context, fh io.Reader, args ...interface{}) (interface{}, error) {
2033

@@ -30,6 +43,12 @@ func NewDefaultSQLiteFeaturesIndexer(db sqlite.Database, to_index []sqlite.Table
3043
return nil, err
3144
}
3245

46+
// we read the whole thing in to memory here so don't
47+
// have to worry about whether fh is a ReadSeeker if
48+
// the first attempt to load a primary WOF file fails
49+
// and we try again for an alt file
50+
// (20191103/straup)
51+
3352
body, err := ioutil.ReadAll(fh)
3453

3554
if err != nil {
@@ -43,7 +62,14 @@ func NewDefaultSQLiteFeaturesIndexer(db sqlite.Database, to_index []sqlite.Table
4362
alt, alt_err := feature.NewWOFAltFeature(body)
4463

4564
if alt_err != nil && !warning.IsWarning(alt_err) {
65+
4666
msg := fmt.Sprintf("Unable to load %s, because %s (%s)", path, alt_err, err)
67+
68+
if !opts.StrictAltFiles {
69+
log.Printf("%s - SKIPPING\n", msg)
70+
return nil, nil
71+
}
72+
4773
return nil, errors.New(msg)
4874
}
4975

@@ -54,5 +80,17 @@ func NewDefaultSQLiteFeaturesIndexer(db sqlite.Database, to_index []sqlite.Table
5480
}
5581
}
5682

83+
return cb
84+
}
85+
86+
func NewDefaultSQLiteFeaturesIndexer(db sqlite.Database, to_index []sqlite.Table) (*sql_index.SQLiteIndexer, error) {
87+
88+
opts := DefaultSQLiteFeaturesIndexerCallbackOptions()
89+
cb := SQLiteFeaturesIndexerCallback(opts)
90+
91+
return NewSQLiteFeaturesIndexerWithCallback(db, to_index, cb)
92+
}
93+
94+
func NewSQLiteFeaturesIndexerWithCallback(db sqlite.Database, to_index []sqlite.Table, cb sql_index.SQLiteIndexerFunc) (*sql_index.SQLiteIndexer, error) {
5795
return sql_index.NewSQLiteIndexer(db, to_index, cb)
5896
}

vendor/github.com/whosonfirst/go-whosonfirst-index/index.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/whosonfirst/go-whosonfirst-sqlite-features/go.mod

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/whosonfirst/go-whosonfirst-sqlite-features/go.sum

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/whosonfirst/go-whosonfirst-sqlite-index/index.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ github.com/whosonfirst/go-whosonfirst-geojson-v2/properties/whosonfirst
3838
github.com/whosonfirst/go-whosonfirst-geojson-v2/utils
3939
# github.com/whosonfirst/go-whosonfirst-hash v0.1.0
4040
github.com/whosonfirst/go-whosonfirst-hash
41-
# github.com/whosonfirst/go-whosonfirst-index v0.2.2
41+
# github.com/whosonfirst/go-whosonfirst-index v0.2.3
4242
github.com/whosonfirst/go-whosonfirst-index
4343
github.com/whosonfirst/go-whosonfirst-index/fs
4444
# github.com/whosonfirst/go-whosonfirst-index-csv v0.0.0-20191002171239-c6712fe20972
@@ -62,7 +62,7 @@ github.com/whosonfirst/go-whosonfirst-spr
6262
github.com/whosonfirst/go-whosonfirst-sqlite
6363
github.com/whosonfirst/go-whosonfirst-sqlite/database
6464
github.com/whosonfirst/go-whosonfirst-sqlite/utils
65-
# github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.4
65+
# github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.5
6666
github.com/whosonfirst/go-whosonfirst-sqlite-features/tables
6767
github.com/whosonfirst/go-whosonfirst-sqlite-features
6868
# github.com/whosonfirst/go-whosonfirst-sqlite-index v0.1.0

0 commit comments

Comments
 (0)