db

package
v0.0.0-...-7129fda Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StoredSchemasTable          = "analysis_schemas"
	StoredSchemaName            = "table_name"
	StoredSchemaColumnNames     = "column_names"
	StoredSchemaColumnDataTypes = "column_data_types"
	StoredSchemaColumnOptionals = "column_optionals"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatedValues

type AggregatedValues interface {
	Insert(index int, item any) (ok bool)
	InsertZero(index int)
	AddZeroesUpToLength(length int)
	Total(dataType DataType) (DBValue, error)
	Truncate(maxLength int)
}

func NewAggregatedValues

func NewAggregatedValues(dataType DataType, capacity int) (AggregatedValues, error)

type Aggregation

type Aggregation struct {
	Kind      AggregationKind `json:"kind"`
	FieldName string          `json:"fieldName"`
	DataType  DataType        `json:"dataType"`
}

type AggregationKind

type AggregationKind int8
const (
	AggregationSum AggregationKind = iota + 1
	AggregationAverage
	AggregationMin
	AggregationMax
	AggregationCount
)

func (AggregationKind) IsValid

func (kind AggregationKind) IsValid() bool

func (AggregationKind) MarshalJSON

func (kind AggregationKind) MarshalJSON() ([]byte, error)

func (AggregationKind) String

func (kind AggregationKind) String() string

func (*AggregationKind) UnmarshalJSON

func (kind *AggregationKind) UnmarshalJSON(bytes []byte) error

type AnalysisDB

type AnalysisDB interface {
	RunAnalysisQuery(
		ctx context.Context,
		analysis AnalysisQuery,
		table string,
	) (AnalysisResult, error)

	CreateTable(ctx context.Context, schema TableSchema) error

	IngestData(ctx context.Context, data DataSource, schema TableSchema) error

	DropTable(ctx context.Context, table string) (alreadyDropped bool, err error)

	CreateStoredSchemasTable(ctx context.Context) error

	StoreTableSchema(ctx context.Context, schema TableSchema) error

	GetTableSchema(ctx context.Context, table string) (TableSchema, error)

	DeleteTableSchema(ctx context.Context, table string) error
}

type AnalysisQuery

type AnalysisQuery struct {
	Aggregation Aggregation `json:"aggregation"`
	RowSplit    Split       `json:"rowSplit"`
	ColumnSplit Split       `json:"columnSplit"`
}

type AnalysisResult

type AnalysisResult struct {
	Rows     []RowResult `json:"rows"`
	RowsMeta Split       `json:"rowsMeta"`

	Columns     []ColumnResult `json:"columns"`
	ColumnsMeta Split          `json:"columnsMeta"`

	AggregationDataType DataType `json:"aggregationDataType"`
}

func NewAnalysisQueryResult

func NewAnalysisQueryResult(analysis AnalysisQuery) AnalysisResult

func (*AnalysisResult) Finalize

func (analysisResult *AnalysisResult) Finalize() error

func (*AnalysisResult) GetOrCreateRowResult

func (analysisResult *AnalysisResult) GetOrCreateRowResult(
	handle ResultHandle,
) (rowResult RowResult, err error)

func (*AnalysisResult) InitializeColumnResult

func (analysisResult *AnalysisResult) InitializeColumnResult(
	handle ResultHandle,
) (columnIndex int, err error)

func (*AnalysisResult) NewResultHandle

func (analysisResult *AnalysisResult) NewResultHandle() (handle ResultHandle, err error)

func (*AnalysisResult) ParseResultHandle

func (analysisResult *AnalysisResult) ParseResultHandle(handle ResultHandle) error

type Column

type Column struct {
	Name     string   `json:"name"`
	DataType DataType `json:"dataType"`
	Optional bool     `json:"optional"`
}

func (Column) Validate

func (column Column) Validate() error

type ColumnResult

type ColumnResult struct {
	FieldValue DBValue `json:"fieldValue"`
}

type DBValue

type DBValue interface {
	Value() any
	Pointer() any
	Set(value any) (ok bool)
	Equals(value any) bool
	LessThan(value any) (less bool, err error)
}

func NewDBValue

func NewDBValue(dataType DataType) (DBValue, error)

type DataSource

