datasource

package
v0.0.0-...-261b5b0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2016 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Copyright 2011 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Datasource are individual database/source types, a few of which are implemented here (test, csv) and base services (datasource registry).

Index

Constants

View Source
const (
	// Default Max Allowed packets for connections
	MaxAllowedPacket = 4194304
)
View Source
const (
	SchemaDbSourceType = "schemadb"
)

Variables

View Source
var (
	DialectWriterCols = []string{"mysql"}
	DialectWriters    = []schema.DialectWriter{&mysqlWriter{}}
)
View Source
var (

	// If disableRecover=true, we will not capture/suppress panics
	// Test only feature hopefully
	DisableRecover bool
)
View Source
var (
	IntrospectCount = 20
)

Functions

func IntrospectSchema

func IntrospectSchema(s *schema.Schema, name string, iter schema.Iterator) error

func IntrospectTable

func IntrospectTable(tbl *schema.Table, iter schema.Iterator) error

func KeyFromWhere

func KeyFromWhere(wh interface{}) schema.Key

Given a Where expression, lets try to create a key which

requires form    `idenity = "value"`

func MessageConversion

func MessageConversion(vals []interface{}) []schema.Message

func MysqlValueString

func MysqlValueString(t value.ValueType) string

func NewMySqlSessionVars

func NewMySqlSessionVars() expr.ContextReadWriter

func NewNamespacedContextReader

func NewNamespacedContextReader(basereader expr.ContextReader, namespace string) expr.ContextReader

NewNestedContextReader provides a context reader which prefixes all keys with a name space. This is useful if you have overlapping field names between ContextReaders within a NestedContextReader.

func NewNestedContextReadWriter

func NewNestedContextReadWriter(readers []expr.ContextReader, writer expr.ContextWriter, ts time.Time) expr.ContextReadWriter

NewNestedContextReader provides a context reader which is a composite of ordered child readers the first reader with a key will be used

func NewNestedContextReader

func NewNestedContextReader(readers []expr.ContextReader, ts time.Time) expr.ContextReader

NewNestedContextReader provides a context reader which is a composite of ordered child readers the first reader with a key will be used

func OpenConn

func OpenConn(sourceName, sourceConfig string) (schema.Conn, error)

Open a datasource, Globalopen connection function using

default schema registry

func Register

func Register(sourceName string, source schema.Source)

Register makes a datasource available by the provided @sourceName If Register is called twice with the same name or if source is nil, it panics.

Sources are specific schemas of type csv, elasticsearch, etc containing
  multiple tables

func RowsForSession

func RowsForSession(ctx *plan.Context) [][]driver.Value

func SourceIterChannel

func SourceIterChannel(iter schema.Iterator, sigCh <-chan bool) <-chan schema.Message

Open a go routine to run this source iteration until signal/complete

Types

type ContextSimple

type ContextSimple struct {
	Data map[string]value.Value
	// contains filtered or unexported fields
}

func NewContextSimple

func NewContextSimple() *ContextSimple

func NewContextSimpleData

func NewContextSimpleData(data map[string]value.Value) *ContextSimple

func NewContextSimpleNative

func NewContextSimpleNative(data map[string]interface{}) *ContextSimple

func NewContextSimpleTs

func NewContextSimpleTs(data map[string]value.Value, ts time.Time) *ContextSimple

func NewMySqlGlobalVars

func NewMySqlGlobalVars() *ContextSimple

func (*ContextSimple) All

func (m *ContextSimple) All() map[string]value.Value

func (*ContextSimple) Body

func (m *ContextSimple) Body() interface{}

func (*ContextSimple) Commit

func (m *ContextSimple) Commit(rowInfo []expr.SchemaInfo, row expr.RowWriter) error

func (*ContextSimple) Delete

func (m *ContextSimple) Delete(row map[string]value.Value) error

func (ContextSimple) Get

func (m ContextSimple) Get(key string) (value.Value, bool)

func (*ContextSimple) Id

func (m *ContextSimple) Id() uint64

func (*ContextSimple) Put

func (*ContextSimple) Row

func (m *ContextSimple) Row() map[string]value.Value

func (*ContextSimple) Ts

func (m *ContextSimple) Ts() time.Time

type ContextUrlValues

type ContextUrlValues struct {
	Data url.Values
	// contains filtered or unexported fields
}

func NewContextUrlValues

func NewContextUrlValues(uv url.Values) *ContextUrlValues

func NewContextUrlValuesTs

func NewContextUrlValuesTs(uv url.Values, ts time.Time) *ContextUrlValues

func (*ContextUrlValues) Body

