Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] support a paste operator in join.as() syntax #435

Closed
jonseymour opened this issue Apr 8, 2016 · 4 comments
Closed

[feature request] support a paste operator in join.as() syntax #435

jonseymour opened this issue Apr 8, 2016 · 4 comments

Comments

@jonseymour
Copy link
Contributor

As it currently stands, the field names in output stream if a Kapacitor join node are assigned prefixes of the form . where is the alias assigned to the Nth input stream by the as() property method of the join node.

So, for example:

var metric1 = stream
        |from()
                .database('sampledb')
                .retentionPolicy('default')
                .measurement('sample')
                .groupBy('node')
        |window()
                .align()
                .period(5m)
                .every(5m)
        |shift(-5m)
        |mean('metric1').as('metric1')


var metric2 = stream
        |from()
                .database('sampledb')
                .retentionPolicy('default')
                .measurement('sample')
                .groupBy('node')
        |window()
                .align()
                .period(5m)
                .every(5m)
        |shift(-5m)
        |mean('metric2').as('metric2')

metric1
        |join(metric2)
           .as('m1', 'm2')
        |log()

will result in a stream with fields called 'm1.metric1' and 'm2.metric2'

It would be nice if the mandatory period in the resulting name could be avoided.

The suggestion to avoid this is to support use of a trailing paste operator in the arguments to as()

So:

metric1
        |join(metric2)
           .as('s_#', 't_#')

would result in a stream with fields called s_metric1 and t_metric2 and

and:

metric1
        |join(metric2)
           .as('#', '#')

would result in a stream with fields called: metric1 and metric2.

'#' is chosen to mimic similar behaviour in the C pre-processor.

Note: A specification of as('foo##', 'foo##') would result in names called 'foo#metric1', 'foo#metric2'.

A specification of as('foo#bar', 'foo#bar') would result in names called foo#bar.metric1 and foo#bar.metric2.

@jonseymour jonseymour changed the title [feature request] support a pasting operator in join.as() syntax [feature request] support a paste operator in join.as() syntax Apr 8, 2016
@nathanielc
Copy link
Contributor

@jonseymour I like the suggestion but the names of the joining nodes are not always available. If they were I would make 'as' optional.

Example:

var metric1 = stream
        |from()
                .database('sampledb')
                .retentionPolicy('default')
                .measurement('sample')
                .groupBy('node')
        |window()
                .align()
                .period(5m)
                .every(5m)
        |shift(-5m)
        |mean('metric1').as('metric1')

var metric2 = stream
        |from()
                .database('sampledb')
                .retentionPolicy('default')
                .measurement('sample')
                .groupBy('node')
        |window()
                .align()
                .period(5m)
                .every(5m)
        |shift(-5m)
        |mean('metric2').as('metric2')
        |join(metric1)
           .as('m2', 'm1')
        |log()

While convention says that the above script is not readable and so its not used as much its still valid.

Maybe we can make try and populate the as prefixes with the var names be default. If they are not available then as would be required.

Also the . isn't all that important it just made sense to use something to delimit the prefix from the original name.

@jonseymour
Copy link
Contributor Author

The paste operator would be optional of course - if you didn't specify it then current behaviour would apply.

The paste operator would, of course, provide an easy way for the user choose their own delimiter, as in the example above where I used s_# and t_#.

I also like your idea of making as() optional where possible.

@cnelissen
Copy link

+1 for making as() optional. IMO it should only be required if two nodes have fields with the same name, much like when you attempt a join in MySQL on two tables that share columns you get an error like: "column 'id' is ambiguous".

@jonseymour
Copy link
Contributor Author

Closed via #698

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants