This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
PSR for LET, LETTING #21
Draft
dlurton
wants to merge
6
commits into
psr-proposal
Choose a base branch
from
psr-proposal-with-let
base: psr-proposal
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
\newcommand{\TRUE}{\gl{TRUE}\xspace} | ||
\newcommand{\FALSE}{\gl{FALSE}\xspace} | ||
\newcommand{\NULL}{\gl{NULL}\xspace} | ||
\newcommand{\MISSING}{\gl{MISSING}\xspace} | ||
|
||
|
||
\newcommand{\ionquote}[1]{\gl{\bt} #1 \gl{\bt}} | ||
|
||
|
||
% MODEL definitions | ||
\newcommand{\bt}{\texttt{\`}} | ||
\newcommand{\ob}{<\!\!<} | ||
\newcommand{\cb}{>\!\!>} | ||
\newcommand{\out}{\{-} | ||
\newcommand{\cut}{-\}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SPECPDF=main.pdf | ||
|
||
.PHONY: all clean $(SPECPDF) | ||
|
||
all: $(SPECPDF) | ||
|
||
$(SPECPDF): *.tex | ||
latexmk -pdf -pdflatex="pdflatex -interaction=nonstopmode" -use-make main.tex | ||
|
||
clean: | ||
latexmk -C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
\documentclass{article} | ||
\input{../common/preamble} | ||
\input{../common/macros} | ||
|
||
\begin{document} | ||
\input{with-let-letting.tex} | ||
\end{document} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
|
||
This PSR adds defintions for \gn{let\_clause} and \gn{letting\_clause} to figure 3 of the PartiQL specification | ||
dlurton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
and include them as optional clauses for \gl{SELECT} queries. | ||
|
||
\newcounter{rownum_ctr} | ||
\newcommand\row{\stepcounter{rownum_ctr}\arabic{rownum_ctr}} | ||
|
||
\begin{figure}[ht!] | ||
\centering | ||
\scriptsize | ||
\begin{tabular}{|@{~}rc@{~}l@{~}|} | ||
\hline | ||
\row & \multicolumn{2}{@{}l@{~}|}{\gn{query}} \\ | ||
\row & \gp & \gn{sfw\_query} \\ | ||
\row & \gd & \gn{expr\_query} \\ | ||
|
||
\hline | ||
|
||
\row & \multicolumn{2}{@{}l@{~}|}{\gn{sfw\_query}} \\ | ||
\row & \gp & (\gt{WITH} \gn{query} \gt{AS} \gn{variable})? \\ | ||
\row & & \gn{select\_clause} \\ %FIXME (see Figure~\ref{figure:select:bnf}) \\ | ||
\row & & \gn{from\_clause} \\ %FIXME (see Figure~\ref{figure:from:bnf}) \\ | ||
\row & & \textbf{(\gn{let\_clause)}? $\leftarrow $ NEW} \\ | ||
\row & & (\gt{WHERE} \gn{expr\_query})? \\ | ||
\row & & (\gt{GROUP BY} \gn{expr\_query} (\gt{AS} \gn{variable})? \\ | ||
\row & & ~~~~(\gt{,} \gn{expr\_query} (\gt{AS} \gn{variable})?)*)? \\ | ||
\row & & ~~~~\gt{GROUP AS} \gn{variable} \\ | ||
\row & & \textbf{(\gt{LETTING} \gn{expr\_query})? $\leftarrow$ NEW} \\ | ||
\row & & (\gt{HAVING} \gn{expr\_query})? \\ | ||
\row & & ((\gt{OUTER})? (\gt{UNION}\gd\gt{INTERSECT}\gd\gt{EXCEPT}) \gt{ALL}? \gn{sfw\_query})? \\ | ||
\row & & ((\gt{ORDER BY} (\gn{expr\_query} (\gt{ASC}\gd\gt{DESC})? \gs{order\_spec}? \\ | ||
\row & & ~~~~~~~~(\gt{,} \gn{expr\_query} (\gt{ASC}\gd\gt{DESC})? \gs{order\_spec}?)*)? ) \\ | ||
\row & & ~~~~| \gt{PRESERVE})? \\ | ||
\row & & (\gt{LIMIT} \gn{expr\_query})? \\ | ||
\row & & (\gt{OFFSET} \gn{expr\_query})? \\ | ||
|
||
\hline | ||
|
||
\row & \multicolumn{2}{@{}l@{~}|}{\gn{expr\_query}} \\ | ||
\row & \gp & \gt{(} \gn{sfw\_query} \gt{)} \\ | ||
\row & \gd & \gn{path\_expr} \\ | ||
\row & \gd & \gn{function\_name} \gl{(} (\gn{expr\_query} (\gt{,} \gn{expr\_query})*)? \gl{)} \\ | ||
\row & \gd & \gt{\{} (\gs{expr\_query}\gt{:}\gn{expr\_query} (\gt{,} \gs{expr\_query}\gt{:}\gn{expr\_query})*)? \gt{\}} \\ | ||
\row & \gd & \gt{[} (\gn{expr\_query} (\gt{,} \gn{expr\_query})*)? \gt{]} \\ | ||
\row & \gd & \gl{\ob} (\gn{expr\_query} (\gt{,} \gn{expr\_query})*)? \gl{\cb} \\ | ||
\row & \gd & \gs{sql\_scalar\_expr} \\ | ||
\row & \gd & \gs{value\_constant} \\ | ||
|
||
\hline | ||
|
||
\row & \multicolumn{2}{@{}l@{~}|}{\gn{path\_expr}} \\ | ||
\row & \gp & \gs{variable} \\ | ||
% \row & \gd & \gt{(} \gn{sfw\_query} \gt{)} \\ | ||
\row & \gd & \gt{(} \gn{expr\_query} \gt{)} \\ | ||
\row & \gd & \gn{path\_expr} \gt{.} \gs{attr\_name} \\ | ||
\row & \gd & \gn{path\_expr} \gt{[} \gs{expr\_query} \gt{]} \\ | ||
\row & \gd & \gn{path\_expr} \gt{.} \gl{*} \\ | ||
\row & \gd & \gn{path\_expr} \gt{[} \gl{*} \gt{]} \\ | ||
|
||
\hline | ||
\row & \textbf{$\downarrow$ NEW} & \\ | ||
\row & \multicolumn{2}{@{}l@{~}|}{\textbf{\gn{let\_clause}}} \\ | ||
|
||
\row & \gp & \textbf{\gt{LET} \gn{expr\_query} \gt{AS} \gn{variable} (, \gn{expr\_query} \gt{AS} \gn{variable})*} \\ | ||
|
||
\hline | ||
\row & \textbf{$\downarrow$ NEW} & \\ | ||
\row & \multicolumn{2}{@{}l@{~}|}{\textbf{\gn{letting\_clause}}} \\ | ||
|
||
\row & \gp & \textbf{\gt{LETTING} \gn{expr\_query} \gt{AS} \gn{variable} (, \gn{expr\_query} \gt{AS} \gn{variable})*} \\ | ||
|
||
\hline | ||
\end{tabular} | ||
\caption{Figure 3 of the PartiQL specification.} | ||
\label{figure:query:bnf} | ||
\end{figure} | ||
|
||
\section{\gl{WITH}, \gl{LET} and \gl{LETTING}} | ||
\label{sec:with-let-letting} | ||
This PSR also adds the following section to the PartiQL specificaiton. | ||
|
||
\begin{figure}[ht!] | ||
\centering | ||
\begin{tabular}{lll} | ||
\gn{var\_decl} & \gp & \gn{expr\_query} \gt{AS} \gn{binding} \\ | ||
\gn{var\_decl\_list} & \gp & \gn{var\_decl} (, \gn{var\_decl})* \\ | ||
\gn{with\_clause} & \gp & (to do) \\ | ||
\gn{let\_clause} & \gp & \gt{LET} \gn{var\_decl\_list} \\ | ||
\gn{letting\_clause} & \gp & \gt{LETTING} \gn{var\_decl\_list} \\ | ||
\end{tabular} | ||
\caption{BNF Grammar for \gl{WITH}, \gl{LET} and \gl{LETTING}} | ||
\label{figure:let} | ||
\end{figure} | ||
|
||
\gl{WITH}, \gl{LET} and \gl{LETTING} allow the user to bind expressions to variable names. | ||
Their purpose and semantics are similar, with differences in the context in | ||
which they execute and the scope of the variables they define. Figure | ||
\ref*{figure:query:bnf} shows the contexts in which these clauses are allowed. | ||
|
||
\subsection*{Lexical Scoping} | ||
|
||
Every \gn{var\_decl} included with \gl{WITH}, \gl{LET} or \gl{LETTING} is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: ... |
||
establishes a new environment which is nested according to the lexical order of | ||
the \gn{var\_decl\_list}. The \emph{last} nested environment is then accessible | ||
in different parts of a \gl{SELECT} query for each \gl{WITH}, \gl{LET} and | ||
\gl{LETTING} clauses as described in the following sections. | ||
|
||
To illustrate the lexcial scoping rules of a \gn{var\_decl\_list} we will use | ||
the \gl{LET} clause, however these rules are the same for \gl{WITH} and | ||
\gl{LETTING}. | ||
|
||
\bigskip | ||
|
||
\noindent Variables defined later in the \gn{var\_decl\_list} \emph{shadow} any | ||
preceding variables with the same name. The value of \lstinline{x} is | ||
\lstinline{42}: | ||
|
||
\begin{lstlisting} | ||
LET 1 AS x, 42 AS x | ||
\end{lstlisting} | ||
|
||
\noindent Furthermore, shadowing may also occur with variables defined | ||
\emph{prior} to the \gl{LET} clause. The result of the | ||
following query is \lstinline{<< 42 >>}. | ||
|
||
\begin{lstlisting} | ||
SELECT VALUE x FROM << { 'y': 42 } >> AS x LET x = x.y | ||
\end{lstlisting} | ||
|
||
\noindent Variables defined earlier \gn{var\_decl\_list} cannot access variables defined | ||
later. Here, an error occurs inside the definition of \lstinline{y} because | ||
\lstinline{x} has not been defined yet: | ||
|
||
\begin{lstlisting} | ||
LET x + 1 AS y, 41 AS x | ||
\end{lstlisting} | ||
|
||
\subsection{WITH clause} | ||
|
||
The \gl{WITH} clause defines variables to be defined \emph{before} query | ||
evaluation. Variables defined using \gl{WITH} are scoped to the associated | ||
\gn{expr\_query}. | ||
|
||
\bigskip | ||
|
||
TODO... | ||
|
||
\subsection{LET clause} | ||
\label{sec:let-clause} | ||
|
||
\gl{LET} is an optional clause of a \gl{SELECT} query that immediately follows | ||
the \gl{FROM} clause. \gl{LET} executes once for every environment produced by | ||
the \gl{FROM} clause, creating one nested environment with a newly bound | ||
variable for every \gn{var\_decl}. The \emph{last} environment produced by the | ||
\gl{LET} clause is accessible in the remaining clauses of the \gl{SELECT} query | ||
with certain exceptions defined in section | ||
\ref*{sec:let-variable-accessibility}. | ||
|
||
\subsubsection{Acessibility of variables defined using \gl{LET}} | ||
\label{sec:let-variable-accessibility} | ||
|
||
The \gl{GROUP BY} clause consumes the environments produced by the \gl{FROM} clause and | ||
produces a new set of environments, which affects the clauses which can access | ||
the variables defined by \gl{LET}. Figure | ||
\ref*{figure:let-variable-accessibility} shows which parts of a \gl{SELECT} | ||
query can access variables defined by \gl{LET} with and without \gl{GROUP | ||
BY}. | ||
alancai98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
\begin{figure}[ht] | ||
\centering | ||
\begin{tabular}{lcc} | ||
\gl{SELECT} & \multicolumn{2}{c}{Are variables defined with \gl{LET} accessible?} \\ | ||
clause & Without \gl{GROUP BY} & With \gl{GROUP BY} \\ | ||
\hline | ||
\gl{FROM} & No & No \\ | ||
\gl{LET} & Yes (per lexical scoping) & Yes (per lexical scoping) \\ | ||
\gl{WHERE} & Yes & Yes \\ | ||
\gl{GROUP BY} & N/A & Yes \\ | ||
\gl{LETTING} & N/A & No \\ | ||
\gl{HAVING} & N/A & No \\ | ||
\gl{ORDER BY} & Yes & No \\ | ||
\gl{OFFSET} & No & No \\ | ||
\gl{LIMIT} & No & No \\ | ||
projection & Yes & No \\ | ||
\end{tabular} | ||
\caption{Accessibility of variables defined using the \gl{LET} clause.} | ||
\label{figure:let-variable-accessibility} | ||
\end{figure} | ||
|
||
Note that variables defined by \gl{LET} are not accessible to the \gl{LIMIT} or | ||
\gl{OFFSET} clauses because those clauses do not have access to the environments | ||
produced by the \gl{FROM} or \gl{GROUP BY} clauses. | ||
|
||
|
||
\subsection{\gl{LETTING} clause} | ||
|
||
\gl{LETTING} is an optional clause of a \gl{SELECT} query that immediately | ||
follows the \gl{GROUP BY} clause. \gl{LETTING} executes once for every | ||
environment produced by the \gl{GROUP BY} clause, creating one nested | ||
environment for every \gn{var\_decl}. The \emph{last} environment produced by | ||
the \gl{LETTING} clause is accessible in the remaining clauses of the | ||
\gl{SELECT} query as defined in figure | ||
\ref*{figure:letting-variable-accessibility}. | ||
|
||
Use of \gl{LETTING} without \gl{GROUP BY} is considered to be an error. | ||
|
||
\begin{figure}[ht] | ||
\centering | ||
\begin{tabular}{lcc} | ||
\gl{SELECT} & Are variables defined with \\ | ||
clause & \gl{LETTING} accessible? \\ | ||
\hline | ||
\gl{FROM} & No \\ | ||
\gl{LET} & No \\ | ||
\gl{WHERE} & No \\ | ||
\gl{GROUP BY} & No \\ | ||
\gl{LETTING} & Yes (per lexical scoping) \\ | ||
\gl{HAVING} & Yes \\ | ||
\gl{ORDER BY} & Yes \\ | ||
\gl{OFFSET} & No \\ | ||
\gl{LIMIT} & No \\ | ||
projection & Yes \\ | ||
\end{tabular} | ||
\caption{Accessibility of variables defined using the \gl{LETTING} clause.} | ||
\label{figure:letting-variable-accessibility} | ||
\end{figure} | ||
|
||
|
||
\subsection{Behavior of \gl{WITH}, \gl{LET} and \gl{LETTING} and \gl{SELECT *}} | ||
|
||
\gl{SELECT *} is unaffected by the use of \gl{WITH}, \gl{LET} and \gl{LETTING}. | ||
That is, variables introduced with these clauses are not included in | ||
\gl{SELECT *} projections. | ||
alancai98 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing this? If you do not want the watermark to show, use the instructions in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unnecessary because there is already the text
--DRAFT--
in the heading of every page. Also, it was too big to fit on the page. You could only see part of R, the full A and part of F, previously. When I shrank it, it just looked bad and distracting (IMHO).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too attached to this I just found the text easier to read without the watermark. If the DRAFT watermark is convention or something let me know...