func (m *ContextUrlValues) Body() interface{}

func (*ContextUrlValues) Delete

func (m *ContextUrlValues) Delete(delRow map[string]value.Value) error

func (ContextUrlValues) Get

func (m ContextUrlValues) Get(key string) (value.Value, bool)

func (*ContextUrlValues) Id

func (m *ContextUrlValues) Id() uint64

func (ContextUrlValues) Put

func (ContextUrlValues) Row

func (m ContextUrlValues) Row() map[string]value.Value

func (*ContextUrlValues) String

func (m *ContextUrlValues) String() string

func (ContextUrlValues) Ts

func (m ContextUrlValues) Ts() time.Time

type ContextWrapper

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

func NewContextWrapper

func NewContextWrapper(val interface{}) *ContextWrapper

func (*ContextWrapper) Get

func (m *ContextWrapper) Get(key string) (value.Value, bool)

func (*ContextWrapper) Row

func (m *ContextWrapper) Row() map[string]value.Value

func (*ContextWrapper) Ts

func (m *ContextWrapper) Ts() time.Time

type ContextWriterEmpty

type ContextWriterEmpty struct{}

func (*ContextWriterEmpty) Delete

func (m *ContextWriterEmpty) Delete(delRow map[string]value.Value) error

func (*ContextWriterEmpty) Put

type CsvDataSource

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

Csv DataSource, implements qlbridge schema DataSource, SourceConn, Scanner

to allow csv files to be full featured databases.
- very, very naive scanner, forward only single pass
- can open a file with .Open()
- assumes comma delimited
- not thread-safe
- does not implement write operations

func NewCsvSource

func NewCsvSource(table string, indexCol int, ior io.Reader, exit <-chan bool) (*CsvDataSource, error)

Csv reader assumes we are getting first row as headers

func (*CsvDataSource) Close

func (m *CsvDataSource) Close() error

func (*CsvDataSource) Columns

func (m *CsvDataSource) Columns() []string

func (*CsvDataSource) CreateIterator

func (m *CsvDataSource) CreateIterator() schema.Iterator

func (*CsvDataSource) MesgChan

func (m *CsvDataSource) MesgChan() <-chan schema.Message

func (*CsvDataSource) Next

func (m *CsvDataSource) Next() schema.Message

func (*CsvDataSource) Open

func (m *CsvDataSource) Open(connInfo string) (schema.Conn, error)

func (*CsvDataSource) Table

func (m *CsvDataSource) Table(tableName string) (*schema.Table, error)

func (*CsvDataSource) Tables

func (m *CsvDataSource) Tables() []string

type JsonHelperScannable

type JsonHelperScannable u.JsonHelper

json Helper expects map[string]interface

func (*JsonHelperScannable) MarshalJSON

func (m *JsonHelperScannable) MarshalJSON() ([]byte, error)

func (*JsonHelperScannable) Scan

func (m *JsonHelperScannable) Scan(src interface{}) error

func (*JsonHelperScannable) UnmarshalJSON

func (m *JsonHelperScannable) UnmarshalJSON(data []byte) error

Unmarshall bytes into this typed struct

func (JsonHelperScannable) Value

func (m JsonHelperScannable) Value() (driver.Value, error)

This is the go sql/driver interface we need to implement to allow conversion back forth

type JsonWrapper

type JsonWrapper json.RawMessage

json data

func (*JsonWrapper) MarshalJSON

func (m *JsonWrapper) MarshalJSON() ([]byte, error)

func (*JsonWrapper) Scan

func (m *JsonWrapper) Scan(src interface{}) error

func (*JsonWrapper) Unmarshal

func (m *JsonWrapper) Unmarshal(v interface{}) error

func (*JsonWrapper) UnmarshalJSON

func (m *JsonWrapper) UnmarshalJSON(data []byte) error

Unmarshall bytes into this typed struct

func (JsonWrapper) Value

func (m JsonWrapper) Value() (driver.Value, error)

This is the go sql/driver interface we need to implement to allow conversion back forth

type KeyCol

type KeyCol struct {
	Name string
	Val  driver.Value
}

Variety of Key Types

func NewKeyCol

func NewKeyCol(name string, val driver.Value) KeyCol

func (KeyCol) Key

func (m KeyCol) Key() driver.Value

type KeyInt

type KeyInt struct {
	Id int
}

Variety of Key Types

func NewKeyInt

func NewKeyInt(key int) KeyInt

func (*KeyInt) Key

func (m *KeyInt) Key() driver.Value

type KeyInt64

type KeyInt64 struct {
	Id int64
}

