Permalink
Browse files

Add auto completion for window function keywords and functions

  • Loading branch information...
MKleusberg committed Sep 27, 2018
1 parent 78ae2c3 commit 7e23214e61829485993ce1910ec95233de21dcaa
Showing with 23 additions and 6 deletions.
  1. +23 −6 src/SqlUiLexer.cpp
@@ -33,20 +33,20 @@ void SqlUiLexer::setupAutoCompletion()
<< "DATABASE" << "DEFAULT" << "DEFERRABLE" << "DEFERRED" << "DELETE"
<< "DESC" << "DETACH" << "DISTINCT" << "DROP" << "EACH"
<< "ELSE" << "END" << "ESCAPE" << "EXCEPT" << "EXCLUSIVE"
<< "EXISTS" << "EXPLAIN" << "FAIL" << "FOR" << "FOREIGN"
<< "EXISTS" << "EXPLAIN" << "FAIL" << "FILTER" << "FOLLOWING" << "FOR" << "FOREIGN"
<< "FROM" << "FULL" << "GLOB" << "GROUP" << "HAVING"
<< "IF" << "IGNORE" << "IMMEDIATE" << "IN" << "INDEX"
<< "INDEXED" << "INITIALLY" << "INNER" << "INSERT" << "INSTEAD"
<< "INTERSECT" << "INTO" << "IS" << "ISNULL" << "JOIN"
<< "KEY" << "LEFT" << "LIKE" << "LIMIT" << "MATCH"
<< "NATURAL" << "NO" << "NOT" << "NOTNULL" << "NULL"
<< "OF" << "OFFSET" << "ON" << "OR" << "ORDER"
<< "OUTER" << "PLAN" << "PRAGMA" << "PRIMARY" << "QUERY"
<< "RAISE" << "RECURSIVE" << "REFERENCES" << "REGEXP" << "REINDEX" << "RELEASE"
<< "OUTER" << "OVER" << "PARTITION" << "PLAN" << "PRAGMA" << "PRECEDING" << "PRIMARY" << "QUERY"
<< "RAISE" << "RANGE" << "RECURSIVE" << "REFERENCES" << "REGEXP" << "REINDEX" << "RELEASE"
<< "RENAME" << "REPLACE" << "RESTRICT" << "RIGHT" << "ROLLBACK"
<< "ROWID" << "SAVEPOINT" << "SELECT" << "SET" << "TABLE"
<< "ROWID" << "ROWS" << "SAVEPOINT" << "SELECT" << "SET" << "TABLE"
<< "TEMP" << "TEMPORARY" << "THEN" << "TO" << "TRANSACTION"
<< "TRIGGER" << "UNION" << "UNIQUE" << "UPDATE" << "USING"
<< "TRIGGER" << "UNBOUNDED" << "UNION" << "UNIQUE" << "UPDATE" << "USING"
<< "VACUUM" << "VALUES" << "VIEW" << "VIRTUAL" << "WHEN"
<< "WHERE" << "WITH" << "WITHOUT"
// Data types
@@ -117,7 +117,24 @@ void SqlUiLexer::setupAutoCompletion()
<< "max" + tr("(X) The max() aggregate function returns the maximum value of all values in the group.")
<< "min" + tr("(X) The min() aggregate function returns the minimum non-NULL value of all values in the group.")
<< "sum" + tr("(X) The sum() and total() aggregate functions return sum of all non-NULL values in the group.")
<< "total" + tr("(X) The sum() and total() aggregate functions return sum of all non-NULL values in the group.");
<< "total" + tr("(X) The sum() and total() aggregate functions return sum of all non-NULL values in the group.")
// Window functions
<< "row_number" + tr("() The number of the row within the current partition. Rows are numbered starting from 1 in the order defined by the ORDER BY clause in the window definition, or in arbitrary order otherwise.")
<< "rank" + tr("() The row_number() of the first peer in each group - the rank of the current row with gaps. If there is no ORDER BY clause, then all rows are considered peers and this function always returns 1.")
<< "dense_rank" + tr("() The number of the current row's peer group within its partition - the rank of the current row without gaps. Partitions are numbered starting from 1 in the order defined by the ORDER BY clause in the window definition. If there is no ORDER BY clause, then all rows are considered peers and this function always returns 1. ")
<< "percent_rank" + tr("() Despite the name, this function always returns a value between 0.0 and 1.0 equal to (rank - 1)/(partition-rows - 1), where rank is the value returned by built-in window function rank() and partition-rows is the total number of rows in the partition. If the partition contains only one row, this function returns 0.0. ")
<< "cume_dist" + tr("() The cumulative distribution. Calculated as row-number/partition-rows, where row-number is the value returned by row_number() for the last peer in the group and partition-rows the number of rows in the partition.")
<< "ntile" + tr("(N) Argument N is handled as an integer. This function divides the partition into N groups as evenly as possible and assigns an integer between 1 and N to each group, in the order defined by the ORDER BY clause, or in arbitrary order otherwise. If necessary, larger groups occur first. This function returns the integer value assigned to the group that the current row is a part of.")
<< "lag" + tr("(expr) Returns the result of evaluating expression expr against the previous row in the partition. Or, if there is no previous row (because the current row is the first), NULL.")
<< "lag" + tr("(expr,offset) If the offset argument is provided, then it must be a non-negative integer. In this case the value returned is the result of evaluating expr against the row offset rows before the current row within the partition. If offset is 0, then expr is evaluated against the current row. If there is no row offset rows before the current row, NULL is returned.")
<< "lag" + tr("(expr,offset,default) If default is also provided, then it is returned instead of NULL if the row identified by offset does not exist.")
<< "lead" + tr("(expr) Returns the result of evaluating expression expr against the next row in the partition. Or, if there is no next row (because the current row is the last), NULL.")
<< "lead" + tr("(expr,offset) If the offset argument is provided, then it must be a non-negative integer. In this case the value returned is the result of evaluating expr against the row offset rows after the current row within the partition. If offset is 0, then expr is evaluated against the current row. If there is no row offset rows after the current row, NULL is returned.")
<< "lead" + tr("(expr,offset,default) If default is also provided, then it is returned instead of NULL if the row identified by offset does not exist.")
<< "first_value" + tr("(expr) This built-in window function calculates the window frame for each row in the same way as an aggregate window function. It returns the value of expr evaluated against the first row in the window frame for each row.")
<< "last_value" + tr("(expr) This built-in window function calculates the window frame for each row in the same way as an aggregate window function. It returns the value of expr evaluated against the last row in the window frame for each row.")
<< "nth_value" + tr("(expr,N) This built-in window function calculates the window frame for each row in the same way as an aggregate window function. It returns the value of expr evaluated against the row N of the window frame. Rows are numbered within the window frame starting from 1 in the order defined by the ORDER BY clause if one is present, or in arbitrary order otherwise. If there is no Nth row in the partition, then NULL is returned.")
;

listFunctions.clear();
for(const QString& keyword : functionPatterns)

0 comments on commit 7e23214

Please sign in to comment.