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

Support TUMBLE function #20

Open
yuemingl opened this issue Jun 3, 2019 · 4 comments
Open

Support TUMBLE function #20

yuemingl opened this issue Jun 3, 2019 · 4 comments

Comments

@yuemingl
Copy link

yuemingl commented Jun 3, 2019

More and more SQL engines start supporting streaming functions, like

TUMBLE(rowtime, INTERVAL '1' HOUR)

described here https://calcite.apache.org/docs/stream.html#tumbling-windows-improved

Is it possible to support parameter list like "rowtime, INTERVAL '1' HOUR"?

Other functions like:
DATE_ADD(input_value, INTERVAL quantity_expr unit_of_time)
DATE_SUB(input_value, INTERVAL quantity_expr unit_of_time)

@albin3
Copy link
Member

albin3 commented Jun 4, 2019

To add key word "INTERVAL" and support "INTERVAL quantity_expr unit_of_time" grammar.

@yuemingl
Copy link
Author

yuemingl commented Jun 4, 2019

It works for me after changed file sqlParser.jison by adding:
SECOND return 'SECOND'
MINUTE return 'MINUTE'
HOUR return 'HOUR'
SECONDS return 'SECONDS'
MINUTES return 'MINUTES'
HOURS return 'HOURS'
INTERVAL return 'INTERVAL'

expr
: boolean_primary { $$ = $1 }
| boolean_primary IS not_opt boolean_extra { $$ = { type: 'IsExpression', hasNot: $3, left: $1, right: $4 } }
| NOT expr { $$ = { type: 'NotExpression', value: $2 } }
| expr '&&' expr { $$ = { type: 'AndExpression', operator: $2, left: $1, right: $3 } }
| expr '||' expr { $$ = { type: 'OrExpression', operator: $2, left: $1, right: $3 } }
| expr OR expr { $$ = { type: 'OrExpression', operator: $2, left: $1, right: $3 } }
| expr AND expr { $$ = { type: 'AndExpression', operator: $2, left: $1, right: $3 } }
| expr XOR expr { $$ = { type: 'XORExpression', left: $1, right: $3 } }
| INTERVAL expr SECOND { $$ = { type: 'IntervalExpression', value: $2, unit: $3 } }
| INTERVAL expr MINUTE { $$ = { type: 'IntervalExpression', value: $2, unit: $3 } }
| INTERVAL expr HOUR { $$ = { type: 'IntervalExpression', value: $2, unit: $3 } }
| INTERVAL expr SECONDS { $$ = { type: 'IntervalExpression', value: $2, unit: $3 } }
| INTERVAL expr MINUTES { $$ = { type: 'IntervalExpression', value: $2, unit: $3 } }
| INTERVAL expr HOURS { $$ = { type: 'IntervalExpression', value: $2, unit: $3 } }
;

and changed file stringify.js by adding:

Sql.prototype.travelIntervalExpression = function (ast) {
this.appendKeyword('interval');
this.travel(ast.value);
this.appendKeyword(ast.unit);
}

@albin3
Copy link
Member

albin3 commented Jun 4, 2019

Yes, but SECOND, MINUTE, HOUR.. should better be pack as a "unit_of_time".

@albin3
Copy link
Member

albin3 commented Jun 4, 2019

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

No branches or pull requests

2 participants