Add custom DDL parser - #174
Conversation
7000a72 to
e9adfc3
Compare
e9adfc3 to
48a8fce
Compare
| // In lieu CREATE_TRIGGER, re-use similar CREATE_FUNCTION as operator kind. | ||
| private static final SqlOperator OPERATOR = | ||
| new SqlSpecialOperator("CREATE TRIGGER", | ||
| SqlKind.CREATE_FUNCTION); |
There was a problem hiding this comment.
Is this intentional, or do we need to introduce a dedicated SqlKind for CREATE_TRIGGER?
There was a problem hiding this comment.
It's an enum, so we can't introduce a new type without contributing it upstream to Calcite. Per their docs, we can use an UNKNOWN kind in the meantime, but triggers and functions look very similar so I figure we can use the same kind for both. Looking ahead, I'm planning to have triggers be zero-parameter functions under the hood, s.t. we can manually fire a trigger the same way you'd invoke a function. At that point, triggers would just be syntactic sugar for functions anyway.
| // In lieu DROP_TRIGGER, re-use similar DROP_FUNCTION as operator kind. | ||
| private static final SqlOperator OPERATOR = | ||
| new SqlSpecialOperator("DROP TRIGGER", | ||
| SqlKind.DROP_FUNCTION); |
There was a problem hiding this comment.
mismatched SqlKind here as well? Also would we need a DROP_FUNCTION DDL as well ?
There was a problem hiding this comment.
Yeah we'll need to implement DROP TRIGGER at some point.
Summary
serverDDL parser with new custom one.Details
The Calcite project has a bunch of machinery to generate parsers. It's not practical to replicate that machinery in this project. Instead, I've added a custom parser definition to Calcite, had it generate a parser impl, and then copy-pasted the resulting files here.
The new parser supports the following custom statements:
The new
refreshed <cron>,scheduled <cron>,with (options), andin <namespace>clauses are optional. Thewithclause is intended for passing in options that pop out when rendering templates. For examplewith (foo 'bar')should result in{{foo}}expanding asbar. This could be used to dynamically enable/disable conditional templates, override defaults, etc.The
refreshedclause is intended for creating cron jobs that fire any triggers created as part of the resulting pipeline. Without specifyingrefreshed, anyTableTriggersin the pipeline would only get fired by external event sources. Withrefreshed, we can drive thoseTableTriggerseven without an external event source.The
scheduledclause likewise creates a cron job that drives user-defined triggers.Testing Done
create triggerDDL is tested in #175: