Skip to content

Commit cb0cada

Browse files
authored
Add support for configuring 'cache' and 'cache_ttl' per instance. Closes #287
1 parent 071e190 commit cb0cada

File tree

7 files changed

+214
-110
lines changed

7 files changed

+214
-110
lines changed

fdw.go

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,20 +447,52 @@ func handleCommandInsert(rinfo *C.ResultRelInfo, slot *C.TupleTableSlot, rel C.R
447447
opts := GetFTableOptions(types.Oid(relid))
448448

449449
switch opts["table"] {
450-
case constants.CommandTableCache:
451-
// we know there is just a single column - operation
452-
var isNull C.bool
453-
datum := C.slot_getattr(slot, 1, &isNull)
454-
operation := C.GoString(C.fdw_datumGetString(datum))
450+
case constants.CommandTableSettings:
451+
tupleDesc := buildTupleDesc(rel.rd_att)
452+
attributes := tupleDesc.Attrs
455453
hub, err := hub.GetHub()
456454
if err != nil {
457455
FdwError(err)
458456
return nil
459457
}
460-
if err := hub.HandleCacheCommand(operation); err != nil {
461-
FdwError(err)
458+
var key *string
459+
var value *string
460+
461+
// iterate through the attributes
462+
for i, a := range attributes {
463+
var isNull C.bool
464+
datum := C.slot_getattr(slot, C.int(i+1), &isNull)
465+
if isNull {
466+
continue
467+
}
468+
// get a string from the memory slot
469+
datumStr := C.GoString(C.fdw_datumGetString(datum))
470+
471+
log.Println("[TRACE] name", a.Name)
472+
log.Println("[TRACE] datum", datum)
473+
log.Println("[TRACE] datumstr", datumStr)
474+
475+
// map it to one of key/value
476+
switch a.Name {
477+
case constants.CommandTableSettingsKeyColumn:
478+
key = &datumStr
479+
case constants.CommandTableSettingsValueColumn:
480+
value = &datumStr
481+
}
482+
}
483+
484+
// if both key and value are not set, ERROR
485+
if key == nil || value == nil {
486+
FdwError(fmt.Errorf("invalid setting: both 'key' and 'value' columns need to be set"))
462487
return nil
463488
}
489+
490+
// apply the setting
491+
if err = hub.ApplySetting(*key, *value); err != nil {
492+
FdwError(err)
493+
}
494+
return nil
495+
464496
}
465497

466498
return nil

go.mod

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ require (
99
github.com/hashicorp/go-version v1.6.0 // indirect
1010
github.com/turbot/go-kit v0.5.0
1111
github.com/turbot/steampipe v0.19.0-rc.10
12-
github.com/turbot/steampipe-plugin-sdk/v5 v5.2.1-alpha.0
12+
github.com/turbot/steampipe-plugin-sdk/v5 v5.3.0-rc.0
1313
go.opentelemetry.io/otel v1.10.0
14-
google.golang.org/protobuf v1.28.1
14+
google.golang.org/protobuf v1.29.1
1515
)
1616

1717
require (
@@ -27,15 +27,22 @@ require (
2727
cloud.google.com/go/storage v1.27.0 // indirect
2828
github.com/aws/aws-sdk-go v1.44.183 // indirect
2929
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
30+
github.com/briandowns/spinner v1.23.0 // indirect
3031
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
3132
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
3233
github.com/hashicorp/go-getter v1.6.2 // indirect
3334
github.com/hashicorp/go-safetemp v1.0.0 // indirect
34-
github.com/jackc/pgx/v5 v5.3.0 // indirect
35+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
36+
github.com/jackc/pgx/v5 v5.3.1 // indirect
3537
github.com/jackc/puddle/v2 v2.2.0 // indirect
3638
github.com/jmespath/go-jmespath v0.4.0 // indirect
39+
github.com/karrick/gows v0.3.0 // indirect
3740
github.com/klauspost/compress v1.11.2 // indirect
41+
github.com/spf13/cobra v1.6.1 // indirect
3842
github.com/ulikunitz/xz v0.5.8 // indirect
43+
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
44+
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
45+
golang.org/x/term v0.6.0 // indirect
3946
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
4047
google.golang.org/api v0.107.0 // indirect
4148
)
@@ -65,7 +72,7 @@ require (
6572
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
6673
github.com/dustin/go-humanize v1.0.0 // indirect
6774
github.com/eko/gocache/v3 v3.1.2 // indirect
68-
github.com/fatih/color v1.14.1 // indirect
75+
github.com/fatih/color v1.15.0 // indirect
6976
github.com/felixge/httpsnoop v1.0.3 // indirect
7077
github.com/fsnotify/fsnotify v1.6.0 // indirect
7178
github.com/gertd/go-pluralize v0.2.1
@@ -83,11 +90,11 @@ require (
8390
github.com/hashicorp/errwrap v1.1.0 // indirect
8491
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
8592
github.com/hashicorp/go-multierror v1.1.1 // indirect
86-
github.com/hashicorp/go-plugin v1.4.8 // indirect
93+
github.com/hashicorp/go-plugin v1.4.9 // indirect
8794
github.com/hashicorp/go-retryablehttp v0.5.2 // indirect
8895
github.com/hashicorp/go-uuid v1.0.1 // indirect
8996
github.com/hashicorp/hcl v1.0.0 // indirect
90-
github.com/hashicorp/hcl/v2 v2.16.1 // indirect
97+
github.com/hashicorp/hcl/v2 v2.16.2 // indirect
9198
github.com/hashicorp/terraform v0.15.1 // indirect
9299
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
93100
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
@@ -101,7 +108,7 @@ require (
101108
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
102109
github.com/magiconair/properties v1.8.7 // indirect
103110
github.com/mattn/go-colorable v0.1.13 // indirect
104-
github.com/mattn/go-isatty v0.0.17 // indirect
111+
github.com/mattn/go-isatty v0.0.18 // indirect
105112
github.com/mattn/go-runewidth v0.0.13 // indirect
106113
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
107114
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
@@ -131,16 +138,14 @@ require (
131138
github.com/spf13/jwalterweatherman v1.1.0 // indirect
132139
github.com/spf13/pflag v1.0.5 // indirect
133140
github.com/spf13/viper v1.15.0 // indirect
134-
github.com/stevenle/topsort v0.0.0-20130922064739-8130c1d7596b // indirect
141+
github.com/stevenle/topsort v0.2.0 // indirect
135142
github.com/subosito/gotenv v1.4.2 // indirect
136143
github.com/tklauser/go-sysconf v0.3.9 // indirect
137144
github.com/tklauser/numcpus v0.3.0 // indirect
138145
github.com/tkrajina/go-reflector v0.5.6 // indirect
139-
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
140-
github.com/vmihailenco/tagparser v0.1.1 // indirect
141-
github.com/xlab/treeprint v1.1.0 // indirect
146+
github.com/xlab/treeprint v1.2.0 // indirect
142147
github.com/yusufpapurcu/wmi v1.2.2 // indirect
143-
github.com/zclconf/go-cty v1.12.1 // indirect
148+
github.com/zclconf/go-cty v1.13.1 // indirect
144149
github.com/zclconf/go-cty-yaml v1.0.3 // indirect
145150
go.opencensus.io v0.24.0 // indirect
146151
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.7.0 // indirect
@@ -154,15 +159,15 @@ require (
154159
go.opentelemetry.io/proto/otlp v0.16.0 // indirect
155160
golang.org/x/crypto v0.6.0 // indirect
156161
golang.org/x/exp v0.0.0-20221110155412-d0897a79cd37 // indirect
157-
golang.org/x/mod v0.6.0 // indirect
158-
golang.org/x/net v0.6.0 // indirect
162+
golang.org/x/mod v0.9.0 // indirect
163+
golang.org/x/net v0.8.0 // indirect
159164
golang.org/x/oauth2 v0.4.0 // indirect
160165
golang.org/x/sync v0.1.0 // indirect
161-
golang.org/x/sys v0.5.0 // indirect
162-
golang.org/x/text v0.7.0 // indirect
166+
golang.org/x/sys v0.6.0 // indirect
167+
golang.org/x/text v0.8.0 // indirect
163168
google.golang.org/appengine v1.6.7 // indirect
164169
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
165-
google.golang.org/grpc v1.53.0 // indirect
170+
google.golang.org/grpc v1.54.0 // indirect
166171
gopkg.in/ini.v1 v1.67.0 // indirect
167172
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
168173
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
@@ -176,4 +181,7 @@ replace (
176181
github.com/deislabs/oras => github.com/oras-project/oras v0.9.0
177182
github.com/docker/distribution => github.com/distribution/distribution v2.7.1+incompatible
178183
github.com/docker/docker => github.com/moby/moby v20.10.17+incompatible
184+
185+
// 3258-updates-in-caching-behaviour
186+
github.com/turbot/steampipe => github.com/turbot/steampipe v1.7.0-rc.0.0.20230327152311-88e87507e979
179187
)

0 commit comments

Comments
 (0)