Skip to content

Fix: Handle count 1 with removeBorderValues returning empty results#438

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-261
Draft

Fix: Handle count 1 with removeBorderValues returning empty results#438
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-261

Conversation

Copy link

Copilot AI commented Sep 13, 2025

This PR fixes an issue where using getHistory with removeBorderValues: true and count: 1 would return empty results even when datapoints existed in the database.

Problem

When users specified these parameters together:

const result = await getHistoryAsync('influxdb.0', {
    id: 'measurement.id',
    start: startTime,
    end: endTime,
    removeBorderValues: true,
    returnNewestEntries: true,
    aggregate: 'none',
    count: 1
});

They would sometimes get empty results ([]) even though:

  • Without count: 1, the same query would return multiple results
  • Data points existed in the database for that time range

Root Cause

The issue occurred in the beautify function in lib/aggregate.js. When InfluxDB returned data points that were slightly outside the exact time range (which can happen due to timing precision or grouping behavior), the beautify function would filter out all data points based on strict timestamp boundaries. With count: 1, if the only available data point was outside the precise time boundaries, it would be completely filtered out, resulting in empty results.

Solution

Added intelligent edge case handling in the beautify function that:

  1. Detects the problematic scenario: When removeBorderValues: true and count are specified together, and all data was filtered out due to time range restrictions but original data existed before filtering

  2. Restores closest data points: Instead of returning empty results, the fix identifies and restores the closest data point(s) to satisfy the count requirement

  3. Preserves existing behavior: The fix only activates in the specific edge case and doesn't affect any other functionality

Testing

The fix has been thoroughly tested with multiple scenarios:

  • Normal cases (data within time range) work unchanged
  • Edge case fixed (data outside time range now returns closest points)
  • Works with different count values (1, 2, etc.)
  • Doesn't affect removeBorderValues: false behavior
  • Handles multiple data points correctly

Example of the fix in action:

// Before fix: Returns [] even with available data
// After fix: Returns closest data point
[
  {
    "ts": 1652825992700,
    "val": 1.5,
    "ack": true
  }
]

Fixes #261.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Author

Copilot AI commented Sep 13, 2025

@GermanBluefox 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: GermanBluefox <4582016+GermanBluefox@users.noreply.github.com>
Copilot AI changed the title [WIP] Using count 1 with removeBorderValues can return empty query even if we have datapoints in time range (assumption) Fix: Handle count 1 with removeBorderValues returning empty results Sep 13, 2025
Copilot AI requested a review from GermanBluefox September 13, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using count 1 with removeBorderValues can return empty query even if we have datapoints in time range (assumption)

2 participants