[
https://issues.apache.org/jira/browse/CALCITE-4728?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17398104#comment-17398104
]
James Starr commented on CALCITE-4728:
--------------------------------------
Where the parser is bound in, should be pluggable so other languages could
eventually be supported. Also, you can not start parsing the block until you
have parsed the whole block because the dialect is specified after the block.
So structuring it so calcite store a procedural block, then attempts parse it
during validation with a custom parser that takes a reference to the sql parser
and maybe the existing validator may be the way to go.
Example of postgres using python:
{code:sql}
CREATE FUNCTION pymax (a integer, b integer)
RETURNS integer
AS $$
if a > b:
return a
return b
$$ LANGUAGE plpythonu;
{code}
> Parse and validate procedural code (such as SQL/PSM, PL/SQL, PL/pgSQL, T-SQL)
> -----------------------------------------------------------------------------
>
> Key: CALCITE-4728
> URL: https://issues.apache.org/jira/browse/CALCITE-4728
> Project: Calcite
> Issue Type: Bug
> Reporter: Julian Hyde
> Priority: Major
>
> Parse and validate procedural code (such as the SQL standard's SQL/PSM,
> Oracle's PL/SQL, PostgreSQL's PL/pgSQL, MSSQL's T-SQL).
> This would entail:
> * Extensions to the SQL parser. (I'm not sure whether this would be the core
> parser or an extended parser such as Babel.)
> * AST classes (sub-classes of {{SqlNode}}) for functions, procedures,
> blocks, variable and parameter declarations, variable assignment,
> if-then-else, loop, and so forth.
> * Extensions to the validator to validate blocks.
> * Extensions to the validator to validate a SQL statement that is inside a
> block. (Variables and parameters are in scope.)
> Optional:
> * Extend Interpreter to execute functions, procedures, blocks.
> * Some means to convert a block into executable Java code.
> * Extend {{SqlDialect}} so that ASTs of functions, procedures and blocks can
> be emitted using the syntax of particular dialects.
> The languages are sufficiently similar that we can use the same AST classes
> for all.
> I don't think we need to extend {{RelNode}} to represent blocks. (It's not a
> good fit, since a block does not evaluate to a relation.) Possibly we would
> create some data structure to represent a validated block (e.g. the type of
> each variable; each use of a variable points to the variable's definition).
> {{SqlToRelConverter}} would create this data structure in order "freeze" the
> state of the validator.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)