Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[query] Fix absent function to work correctly #1871

Merged
merged 12 commits into from
Aug 22, 2019
40 changes: 40 additions & 0 deletions src/query/block/block_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package block

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func CompareMeta(t *testing.T, ex, ac Metadata) {
expectedTags := ex.Tags.Tags
actualTags := ac.Tags.Tags
require.Equal(t, len(expectedTags), len(actualTags))
for i, tag := range expectedTags {
assert.Equal(t, string(tag.Name), string(actualTags[i].Name))
assert.Equal(t, string(tag.Value), string(actualTags[i].Value))
}

assert.True(t, ex.Bounds.Equals(ac.Bounds))
}
4 changes: 2 additions & 2 deletions src/query/block/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ func (m *columnBlockSeriesIter) Next() bool {
}

cols := m.columns
for i := 0; i < len(cols); i++ {
m.values[i] = cols[i].Values[m.idx]
for i, col := range cols {
m.values[i] = col.Values[m.idx]
}

return next
Expand Down
130 changes: 130 additions & 0 deletions src/query/block/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package block

type emptyBlock struct {
meta Metadata
}

// NewEmptyBlock creates an empty block with the given metadata.
func NewEmptyBlock(meta Metadata) Block {
return &emptyBlock{meta: meta}
}

func (b *emptyBlock) Close() error { return nil }

func (b *emptyBlock) WithMetadata(meta Metadata, _ []SeriesMeta) (Block, error) {
return NewEmptyBlock(meta), nil
}

func (b *emptyBlock) StepIter() (StepIter, error) {
return &emptyStepIter{meta: b.meta}, nil
}

type emptyStepIter struct {
meta Metadata
}

func (it *emptyStepIter) Close() {}
func (it *emptyStepIter) Err() error { return nil }
func (it *emptyStepIter) StepCount() int { return it.meta.Bounds.Steps() }
func (it *emptyStepIter) SeriesMeta() []SeriesMeta { return []SeriesMeta{} }
func (it *emptyStepIter) Next() bool { return false }
func (it *emptyStepIter) Meta() Metadata { return it.meta }
func (it *emptyStepIter) Current() Step { return nil }

func (b *emptyBlock) SeriesIter() (SeriesIter, error) {
return &emptySeriesIter{
meta: b.meta,
}, nil
}

type emptySeriesIter struct {
meta Metadata
}

func (it *emptySeriesIter) Close() {}
func (it *emptySeriesIter) Err() error { return nil }
func (it *emptySeriesIter) SeriesCount() int { return 0 }
func (it *emptySeriesIter) SeriesMeta() []SeriesMeta { return []SeriesMeta{} }
func (it *emptySeriesIter) Next() bool { return false }
func (it *emptySeriesIter) Current() Series { return Series{} }
func (it *emptySeriesIter) Meta() Metadata { return it.meta }

// Unconsolidated returns the unconsolidated version for the block
func (b *emptyBlock) Unconsolidated() (UnconsolidatedBlock, error) {
return &ucEmptyBlock{
meta: b.meta,
}, nil
}

type ucEmptyBlock struct {
meta Metadata
}

func (b *ucEmptyBlock) Close() error { return nil }

func (b *ucEmptyBlock) WithMetadata(
meta Metadata, _ []SeriesMeta) (UnconsolidatedBlock, error) {
return &ucEmptyBlock{
meta: meta,
}, nil
}

func (b *ucEmptyBlock) Consolidate() (Block, error) {
return NewEmptyBlock(b.meta), nil
}

func (b *ucEmptyBlock) StepIter() (UnconsolidatedStepIter, error) {
return &ucEmptyStepIter{
meta: b.meta,
}, nil
}

type ucEmptyStepIter struct {
meta Metadata
}

func (it *ucEmptyStepIter) Close() {}
func (it *ucEmptyStepIter) Err() error { return nil }
func (it *ucEmptyStepIter) StepCount() int { return it.meta.Bounds.Steps() }
func (it *ucEmptyStepIter) SeriesMeta() []SeriesMeta { return []SeriesMeta{} }
func (it *ucEmptyStepIter) Next() bool { return false }
func (it *ucEmptyStepIter) Meta() Metadata { return it.meta }
func (it *ucEmptyStepIter) Current() UnconsolidatedStep { return nil }

func (b *ucEmptyBlock) SeriesIter() (UnconsolidatedSeriesIter, error) {
return &ucEmptySeriesIter{
meta: b.meta,
}, nil
}

type ucEmptySeriesIter struct {
meta Metadata
}

func (it *ucEmptySeriesIter) Close() {}
func (it *ucEmptySeriesIter) Err() error { return nil }
func (it *ucEmptySeriesIter) SeriesCount() int { return 0 }
func (it *ucEmptySeriesIter) SeriesMeta() []SeriesMeta { return []SeriesMeta{} }
func (it *ucEmptySeriesIter) Next() bool { return false }
func (it *ucEmptySeriesIter) Current() UnconsolidatedSeries { return UnconsolidatedSeries{} }
func (it *ucEmptySeriesIter) Meta() Metadata { return it.meta }
99 changes: 99 additions & 0 deletions src/query/block/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package block

import (
"testing"
"time"

"github.com/m3db/m3/src/query/models"

"github.com/stretchr/testify/assert"
)

var (
emptyArgs = []interface{}{}
start = time.Now()
steps = 15
testBound = models.Bounds{
Start: start,
Duration: time.Minute * time.Duration(steps),
StepSize: time.Minute,
}
)

func TestEmptyBlock(t *testing.T) {
meta := MustMakeMeta(testBound, "a", "b")
bl := NewEmptyBlock(meta)

series, err := bl.SeriesIter()
assert.NoError(t, err)
assert.NoError(t, series.Err())
assert.False(t, series.Next())
assert.Equal(t, 0, series.SeriesCount())
assert.Equal(t, []SeriesMeta{}, series.SeriesMeta())
assert.True(t, meta.Equals(series.Meta()))

step, err := bl.StepIter()
assert.NoError(t, err)
assert.NoError(t, step.Err())
assert.False(t, step.Next())
assert.Equal(t, steps, step.StepCount())
assert.Equal(t, []SeriesMeta{}, step.SeriesMeta())
assert.True(t, meta.Equals(step.Meta()))

assert.NotPanics(t, func() {
series.Close()
step.Close()
})

assert.NoError(t, bl.Close())
}

func TestEmptyUnconsolidatedBlock(t *testing.T) {
meta := MustMakeMeta(testBound, "a", "b")
b := NewEmptyBlock(meta)
bl, err := b.Unconsolidated()
assert.NoError(t, err)

series, err := bl.SeriesIter()
assert.NoError(t, err)
assert.NoError(t, series.Err())
assert.False(t, series.Next())
assert.Equal(t, 0, series.SeriesCount())
assert.Equal(t, []SeriesMeta{}, series.SeriesMeta())
assert.True(t, meta.Equals(series.Meta()))

step, err := bl.StepIter()
assert.NoError(t, err)
assert.NoError(t, step.Err())
assert.False(t, step.Next())
assert.Equal(t, steps, step.StepCount())
assert.Equal(t, []SeriesMeta{}, step.SeriesMeta())
assert.True(t, meta.Equals(step.Meta()))

assert.NotPanics(t, func() {
series.Close()
step.Close()
})

assert.NoError(t, bl.Close())
}
45 changes: 45 additions & 0 deletions src/query/block/meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package block

import (
"fmt"

"github.com/m3db/m3/src/query/models"
)

// Metadata is metadata for a block, describing size and common tags accross
// constituent series.
type Metadata struct {
Bounds models.Bounds
Tags models.Tags // Common tags across different series
}

// Equals returns a boolean reporting whether the compared metadata has equal
// fields.
func (m Metadata) Equals(other Metadata) bool {
return m.Tags.Equals(other.Tags) && m.Bounds.Equals(other.Bounds)
}

// String returns a string representation of metadata.
func (m Metadata) String() string {
return fmt.Sprintf("Bounds: %v, Tags: %v", m.Bounds, m.Tags)
}
37 changes: 37 additions & 0 deletions src/query/block/meta_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package block

import (
"testing"

"github.com/m3db/m3/src/query/models"

"github.com/stretchr/testify/assert"
)

func TestMeta(t *testing.T) {
bounds, otherBounds := models.Bounds{}, models.Bounds{}
badBounds := models.Bounds{Duration: 100}

assert.True(t, bounds.Equals(otherBounds))
assert.False(t, bounds.Equals(badBounds))
}
Loading