postgres

package
v0.0.0-...-0d40728 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// PredictionTableName is the name of the table for prediction requests.
	PredictionTableName = "prediction"
	// RequestTableName is the name of the table for solution requests.
	RequestTableName = "request"

	// SolutionTableName is the name of the table for solutions.
	SolutionTableName = "solution"
	// SolutionFeatureWeightTableName is the name of the table for solution feature weights.
	SolutionFeatureWeightTableName = "solution_weight"
	// SolutionStateTableName is the name of the table for solution state.
	SolutionStateTableName = "solution_state"
	// SolutionResultTableName is the name of the table for the result.
	SolutionResultTableName = "solution_result"
	// SolutionResultExplainOutputTableName is the name of the table for the result explain output.
	SolutionResultExplainOutputTableName = "solution_result_explain"
	// SolutionScoreTableName is the name of the table for the score.
	SolutionScoreTableName = "solution_score"
	// RequestFeatureTableName is the name of the table for the request features.
	RequestFeatureTableName = "request_feature"
	// RequestFilterTableName is the name of the table for the request filters.
	RequestFilterTableName = "request_filter"
	// WordStemTableName is the name of the table for the word stems.
	WordStemTableName = "word_stem"
)

Variables

This section is empty.

Functions

func DefaultPostgresValueFromD3MType

func DefaultPostgresValueFromD3MType(typ string) interface{}

DefaultPostgresValueFromD3MType generates a default postgres value from a d3m type.

func GetIndexStatement

func GetIndexStatement(tableName string, fieldName string, typ string) string

GetIndexStatement returns the index SQL statement for a field of the provided type.

func GetValidTypes

func GetValidTypes() []string

GetValidTypes returns all of the supported types in the DB

func GetViewField

func GetViewField(variable *model.Variable) string

GetViewField returns a SQL string that does a typed select, defaulting as necessary.

func IsColumnType

func IsColumnType(client DatabaseDriver, tableName string, variable *model.Variable, colType string) bool

IsColumnType can be use to check columns potential types

func IsNullable

func IsNullable(typ string) bool

IsNullable indicates whether or not a database type can be empty.

func MapD3MTypeToPostgresType

func MapD3MTypeToPostgresType(typ string) string

MapD3MTypeToPostgresType generates a postgres type from a d3m type.

func MapPostgresTypeToD3MType

func MapPostgresTypeToD3MType(pType string) ([]string, error)

MapPostgresTypeToD3MType converts postgres types to D3M types

func ValueForFieldType

func ValueForFieldType(typ string, field string) string

ValueForFieldType generates the select field value for a given variable type.

Types

type ClientCtor

type ClientCtor func() (DatabaseDriver, error)

ClientCtor repressents a client constructor to instantiate a postgres client.

func NewClient

func NewClient(host string, port int, user string, password string, database string, logLevel string, batch bool) ClientCtor

NewClient instantiates and returns a new postgres client constructor. Log level is one of none, info, warn, error, debug.

type Config

type Config struct {
	Database         string
	Table            string
	User             string
	Password         string
	Port             int
	Host             string
	BatchSize        int
	PostgresLogLevel string
}

Config has the necessary configuration values for a postgres connection.

type CopyFromSource

type CopyFromSource func(*Database, string, *Dataset) error

CopyFromSource represents a function that can use the CopyFrom operation to bulk load the data to SQL.

type Database

type Database struct {
	Client            DatabaseDriver
	Tables            map[string]*Dataset
	BatchSize         int
	BatchSizeStemWord int
	// contains filtered or unexported fields
}

Database is a struct representing a full logical database.

func NewDatabase

func NewDatabase(config *Config, batch bool) (*Database, error)

NewDatabase creates a new database instance.

func (*Database) AddWordStems

func (d *Database) AddWordStems(data []string) error

AddWordStems builds the word stemming lookup in the database.

func (*Database) CreateIndex

func (d *Database) CreateIndex(tableName string, fieldName string, typ string) error

CreateIndex will create an index in postgres on the specified field.

func (*Database) CreateResultTable

func (d *Database) CreateResultTable(tableName string) error

CreateResultTable creates an empty table for the solution results.

func (*Database) CreateSolutionMetadataTables

func (d *Database) CreateSolutionMetadataTables() error

CreateSolutionMetadataTables creates an empty table for the solution results.

func (*Database) DeleteDataset

func (d *Database) DeleteDataset(name string)

DeleteDataset deletes all tables & views for a dataset.

func (*Database) DropTable

func (d *Database) DropTable(tableName string) error

DropTable drops the specified table from the database.

func (*Database) DropView

func (d *Database) DropView(viewName string) error

DropView drops the specified view from the database.

func (*Database) IngestRow

func (d *Database) IngestRow(tableName string, data []string) error

