-
Notifications
You must be signed in to change notification settings - Fork 215
29 noid #37
Changes from 3 commits
342e777
348f5bb
2682b08
73ae917
16049e9
5586616
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,13 +81,19 @@ func (i *Influxdb) Stop() error { | |
func (i *Influxdb) applyOp(msg *message.Msg) (*message.Msg, error) { | ||
switch msg.Op { | ||
case message.Insert: | ||
docSize := len(msg.Document()) | ||
columns := make([]string, 0, docSize) | ||
if !msg.IsMap() { | ||
i.pipe.Err <- NewError(ERROR, i.path, "Rethinkdb error (document must be a json document)", msg.Data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad error message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch |
||
return msg, nil | ||
} | ||
doc := msg.Map() | ||
|
||
sz := len(doc) | ||
columns := make([]string, 0, sz) | ||
points := make([][]interface{}, 1) | ||
points[0] = make([]interface{}, 0, docSize) | ||
for k := range msg.Document() { | ||
points[0] = make([]interface{}, 0, sz) | ||
for k, v := range doc { | ||
columns = append(columns, k) | ||
points[0] = append(points[0], msg.Document()[k]) | ||
points[0] = append(points[0], v) | ||
} | ||
series := &client.Series{ | ||
Name: i.seriesName, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,13 +90,19 @@ func (r *Rethinkdb) applyOp(msg *message.Msg) (*message.Msg, error) { | |
err error | ||
) | ||
|
||
if !msg.IsMap() { | ||
r.pipe.Err <- NewError(ERROR, r.path, "Rethinkdb error (document must be a json document)", msg.Data) | ||
return msg, nil | ||
} | ||
doc := msg.Map() | ||
|
||
switch msg.Op { | ||
case message.Delete: | ||
resp, err = gorethink.Table(r.table).Get(msg.IDString()).Delete().RunWrite(r.client) | ||
resp, err = gorethink.Table(r.table).Get(msg.IDString("id")).Delete().RunWrite(r.client) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is where people could get tripped up without a transformer to move the _id -> id in the doc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, we need to document the semantics of the adaptors wrt the ids.. |
||
case message.Insert: | ||
resp, err = gorethink.Table(r.table).Insert(msg.Document()).RunWrite(r.client) | ||
resp, err = gorethink.Table(r.table).Insert(doc).RunWrite(r.client) | ||
case message.Update: | ||
resp, err = gorethink.Table(r.table).Insert(msg.DocumentWithID("id"), gorethink.InsertOpts{Conflict: "replace"}).RunWrite(r.client) | ||
resp, err = gorethink.Table(r.table).Insert(doc, gorethink.InsertOpts{Conflict: "replace"}).RunWrite(r.client) | ||
} | ||
if err != nil { | ||
return msg, err | ||
|
@@ -107,6 +113,9 @@ func (r *Rethinkdb) applyOp(msg *message.Msg) (*message.Msg, error) { | |
|
||
func (r *Rethinkdb) setupClient() (*gorethink.Session, error) { | ||
// set up the clientConfig, we need host:port, username, password, and database name | ||
if r.debug { | ||
fmt.Printf("Connecting to %s\n", r.uri.Host) | ||
} | ||
client, err := gorethink.Connect(gorethink.ConnectOpts{ | ||
Address: r.uri.Host, | ||
MaxIdle: 10, | ||
|
@@ -116,6 +125,9 @@ func (r *Rethinkdb) setupClient() (*gorethink.Session, error) { | |
return nil, fmt.Errorf("Unable to connect: %s", err) | ||
} | ||
|
||
if r.debug { | ||
fmt.Printf("dropping and creating table '%s' on database '%s'\n", r.table, r.database) | ||
} | ||
gorethink.Db(r.database).TableDrop(r.table).RunWrite(client) | ||
gorethink.Db(r.database).TableCreate(r.table).RunWrite(client) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,10 +104,13 @@ func (t *Transformer) transformOne(msg *message.Msg) (*message.Msg, error) { | |
} | ||
|
||
now := time.Now().Nanosecond() | ||
|
||
if doc, err = mejson.Marshal(msg.Document()); err != nil { | ||
t.pipe.Err <- t.transformerError(ERROR, err, msg) | ||
return msg, nil | ||
if msg.IsMap() { | ||
if doc, err = mejson.Marshal(msg.Data); err != nil { | ||
t.pipe.Err <- t.transformerError(ERROR, err, msg) | ||
return msg, nil | ||
} | ||
} else { | ||
doc = msg.Data | ||
} | ||
|
||
if value, err = t.vm.ToValue(doc); err != nil { | ||
|
@@ -137,11 +140,9 @@ func (t *Transformer) transformOne(msg *message.Msg) (*message.Msg, error) { | |
t.pipe.Err <- t.transformerError(ERROR, err, msg) | ||
return msg, nil | ||
} | ||
msg.SetDocument(doc) | ||
msg.Data = doc | ||
default: | ||
if t.debug { | ||
fmt.Println("transformer skipping doc") | ||
} | ||
msg.Data = r | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you're meaning to set msg.Data to the result type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, got tripped up by the switch semantics |
||
} | ||
|
||
if t.debug { | ||
|
@@ -154,9 +155,9 @@ func (t *Transformer) transformOne(msg *message.Msg) (*message.Msg, error) { | |
|
||
func (t *Transformer) transformerError(lvl ErrorLevel, err error, msg *message.Msg) error { | ||
if e, ok := err.(*otto.Error); ok { | ||
return NewError(lvl, t.path, fmt.Sprintf("Transformer error (%s)", e.String()), msg.Document()) | ||
return NewError(lvl, t.path, fmt.Sprintf("Transformer error (%s)", e.String()), msg.Data) | ||
} | ||
return NewError(lvl, t.path, fmt.Sprintf("Transformer error (%s)", err.Error()), msg.Document()) | ||
return NewError(lvl, t.path, fmt.Sprintf("Transformer error (%s)", err.Error()), msg.Data) | ||
} | ||
|
||
// TransformerConfig holds config options for a transformer adaptor | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, I don't know if it's better to use a transformer to remove the source id/_id to allow the sink to use its own way of auto-generating the id/_id or do something with the adaptor's config to tell it to ignore any ids provided, not really something that has to be solved now though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a good default is to just let the adaptor default to good behaviour, and use the data that's it's given. if the adaptor can't get an id, then it will auto create one. it's up to the transformer to hand that.
rethink is the interesting one here, in that
mongo->elasticsearch both use an _id, whereas with mongo->rethink, rethink uses an 'id', while mongo uses an _id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 it's probably something that can be easily "solved" with good docs and examples