Variety of Key Types

func NewKeyInt64

func NewKeyInt64(key int64) KeyInt64

func (*KeyInt64) Key

func (m *KeyInt64) Key() driver.Value

type MessageArray

type MessageArray struct {
	Idv   uint64
	Items []*SqlDriverMessageMap
}

func (*MessageArray) Body

func (m *MessageArray) Body() interface{}

func (*MessageArray) Id

func (m *MessageArray) Id() uint64

type NamespacedContextReader

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

func (*NamespacedContextReader) Get

func (*NamespacedContextReader) Row

func (*NamespacedContextReader) Ts

type NestedContextReader

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

func (*NestedContextReader) Delete

func (n *NestedContextReader) Delete(delRow map[string]value.Value) error

func (*NestedContextReader) Get

func (n *NestedContextReader) Get(key string) (value.Value, bool)

func (*NestedContextReader) Put

func (*NestedContextReader) Row

func (n *NestedContextReader) Row() map[string]value.Value

func (*NestedContextReader) Ts

func (n *NestedContextReader) Ts() time.Time

type Registry

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

Our internal map of different types of datasources that are registered for our runtime system to use

func DataSourcesRegistry

func DataSourcesRegistry() *Registry

get registry of all datasource types

func (*Registry) Conn

func (m *Registry) Conn(db string) schema.Conn

Get connection for given Database

@db      database name

func (*Registry) DataSource

func (m *Registry) DataSource(connInfo string) schema.Source

given connection info, get datasource

@connInfo =    csv:///dev/stdin
               mockcsv

func (*Registry) Get

func (m *Registry) Get(sourceName string) schema.Source

Get a Data Source, similar to Source(@connInfo)

func (*Registry) Schema

func (m *Registry) Schema(schemaName string) (*schema.Schema, bool)

Get schema for given source

@schemaName =  virtual database name made up of multiple backend-sources

func (*Registry) SchemaAdd

func (m *Registry) SchemaAdd(s *schema.Schema)

Add a new Schema

func (*Registry) SourceSchemaAdd

func (m *Registry) SourceSchemaAdd(ss *schema.SchemaSource) error

Add a new SourceSchema to a schema which will be created if it doesn't exist

func (*Registry) String

func (m *Registry) String() string

func (*Registry) Tables

func (m *Registry) Tables() []string

Get all tables from this registry

type SchemaDb

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

Static Schema Source, implements qlbridge DataSource to allow in memory native go data

to have a Schema and implement and be operated on by Sql Operations

func NewSchemaDb

func NewSchemaDb(s *schema.Schema) *SchemaDb

func (*SchemaDb) Close

func (m *SchemaDb) Close() error

func (*SchemaDb) Open

func (m *SchemaDb) Open(schemaObjectName string) (schema.Conn, error)

Create a SchemaSource specific to schema object (table, database)

func (*SchemaDb) Table

func (m *SchemaDb) Table(table string) (*schema.Table, error)

func (*SchemaDb) Tables

func (m *SchemaDb) Tables() []string

type SchemaSource

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

func (*SchemaSource) Close

func (m *SchemaSource) Close() error

func (*SchemaSource) Columns

func (m *SchemaSource) Columns() []string

func (*SchemaSource) Get

func (m *SchemaSource) Get(key driver.Value) (schema.Message, error)

func (*SchemaSource) Next

func (m *SchemaSource) Next() schema.Message

func (*SchemaSource) SetContext

func (m *SchemaSource) SetContext(ctx *plan.Context)

func (*SchemaSource) SetRows

func (m *SchemaSource) SetRows(rows [][]driver.Value)

type SqlDriverMessage

type SqlDriverMessage struct {
	Vals  []driver.Value
	IdVal uint64
}

func (*SqlDriverMessage) Body

func (m *SqlDriverMessage) Body() interface{}

func (*SqlDriverMessage) Id

func (m *SqlDriverMessage) Id() uint64

func (*SqlDriverMessage) ToMsgMap

func (m *SqlDriverMessage) ToMsgMap(colidx map[string]int) *SqlDriverMessageMap

type SqlDriverMessageMap

type SqlDriverMessageMap struct {
	Vals     []driver.Value // Values
	ColIndex map[string]int // Map of column names to ordinal position in row
	IdVal    uint64         // id()
	// contains filtered or unexported fields
}

func NewSqlDriverMessageMap

func NewSqlDriverMessageMap(id uint64, row []driver.Value, colindex map[string]int) *SqlDriverMessageMap

func NewSqlDriverMessageMapCtx

