Skip to content

Commit fbbf0cc

Browse files
authored
Row count is incorrect when using aggregator connections. Closes #402
1 parent 778b52f commit fbbf0cc

File tree

6 files changed

+52
-36
lines changed

6 files changed

+52
-36
lines changed

.idea/modules.xml

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

.idea/steampipe-postgres-fdw.iml

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

hub/hub.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,24 @@ func (h *Hub) AddScanMetadata(iter Iterator) {
195195
return
196196
}
197197

198-
// get list of scan metadata from iterator (may be more than 1 for group_iterator)
199-
scanMetadata := iter.GetScanMetadata()
200-
for _, m := range scanMetadata {
201-
// set ID
202-
m.Id = id
203-
id++
204-
log.Printf("[TRACE] got metadata table: %s cache hit: %v, rows fetched %d, hydrate calls: %d",
205-
m.Table, m.CacheHit, m.RowsFetched, m.HydrateCalls)
206-
// read the scan metadata from the iterator and add to our stack
207-
h.scanMetadata = append(h.scanMetadata, m)
208-
209-
// hydrate metric labels
210-
labels := []attribute.KeyValue{
211-
attribute.String("table", m.Table),
212-
attribute.String("connection", connectionName),
213-
attribute.String("plugin", connectionPlugin.PluginName),
214-
}
215-
log.Printf("[TRACE] update hydrate calls counter with %d", m.HydrateCalls)
216-
h.hydrateCallsCounter.Add(ctx, m.HydrateCalls, metric.WithAttributes(labels...))
198+
// get scan metadata from iterator
199+
m := iter.GetScanMetadata()
200+
201+
// set ID
202+
m.Id = id
203+
log.Printf("[TRACE] got metadata table: %s cache hit: %v, rows fetched %d, hydrate calls: %d",
204+
m.Table, m.CacheHit, m.RowsFetched, m.HydrateCalls)
205+
// read the scan metadata from the iterator and add to our stack
206+
h.scanMetadata = append(h.scanMetadata, m)
207+
208+
// hydrate metric labels
209+
labels := []attribute.KeyValue{
210+
attribute.String("table", m.Table),
211+
attribute.String("connection", connectionName),
212+
attribute.String("plugin", connectionPlugin.PluginName),
217213
}
214+
log.Printf("[TRACE] update hydrate calls counter with %d", m.HydrateCalls)
215+
h.hydrateCallsCounter.Add(ctx, m.HydrateCalls, metric.WithAttributes(labels...))
218216

219217
// now trim scan metadata - max 1000 items
220218
const maxMetadataItems = 1000

hub/in_memory_iterator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (i *inMemoryIterator) CanIterate() bool {
6565
}
6666
}
6767

68-
func (i *inMemoryIterator) GetScanMetadata() []ScanMetadata {
69-
return nil
68+
func (i *inMemoryIterator) GetScanMetadata() ScanMetadata {
69+
return ScanMetadata{}
7070
}
7171
func (i *inMemoryIterator) GetTraceContext() *telemetry.TraceCtx {
7272
return &telemetry.TraceCtx{Ctx: context.Background()}

hub/iterator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ type Iterator interface {
1414
Status() queryStatus
1515
Error() error
1616
CanIterate() bool
17-
GetScanMetadata() []ScanMetadata
17+
GetScanMetadata() ScanMetadata
1818
GetTraceContext() *telemetry.TraceCtx
1919
}

hub/scan_iterator.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,24 @@ func (i *scanIterator) CanIterate() bool {
173173

174174
}
175175

176-
func (i *scanIterator) GetScanMetadata() []ScanMetadata {
177-
res := make([]ScanMetadata, len(i.scanMetadata))
178-
idx := 0
176+
// GetScanMetadata returns the scan metadata for this iterator
177+
// note: if this is an aggregator query, we will have a scan metadata for each connection
178+
// we need to combine them into a single scan metadata object
179+
func (i *scanIterator) GetScanMetadata() ScanMetadata {
180+
res := ScanMetadata{
181+
Table: i.table,
182+
Columns: i.queryContext.Columns,
183+
Quals: i.queryContext.Quals,
184+
StartTime: i.startTime,
185+
Duration: time.Since(i.startTime),
186+
}
179187
for _, m := range i.scanMetadata {
180-
res[idx] = ScanMetadata{
181-
Table: i.table,
182-
CacheHit: m.CacheHit,
183-
RowsFetched: m.RowsFetched,
184-
HydrateCalls: m.HydrateCalls,
185-
Columns: i.queryContext.Columns,
186-
Quals: i.queryContext.Quals,
187-
StartTime: i.startTime,
188-
Duration: time.Since(i.startTime),
189-
}
190-
idx++
188+
res.CacheHit = res.CacheHit || m.CacheHit
189+
res.RowsFetched += m.RowsFetched
190+
res.HydrateCalls += m.HydrateCalls
191191
}
192192
return res
193+
193194
}
194195

195196
func (i *scanIterator) GetTraceContext() *telemetry.TraceCtx {

0 commit comments

Comments
 (0)