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 time() function in binary comparisons #1888

Merged
merged 6 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/query/block/accounted.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,27 @@ package block

import "github.com/m3db/m3/src/query/cost"

// AccountedBlock is a wrapper for a block which enforces limits on the number of datapoints used by the block.
// AccountedBlock is a wrapper for a block which enforces limits on the number
// of datapoints used by the block.
type AccountedBlock struct {
Block

enforcer cost.ChainedEnforcer
}

// NewAccountedBlock wraps the given block and enforces datapoint limits.
func NewAccountedBlock(wrapped Block, enforcer cost.ChainedEnforcer) *AccountedBlock {
func NewAccountedBlock(
wrapped Block,
enforcer cost.ChainedEnforcer,
) *AccountedBlock {
return &AccountedBlock{
Block: wrapped,
enforcer: enforcer,
}
}

// Close closes the block, and marks the number of datapoints used by this block as finished.
// Close closes the block, and marks the number of datapoints used
// by this block as finished.
func (ab *AccountedBlock) Close() error {
ab.enforcer.Close()
return ab.Block.Close()
Expand Down
7 changes: 6 additions & 1 deletion src/query/block/accounted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/m3db/m3/src/query/cost"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)

func TestAccountedBlock_Close(t *testing.T) {
Expand All @@ -37,5 +38,9 @@ func TestAccountedBlock_Close(t *testing.T) {
mockEnforcer := cost.NewMockChainedEnforcer(ctrl)
mockEnforcer.EXPECT().Close()

NewAccountedBlock(wrapped, mockEnforcer).Close()
block := NewAccountedBlock(wrapped, mockEnforcer)

wrapped.EXPECT().Info().Return(NewBlockInformation(BlockM3TSZCompressed))
assert.Equal(t, BlockM3TSZCompressed, block.Info().Type())
assert.NotPanics(t, func() { block.Close() })
}
26 changes: 26 additions & 0 deletions src/query/block/block_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/query/block/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ColumnBlockBuilder struct {
}

type columnBlock struct {
blockType BlockType
columns []column
meta Metadata
seriesMeta []SeriesMeta
Expand Down Expand Up @@ -78,6 +79,7 @@ func (c *columnBlock) WithMetadata(
columns: c.columns,
meta: meta,
seriesMeta: seriesMetas,
blockType: BlockDecompressed,
}, nil
}

Expand All @@ -90,6 +92,10 @@ func (c *columnBlock) StepCount() int {
return len(c.columns)
}

func (c *columnBlock) Info() BlockInformation {
return NewBlockInformation(c.blockType)
}

// Close frees up any resources
// TODO: actually free up the resources
func (c *columnBlock) Close() error {
Expand Down Expand Up @@ -182,10 +188,15 @@ func NewColumnBlockBuilder(
block: &columnBlock{
meta: meta,
seriesMeta: seriesMeta,
blockType: BlockDecompressed,
},
}
}

func (cb ColumnBlockBuilder) SetBlockType(blockType BlockType) {
cb.block.blockType = blockType
}

// AppendValue adds a value to a column at index
func (cb ColumnBlockBuilder) AppendValue(idx int, value float64) error {
columns := cb.block.columns
Expand Down
46 changes: 46 additions & 0 deletions src/query/block/column_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 (
"context"
"testing"

"github.com/m3db/m3/src/query/cost"
"github.com/m3db/m3/src/query/models"
"github.com/stretchr/testify/assert"

"github.com/uber-go/tally"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Combine the external imports here? (don't know why linter is clearly not working...)

i.e. this should be:

	"context"
	"testing"

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

	"github.com/stretchr/testify/assert"
 	"github.com/uber-go/tally"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha can't say I miss the linter no longer breaking builds, but will fix it up

)

func TestColumnBuilderInfoTypes(t *testing.T) {
ctx := models.NewQueryContext(context.Background(),
tally.NoopScope, cost.NoopChainedEnforcer(),
models.QueryContextOptions{})

builder := NewColumnBlockBuilder(ctx, Metadata{}, []SeriesMeta{})
block := builder.Build()
assert.Equal(t, BlockDecompressed, block.Info().blockType)

block = builder.Build()
builder.SetBlockType(BlockScalar)
assert.Equal(t, BlockScalar, block.Info().blockType)
}
4 changes: 4 additions & 0 deletions src/query/block/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (b *containerBlock) AddBlock(bl Block) error {
return nil
}

func (c *containerBlock) Info() BlockInformation {
return NewBlockInformation(BlockContainer)
}

func (b *containerBlock) Close() error {
multiErr := xerrors.NewMultiError()
multiErr = multiErr.Add(b.err)
Expand Down
86 changes: 86 additions & 0 deletions src/query/block/information.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) 2019 Uber Technologies, Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: Rename this file info.go for more "Go-ish" name?

//
// 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

func (t BlockType) String() string {
switch t {
case BlockM3TSZCompressed:
return "M3TSZ_compressed"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this should be upper case and rest lower? Maybe we should make it just "compressedM3TSZ" for lower camel casing or "compressed_m3tsz" if we want to do lowercase underscore separated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM; don't really see this used as anything other than as human-readable debug info since it's all runtime stuff so makes sense to pretty it up 👍

case BlockDecompressed:
return "decompressed"
case BlockScalar:
return "scalar"
case BlockLazy:
return "lazy"
case BlockTime:
return "time"
case BlockContainer:
return "container"
case BlockWrapper:
return "wrapper"
case BlockConsolidated:
return "consolidated"
}

return "unknown"
}

type BlockInformation struct {
Copy link
Collaborator

@robskillington robskillington Aug 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this just BlockInfo? Sounds more "Go-ish" (I know that's so subjective obviously though...).

Also needs comment yeah? (think the exported types in this file are all missing comments)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah fair enough; thought the general idea was functions and types have full names but variables have Go-ish names, will change it

blockType BlockType
inner []BlockType
}

func NewBlockInformation(blockType BlockType) BlockInformation {
return BlockInformation{blockType: blockType}
}

func NewWrappedBlockInformation(
blockType BlockType,
wrap BlockInformation,
) BlockInformation {
inner := make([]BlockType, len(wrap.inner)+1)
copy(inner[:1], wrap.inner)
inner[0] = wrap.blockType
return BlockInformation{
blockType: blockType,
inner: inner,
}
}

func (b BlockInformation) Type() BlockType {
return b.blockType
}

func (b BlockInformation) InnerType() BlockType {
if b.inner == nil {
return b.Type()
}

return b.inner[0]
}

func (b BlockInformation) BaseType() BlockType {
if b.inner == nil {
return b.Type()
}

return b.inner[len(b.inner)-1]
}
4 changes: 4 additions & 0 deletions src/query/block/lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func NewLazyBlock(block Block, opts LazyOptions) Block {
}
}

func (c *lazyBlock) Info() BlockInformation {
return NewWrappedBlockInformation(BlockLazy, c.block.Info())
}

func (b *lazyBlock) Close() error { return b.block.Close() }

func (b *lazyBlock) WithMetadata(
Expand Down
5 changes: 5 additions & 0 deletions src/query/block/lazy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func TestValidOffset(t *testing.T) {
offset := time.Minute
off := NewLazyBlock(b, testLazyOpts(offset, 1.0))

b.EXPECT().Info().Return(NewBlockInformation(BlockM3TSZCompressed))
info := off.Info()
assert.Equal(t, BlockLazy, info.Type())
assert.Equal(t, BlockM3TSZCompressed, info.BaseType())

// ensure functions are marshalled to the underlying block.
b.EXPECT().Close().Return(nil)
err := off.Close()
Expand Down
Loading