type DataSource interface {
	ReadRow() (row []string, rowNumber int, done bool, err error)
}

type DataType

type DataType int8
const (
	DataTypeText DataType = iota + 1
	DataTypeInt
	DataTypeFloat
	DataTypeDateTime
	DataTypeUUID
)

func (DataType) IsValid

func (dataType DataType) IsValid() bool

func (DataType) IsValidForAggregation

func (dataType DataType) IsValidForAggregation() error

func (DataType) MarshalJSON

func (dataType DataType) MarshalJSON() ([]byte, error)

func (DataType) String

func (dataType DataType) String() string

func (*DataType) UnmarshalJSON

func (dataType *DataType) UnmarshalJSON(bytes []byte) error

type DateInterval

type DateInterval int8
const (
	DateIntervalYear DateInterval = iota + 1
	DateIntervalQuarter
	DateIntervalMonth
	DateIntervalWeek
	DateIntervalDay
)

func (DateInterval) IsNone

func (dateInterval DateInterval) IsNone() bool

func (DateInterval) IsValid

func (dateInterval DateInterval) IsValid() bool

func (DateInterval) MarshalJSON

func (dateInterval DateInterval) MarshalJSON() ([]byte, error)

func (DateInterval) String

func (dateInterval DateInterval) String() string

func (*DateInterval) UnmarshalJSON

func (dateInterval *DateInterval) UnmarshalJSON(data []byte) error

type ResultHandle

type ResultHandle struct {
	Aggregation DBValue
	Row         DBValue
	Column      DBValue
}

type RowResult

type RowResult struct {
	FieldValue           DBValue          `json:"fieldValue"`
	AggregationTotal     DBValue          `json:"aggregationTotal"`
	AggregationsByColumn AggregatedValues `json:"aggregationsByColumn"`
}

type SortOrder

type SortOrder int8
const (
	SortOrderAscending SortOrder = iota + 1
	SortOrderDescending
)

func (SortOrder) IsValid

func (sortOrder SortOrder) IsValid() bool

func (SortOrder) MarshalJSON

func (sortOrder SortOrder) MarshalJSON() ([]byte, error)

func (SortOrder) String

func (sortOrder SortOrder) String() string

func (*SortOrder) UnmarshalJSON

func (sortOrder *SortOrder) UnmarshalJSON(bytes []byte) error

type Split

type Split struct {
	FieldName string    `json:"fieldName"`
	DataType  DataType  `json:"dataType"`
	Limit     int       `json:"limit"`
	SortOrder SortOrder `json:"sortOrder"`
	// May only be present if DataType is INTEGER.
	IntegerInterval int `json:"integerInterval,omitempty"`
	// May only be present if DataType is FLOAT.
	FloatInterval float64 `json:"floatInterval,omitempty"`
	// May only be present if DataType is DATETIME.
	DateInterval DateInterval `json:"dateInterval,omitempty"`
}

type StoredTableSchema

type StoredTableSchema struct {
	TableName   string   `json:"table_name"`
	ColumnNames []string `json:"column_names"`
	DataTypes   []int8   `json:"column_data_types"`
	Optionals   []bool   `json:"column_optionals"`
}

func (StoredTableSchema) ToSchema

func (storedSchema StoredTableSchema) ToSchema() (TableSchema, error)

type TableSchema

type TableSchema struct {
	TableName string   `json:"tableName"`
	Columns   []Column `json:"columns"`
}

func NewTableSchema

func NewTableSchema(columnNames []string) TableSchema

func (TableSchema) ConvertAndAppendRow

func (schema TableSchema) ConvertAndAppendRow(convertedRow []any, rawRow []string) ([]any, error)

func (TableSchema) ConvertRowToMap

func (schema TableSchema) ConvertRowToMap(rawRow []string) (map[string]any, error)

func (TableSchema) DeduceDataTypesFromRow

func (schema TableSchema) DeduceDataTypesFromRow(row []string) error

func (TableSchema) ToStored

func (schema TableSchema) ToStored() StoredTableSchema

func (TableSchema) Validate

func (schema TableSchema) Validate() error

func (TableSchema) ValidateColumns

func (schema TableSchema) ValidateColumns() []error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL