mongo

package
v0.15.5 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2018 License: MIT Imports: 19 Imported by: 3

README

Mongo Data Source

Provides SQL Access to Mongo via the DataUX Mysql Proxy Service.

mongo dataux

mysql -h 127.0.0.1 -P4000


-- Create a new schema = "dbx1" with one source being
-- a mongo database called "mgo_datauxtest"

CREATE source mgo_datauxtest WITH {
  "type":"mongo",
  "schema":"dbx1",
  "hosts": ["localhost:28017"]
};

-- Syntax:  CREATE source DB_NAME WITH json_properties
-- DB_NAME = existing database in mongo, in this example "mgo_datauxtest"

-- WITH Properties:
-- "schema":  Name of schema to attach this source to
-- "type":  Source type, most be datasource registered in registry (mongo, bigtable, etc)
-- "hosts": Array of hosts:port



use dbx1;

show tables;

describe article;

select * from article;



SQL -> Mongo

Mongo SQL Query
show collections show tables;
na, -- runtime inspection describe mytable;
db.accounts.find({},{created:{"$gte":"1/1/2016"}}).count(); select count(*) from accounts WHERE created > "1/1/2016";
db.article.find({"year":{"$in": [2013,2014,2015] }},{}} select * from article WHERE year IN (2015,2014,2013);
db.article.find({"created":{"$gte": new Date('Aug 01, 2011'), "$lte": new Date('Aug 03, 2013') },{title:1,count:1,author:1}} `SELECT title, count, author FROM article WHERE created BETWEEN todate("2011-08-01") AND todate("2013-08-03")
db.article.find({"title":{"Pattern":"^list","Options":"i"}},{title:1,count:1}) SELECT title, count AS ct FROM article WHERE title like \"list%\"
na, not avail in mongo (polyfill in dataux) SELECT avg(CHAR_LENGTH(CAST(title, \"AS\", \"CHAR\"))) AS title_avg FROM article;
need to document ... select min(year), max(year), avg(year), sum(year) from table WHERE exists(a);

Documentation

Index

Constants

View Source
const (
	// SourceType for this mongo source.
	SourceType = "mongo"
)

Variables

View Source
var (
	// DefaultLimit is default page size
	DefaultLimit = 20
)

Functions

func NewSource

func NewSource() schema.Source

NewSource mongo source.

Types

type ResultReader

type ResultReader struct {
	*exec.TaskBase

	Docs     []u.JsonHelper
	Vals     [][]driver.Value
	Total    int
	Aggs     u.JsonHelper
	ScrollId string
	// contains filtered or unexported fields
}

ResultReader Mongo implements result paging, reading - driver.Rows

func NewResultReader

func NewResultReader(req *SqlToMgo, q *mgo.Query, limit int) *ResultReader

func (*ResultReader) Close

func (m *ResultReader) Close() error

func (*ResultReader) Run

func (m *ResultReader) Run() error

type ResultReaderNext

type ResultReaderNext struct {
	*ResultReader
}

ResultReaderNext a wrapper, allowing us to implement sql/driver Next() interface which is different than qlbridge/datasource Next()

type Source

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

Source Mongo Data Source implements qlbridge DataSource interfaces to mongo server - singleton shared across all sessions/connections - creates connections by mgo.Session.Clone()

func (*Source) Close

func (m *Source) Close() error

func (*Source) Init

func (m *Source) Init()

Init initilize this source.

func (*Source) Open

func (m *Source) Open(collectionName string) (schema.Conn, error)

Open connection.

func (*Source) Setup

func (m *Source) Setup(ss *schema.Schema) error

Setup this source.

func (*Source) Table

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

Table get single table schema.

func (*Source) Tables

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

Tables list of tables

type SqlToMgo

type SqlToMgo struct {
	*exec.TaskBase
	// contains filtered or unexported fields
}

SqlToMgo Rewrite a Sql AST statement to a Mongo request

  • Walk the AST and see what can be pushed down and what can't
  • try to poly-fill the missing pieces
  • stateful single use request

func NewSqlToMgo

func NewSqlToMgo(table *schema.Table, sess *mgo.Session) *SqlToMgo

NewSqlToMgo create sql to mongo converter

func (*SqlToMgo) Columns

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

Columns return list of column names

func (*SqlToMgo) WalkExecSource

func (m *SqlToMgo) WalkExecSource(p *plan.Source) (exec.Task, error)

func (*SqlToMgo) WalkSourceSelect

func (m *SqlToMgo) WalkSourceSelect(planner plan.Planner, p *plan.Source) (plan.Task, error)

WalkSourceSelect An interface implemented by this connection allowing the planner to push down as much logic into mongo as possible

Jump to

Keyboard shortcuts

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