Skip to content

Commit c170b5d

Browse files
committed
update tests
Signed-off-by: yeya24 <[email protected]>
1 parent 9c6dc46 commit c170b5d

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

integration/parquet_querier_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func TestParquetProjectionPushdown(t *testing.T) {
305305
testCases := []struct {
306306
name string
307307
query string
308-
expectedLabels []string // Labels that should be present in result (besides __name__)
308+
expectedLabels []string // Labels that should be present in result
309309
}{
310310
{
311311
name: "simple_sum_by_job",
@@ -346,17 +346,19 @@ func TestParquetProjectionPushdown(t *testing.T) {
346346
actualLabels[label.Name] = struct{}{}
347347
}
348348

349+
// Check that all expected labels are present
350+
for _, expectedLabel := range tc.expectedLabels {
351+
_, ok := actualLabels[expectedLabel]
352+
require.True(t, ok,
353+
"series should have %s label", expectedLabel)
354+
}
355+
349356
// Check that no unexpected labels are present
350357
for lbl := range actualLabels {
351358
if !slices.Contains(tc.expectedLabels, lbl) {
352-
require.Fail(t, "series should not have %s label", lbl)
359+
require.Fail(t, "series should not have unexpected label: %s", lbl)
353360
}
354361
}
355-
// Check that all expected labels are present
356-
for _, expectedLabel := range tc.expectedLabels {
357-
require.True(t, actualLabels[expectedLabel],
358-
"series should have %s label", expectedLabel)
359-
}
360362
}
361363
})
362364
}

pkg/querier/parquet_queryable.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ func (q *parquetQuerierWithFallback) Select(ctx context.Context, sortSeries bool
510510
}
511511

512512
queryIngesters := q.queryIngestersWithin == 0 || maxt >= util.TimeToMillis(time.Now().Add(-q.queryIngestersWithin).Add(-q.projectionHintsIngesterBuffer))
513-
disableProjection := len(remaining) > 0 || queryIngesters
513+
// Only enable projection if ProjectionInclude is true.
514+
disableProjection := len(remaining) > 0 || queryIngesters || !hints.ProjectionInclude
514515
// Reset projection hints if there are mixed blocks (both parquet and non-parquet) or the query needs to merge results between ingester and parquet blocks
515516
if disableProjection {
516517
hints.ProjectionLabels = nil

pkg/querier/parquet_queryable_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ func TestSelectProjectionHints(t *testing.T) {
643643
projectionHintsIngesterBuffer time.Duration
644644
hasRemainingBlocks bool // Whether there are non-parquet (TSDB) blocks
645645
inputProjectionLabels []string
646+
inputProjectionInclude bool // Input ProjectionInclude value
646647
expectedProjectionLabels []string // nil means projection disabled
647648
expectedProjectionInclude bool
648649
}{
@@ -653,6 +654,7 @@ func TestSelectProjectionHints(t *testing.T) {
653654
projectionHintsIngesterBuffer: 1 * time.Hour,
654655
hasRemainingBlocks: false,
655656
inputProjectionLabels: []string{"__name__", "job"},
657+
inputProjectionInclude: true,
656658
expectedProjectionLabels: []string{"__name__", "job"}, // Preserved
657659
expectedProjectionInclude: true,
658660
},
@@ -663,6 +665,7 @@ func TestSelectProjectionHints(t *testing.T) {
663665
projectionHintsIngesterBuffer: 1 * time.Hour,
664666
hasRemainingBlocks: true, // Mixed blocks
665667
inputProjectionLabels: []string{"__name__", "job"},
668+
inputProjectionInclude: true,
666669
expectedProjectionLabels: nil, // Reset
667670
expectedProjectionInclude: false,
668671
},
@@ -673,6 +676,7 @@ func TestSelectProjectionHints(t *testing.T) {
673676
projectionHintsIngesterBuffer: 1 * time.Hour,
674677
hasRemainingBlocks: false,
675678
inputProjectionLabels: []string{"__name__", "job"},
679+
inputProjectionInclude: true,
676680
expectedProjectionLabels: nil, // Reset (maxT >= now - 2h - 1h = now - 3h)
677681
expectedProjectionInclude: false,
678682
},
@@ -683,6 +687,7 @@ func TestSelectProjectionHints(t *testing.T) {
683687
projectionHintsIngesterBuffer: 1 * time.Hour,
684688
hasRemainingBlocks: false,
685689
inputProjectionLabels: []string{"__name__", "job"},
690+
inputProjectionInclude: true,
686691
expectedProjectionLabels: nil, // Reset (maxT = now - 2.5h, threshold = now - 3h, so 2.5h > 3h means disabled)
687692
expectedProjectionInclude: false,
688693
},
@@ -693,6 +698,7 @@ func TestSelectProjectionHints(t *testing.T) {
693698
projectionHintsIngesterBuffer: 1 * time.Hour,
694699
hasRemainingBlocks: false,
695700
inputProjectionLabels: []string{"__name__", "job"},
701+
inputProjectionInclude: true,
696702
expectedProjectionLabels: nil, // Reset
697703
expectedProjectionInclude: false,
698704
},
@@ -703,6 +709,7 @@ func TestSelectProjectionHints(t *testing.T) {
703709
projectionHintsIngesterBuffer: 1 * time.Hour,
704710
hasRemainingBlocks: false,
705711
inputProjectionLabels: []string{"__name__", "job"},
712+
inputProjectionInclude: true,
706713
expectedProjectionLabels: []string{"__name__", "job"}, // Preserved
707714
expectedProjectionInclude: true,
708715
},
@@ -713,6 +720,7 @@ func TestSelectProjectionHints(t *testing.T) {
713720
projectionHintsIngesterBuffer: 0, // No buffer
714721
hasRemainingBlocks: false,
715722
inputProjectionLabels: []string{"__name__", "job"},
723+
inputProjectionInclude: true,
716724
expectedProjectionLabels: []string{"__name__", "job"}, // Preserved
717725
expectedProjectionInclude: true,
718726
},
@@ -723,9 +731,21 @@ func TestSelectProjectionHints(t *testing.T) {
723731
projectionHintsIngesterBuffer: 1 * time.Hour,
724732
hasRemainingBlocks: false,
725733
inputProjectionLabels: []string{"__name__", "job"},
734+
inputProjectionInclude: true,
726735
expectedProjectionLabels: nil, // Reset
727736
expectedProjectionInclude: false,
728737
},
738+
"projection disabled: ProjectionInclude is false, disable projection": {
739+
minT: util.TimeToMillis(now.Add(-10 * time.Hour)),
740+
maxT: util.TimeToMillis(now.Add(-5 * time.Hour)),
741+
queryIngestersWithin: 2 * time.Hour,
742+
projectionHintsIngesterBuffer: 1 * time.Hour,
743+
hasRemainingBlocks: false,
744+
inputProjectionLabels: []string{"job"},
745+
inputProjectionInclude: false,
746+
expectedProjectionLabels: nil,
747+
expectedProjectionInclude: false,
748+
},
729749
}
730750

731751
for testName, testData := range tests {
@@ -782,7 +802,7 @@ func TestSelectProjectionHints(t *testing.T) {
782802
Start: testData.minT,
783803
End: testData.maxT,
784804
ProjectionLabels: testData.inputProjectionLabels,
785-
ProjectionInclude: true,
805+
ProjectionInclude: testData.inputProjectionInclude,
786806
}
787807

788808
// Execute Select

0 commit comments

Comments
 (0)