js-sql-parser icon indicating copy to clipboard operation
js-sql-parser copied to clipboard

Support TUMBLE function

Open yuemingl opened this issue 6 years ago • 4 comments

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)

yuemingl avatar Jun 03 '19 23:06 yuemingl

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

albin3 avatar Jun 04 '19 03:06 albin3

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); }

yuemingl avatar Jun 04 '19 04:06 yuemingl

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

albin3 avatar Jun 04 '19 06:06 albin3

Will support follows https://dev.mysql.com/doc/refman/5.7/en/expressions.html#temporal-intervals

albin3 avatar Jun 04 '19 06:06 albin3