func NewSqlDriverMessageMapCtx(id uint64, ctx expr.ContextReader, colindex map[string]int) *SqlDriverMessageMap

func NewSqlDriverMessageMapEmpty

func NewSqlDriverMessageMapEmpty() *SqlDriverMessageMap

func NewSqlDriverMessageMapVals

func NewSqlDriverMessageMapVals(id uint64, row []driver.Value, cols []string) *SqlDriverMessageMap

func (*SqlDriverMessageMap) Body

func (m *SqlDriverMessageMap) Body() interface{}

func (*SqlDriverMessageMap) Copy

func (*SqlDriverMessageMap) Get

func (m *SqlDriverMessageMap) Get(key string) (value.Value, bool)

func (*SqlDriverMessageMap) Id

func (m *SqlDriverMessageMap) Id() uint64

func (*SqlDriverMessageMap) Key

func (m *SqlDriverMessageMap) Key() string

func (*SqlDriverMessageMap) Row

func (m *SqlDriverMessageMap) Row() map[string]value.Value

func (*SqlDriverMessageMap) SetKey

func (m *SqlDriverMessageMap) SetKey(key string)

func (*SqlDriverMessageMap) SetKeyHashed

func (m *SqlDriverMessageMap) SetKeyHashed(key string)

func (*SqlDriverMessageMap) SetRow

func (m *SqlDriverMessageMap) SetRow(row []driver.Value)

func (*SqlDriverMessageMap) Ts

func (m *SqlDriverMessageMap) Ts() time.Time

func (*SqlDriverMessageMap) Values

func (m *SqlDriverMessageMap) Values() []driver.Value

type StaticSource

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

A static, non-thread safe, single-table data source

func NewStaticSource

func NewStaticSource(name string, cols []string, msgs []schema.Message) *StaticSource

func (*StaticSource) Close

func (m *StaticSource) Close() error

func (*StaticSource) Columns

func (m *StaticSource) Columns() []string

func (*StaticSource) CreateIterator

func (m *StaticSource) CreateIterator() schema.Iterator

func (*StaticSource) MesgChan

func (m *StaticSource) MesgChan() <-chan schema.Message

func (*StaticSource) Next

func (m *StaticSource) Next() schema.Message

func (*StaticSource) Open

func (m *StaticSource) Open(_ string) (schema.Conn, error)

func (*StaticSource) Tables

func (m *StaticSource) Tables() []string

type StringArray

type StringArray []string

Convert json to array of strings

func (*StringArray) MarshalJSON

func (m *StringArray) MarshalJSON() ([]byte, error)

func (*StringArray) Scan

func (m *StringArray) Scan(src interface{}) error

func (*StringArray) UnmarshalJSON

func (m *StringArray) UnmarshalJSON(data []byte) error

func (StringArray) Value

func (m StringArray) Value() (driver.Value, error)

type TimeValue

type TimeValue time.Time

Convert string/bytes to time.Time

auto-parses a variety of different date formats
that are supported in http://godoc.org/github.com/araddon/dateparse

func (*TimeValue) MarshalJSON

func (m *TimeValue) MarshalJSON() ([]byte, error)

func (*TimeValue) Scan

func (m *TimeValue) Scan(src interface{}) error

func (TimeValue) Time

func (m TimeValue) Time() time.Time

func (*TimeValue) Unmarshal

func (m *TimeValue) Unmarshal(v interface{}) error

func (*TimeValue) UnmarshalJSON

func (m *TimeValue) UnmarshalJSON(data []byte) error

func (TimeValue) Value

func (m TimeValue) Value() (driver.Value, error)

type UrlValuesMsg

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

func NewUrlValuesMsg

func NewUrlValuesMsg(id uint64, body *ContextUrlValues) *UrlValuesMsg

func (*UrlValuesMsg) Body

func (m *UrlValuesMsg) Body() interface{}

func (*UrlValuesMsg) Id

func (m *UrlValuesMsg) Id() uint64

func (*UrlValuesMsg) String

func (m *UrlValuesMsg) String() string

type ValueContextWrapper

type ValueContextWrapper struct {
	*SqlDriverMessage
	// contains filtered or unexported fields
}

func NewValueContextWrapper

func NewValueContextWrapper(msg *SqlDriverMessage, cols map[string]*rel.Column) *ValueContextWrapper

func (*ValueContextWrapper) Get

func (m *ValueContextWrapper) Get(key string) (value.Value, bool)

func (*ValueContextWrapper) Row

func (m *ValueContextWrapper) Row() map[string]value.Value

func (*ValueContextWrapper) Ts

func (m *ValueContextWrapper) Ts() time.Time

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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