Changes between Version 5 and Version 6 of rfc28_sqlfunc
- Timestamp:
- Aug 1, 2010, 4:59:38 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
rfc28_sqlfunc
v5 v6 1 = RFC 28: OGR SQL SELECT Functions =1 = RFC 28: OGR SQL Generalized Expressions = 2 2 3 3 Author: Frank Warmerdam[[BR]] … … 7 7 == Summary == 8 8 9 The OGR SQL evaluation engine currently does not allow general purpose functions to be applied to columns in SELECT statements. Some special purpose functions are supported (ie. CAST, COUNT, AVG, MAX, MIN, and SUM), but not as part of more general expressions and generally in very constrained arrangements. It is the intent of this work item to extend the OGR SQL engine to support fairly general purpose expression evaluation in the output field list of OGR SQL SELECT statements and to implement a few preliminary processing functions in a fashion compatible with standard SQL. For example, after implementation it is intended the following could be evaluated.9 The OGR SQL evaluation engine currently does not allow general purpose functions to be applied to columns in SELECT statements. Some special purpose functions are supported (ie. CAST, COUNT, AVG, MAX, MIN, and SUM), but not as part of more general expressions and generally in very constrained arrangements. It is the intent of this work item to extend the OGR SQL engine to support fairly general purpose expression evaluation in the output field list of OGR SQL SELECT statements and to implement a few preliminary processing functions in a fashion compatible with standard SQL. As well, expressions used in WHERE clauses will be generalized to support evaluation of non-logical operations, such as math and functions. For example, after implementation it is intended the following could be evaluated. 10 10 11 11 {{{ 12 12 SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM customers 13 13 SELECT id, "Regional Road" AS roadtypename FROM roads where roadtype=3 14 SELECT (subtotal+salestax) as totalcost from invoice_info 14 SELECT (subtotal+salestax) as totalcost from invoice_info where 100 <= (subtotal+salestax) 15 15 }}} 16 16 17 17 == Technical Approach == 18 18 19 ... to be filled in, but the intention is that the existing expression evaluation engine for the WHERE clause would be extended and used also on the SELECT field generation side. 19 Currently logical expressions take a very constrained format with the base elements having to be of the form ''<field> <operation> <constant_value>''. As part of the generalization non-logical expressions will be supported and the left and right side of operators will be equally treated. The current OGR SQL parser is ad hoc and cannot be practically extended to this generalized form of expression. So at this point we will move to a yacc/bison based parser grammar for expressions. 20 21 Since it is not really practical to continue to use the existing ad hoc SELECT parsing when parts of the SELECT statement are expressions, the yacc/bison based parser will also be used to parse the whole SELECT statement. 22 23 The current expression node will be generalized to have 0-n children (for arguments to functions), and to treat field references and constant values as distinct leaf nodes rather than embedding this information in a node defining an operation. 20 24 21 25 It should be noted that as a side effect WHERE clauses will also support more general expressions - not just logical comparisons. For instance: 22 26 23 27 SELECT * WHERE (subtotal+salestax) > 100.0 24 25 28 26 29 == New Functions == … … 79 82 == Special Notes == 80 83 81 The existing CAST operator will likely be reworked as a regular function. This might also imply it can work on the WHERE clause side. 82 83 The MAX, MIN, AVG, SUM and COUNT operators will not be handled by the expression evaluator. Their implementation will remain a 84 special case for summarized results. 85 86 How will DISTINCT be handled? It seems like this is a form of summarization mode and is likely to be only supported in some very limited forms. 87 84 The existing CAST, and column summary functions COUNT, AVG, MIN, MAX and SUM will be treated more-or-less as functions but constrained to be root operations on column definitions and treated as a special case (still). 85 88 86 == Compatability Implications == 89 87 … … 101 99 == Testing == 102 100 101 All existing OGR SQL test suite tests should pass, and autotest/ogr/ogr_sql_test.py and perhaps other scripts will be extended for the new capabilities. 102 103 103 == Documentation == 104 104 105 The [http://www.gdal.org/ogr/ogr_sql.html OGR SQL] document will be extended to describe the new capabilities. 105 106