featurebase/sql/model.go
Travis Turner aa17b8d725
Enable linter: stylecheck (#2317)
* Enable linter: stylecheck

This enabled the stylecheck linter, but excludes some staticchecks for
now. The following are ignored because they will take a bit of time to
address, but the intention is to address them and remove them from the
exclusion list.

ST1000: at least one file in a package should have a package comment
ST1003: golang naming standards
ST1008: error should be returned as the last argument
ST1016: methods on the same type should have the same receiver name
ST1020: comment on exported function

* Address ST1015

For some reason this failed in CI but not locally. I can't figure out
why that check isn't happening locally. This just moves the switch
statements around so that the `default` is the first (or last) item.

* Adjust error string in test to match case-adjusted error

* Remove TestCloseTimeout
2023-03-14 08:45:18 -05:00

130 lines
2.3 KiB
Go

// Copyright 2022 Molecula Corp. (DBA FeatureBase).
// SPDX-License-Identifier: Apache-2.0
package sql
import (
"fmt"
pilosa "github.com/featurebasedb/featurebase/v3"
"github.com/pkg/errors"
)
var (
ErrUnsupportedQuery = errors.New("unsupported query")
)
// KeyIndexColumn is a column for a keyed index.
// TODO: what the difference between this and IDIndexColumn?
type KeyIndexColumn struct {
Index *pilosa.Index
text string
alias string
}
func NewKeyIndexColumn(index *pilosa.Index, alias string) *KeyIndexColumn {
return &KeyIndexColumn{
Index: index,
text: ColID,
alias: alias,
}
}
func (i *KeyIndexColumn) Source() string {
return "" // TODO
}
func (i *KeyIndexColumn) Name() string {
return i.text
}
func (i *KeyIndexColumn) Alias() string {
if i.alias != "" {
return i.alias
}
return i.Name()
}
type IDIndexColumn struct {
Index *pilosa.Index
text string
alias string
}
func NewIDIndexColumn(index *pilosa.Index, alias string) *IDIndexColumn {
return &IDIndexColumn{
Index: index,
text: ColID,
alias: alias,
}
}
func (i *IDIndexColumn) Source() string {
return "" // TODO
}
func (i *IDIndexColumn) Name() string {
return i.text
}
func (i *IDIndexColumn) Alias() string {
if i.alias != "" {
return i.alias
}
return i.Name()
}
type FieldColumn struct {
Field *pilosa.Field
text string
alias string
}
func NewFieldColumn(field *pilosa.Field, alias string) *FieldColumn {
return &FieldColumn{
Field: field,
text: field.Name(),
alias: alias,
}
}
func (f *FieldColumn) Source() string {
return ""
}
func (f *FieldColumn) Name() string {
return f.text
}
func (f *FieldColumn) Alias() string {
if f.alias != "" {
return f.alias
}
return f.Name()
}
type FuncColumn struct {
Field *pilosa.Field
FuncName FuncName
alias string
}
func NewFuncColumn(funcName FuncName, field *pilosa.Field, alias string) *FuncColumn {
return &FuncColumn{
Field: field,
FuncName: funcName,
alias: alias,
}
}
func (f *FuncColumn) Source() string {
return string(f.FuncName)
}
func (f *FuncColumn) Name() string {
fieldName := "*"
if f.Field != nil {
fieldName = f.Field.Name()
}
return fmt.Sprintf("%s(%s)", f.FuncName, fieldName)
}
func (f *FuncColumn) Alias() string {
if f.alias != "" {
return f.alias
}
return f.Name()
}