IngestRow parses the raw csv data and stores it to the table specified. The previously parsed metadata is used to map columns.

func (*Database) InitializeDataset

func (d *Database) InitializeDataset(meta *model.Metadata) (*Dataset, error)

InitializeDataset initializes the dataset with the provided metadata.

func (*Database) InitializeTable

func (d *Database) InitializeTable(tableName string, ds *Dataset) error

InitializeTable generates and runs a table create statement based on the schema.

func (*Database) InsertRemainingRows

func (d *Database) InsertRemainingRows() error

InsertRemainingRows empties all batches and inserts the data to the database.

func (*Database) IsArray

func (d *Database) IsArray(typ string) bool

IsArray returns true if the type is an array type.

func (*Database) StoreMetadata

func (d *Database) StoreMetadata(tableName string) error

StoreMetadata stores the variable information to the specified table.

type DatabaseDriver

type DatabaseDriver interface {
	Begin() (pgx.Tx, error)
	Query(string, ...interface{}) (pgx.Rows, error)
	QueryRow(string, ...interface{}) pgx.Row
	Exec(string, ...interface{}) (pgconn.CommandTag, error)
	SendBatch(batch *pgx.Batch) pgx.BatchResults
	CopyFrom(string, []string, [][]interface{}) (int64, error)
}

DatabaseDriver defines the behaviour of the querying engine.

type Dataset

type Dataset struct {
	ID          string
	Name        string
	Description string
	Variables   []*model.Variable
	// contains filtered or unexported fields
}

Dataset is a struct containing the metadata of a dataset being processed.

func NewDataset

func NewDataset(id, name, description string, variables []*model.Variable, primaryKey string) *Dataset

NewDataset creates a new dataset instance.

func (*Dataset) AddInsert

func (ds *Dataset) AddInsert(statement string, args []interface{})

AddInsert adds an insert statement and parameters to the batch.

func (*Dataset) AddInsertFromSource

func (ds *Dataset) AddInsertFromSource(values []interface{})

AddInsertFromSource adds a row to insert using the copy protocol.

func (*Dataset) AddVariable

func (ds *Dataset) AddVariable(variable *model.Variable)

AddVariable adds a variable to the dataset.

func (*Dataset) GetBatch

func (ds *Dataset) GetBatch() *pgx.Batch

GetBatch returns the insert statement batch.

func (*Dataset) GetBatchSize

func (ds *Dataset) GetBatchSize() int

GetBatchSize gets the insert batch count.

func (*Dataset) GetColumns

func (ds *Dataset) GetColumns() []string

GetColumns builds captures the variable names in a string slice.

func (*Dataset) GetInsertSource

func (ds *Dataset) GetInsertSource() [][]interface{}

GetInsertSource returns the insert from source batch.

func (*Dataset) GetInsertSourceLength

func (ds *Dataset) GetInsertSourceLength() int

GetInsertSourceLength gets the insert from source size.

func (*Dataset) GetPrimaryKey

func (ds *Dataset) GetPrimaryKey() string

GetPrimaryKey returns the primary key of the dataset.

func (*Dataset) HasVariable

func (ds *Dataset) HasVariable(variable *model.Variable) bool

HasVariable checks to see if a variable is already contained in the dataset.

func (*Dataset) ResetBatch

func (ds *Dataset) ResetBatch()

ResetBatch clears the batch contents.

type IntegratedClient

type IntegratedClient struct {
	// contains filtered or unexported fields
}

IntegratedClient is a postgres client that can be used to query a postgres database.

func (IntegratedClient) Begin

func (ic IntegratedClient) Begin() (pgx.Tx, error)

Begin creates a new transaction.

func (IntegratedClient) CopyFrom

func (ic IntegratedClient) CopyFrom(storageName string, columns []string, rows [][]interface{}) (int64, error)

CopyFrom copies data using the Postgres copy protocol for bulk data insertion.

func (IntegratedClient) Exec

func (ic IntegratedClient) Exec(sql string, params ...interface{}) (pgconn.CommandTag, error)

Exec executes the sql command.

func (IntegratedClient) Query

func (ic IntegratedClient) Query(sql string, params ...interface{}) (pgx.Rows, error)

Query queries the database and returns the matching rows.

func (IntegratedClient) QueryRow

func (ic IntegratedClient) QueryRow(sql string, params ...interface{}) pgx.Row

QueryRow returns the first row from the query execution.

func (IntegratedClient) SendBatch

func (ic IntegratedClient) SendBatch(batch *pgx.Batch) pgx.BatchResults

SendBatch submits a batch.

type WordStem

type WordStem struct {
	Word string
	Stem string
}

WordStem contains the pairing of a word and its stemmed version.

Jump to

Keyboard shortcuts

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