Changes between Initial Version and Version 1 of rfc21_ogrsqlcast


Ignore:
Timestamp:
Jan 24, 2008, 2:25:53 PM (16 years ago)
Author:
tamas
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • rfc21_ogrsqlcast

    v1 v1  
     1= RFC 21: OGR SQL type cast and field name alias =
     2
     3Author: Tamas Szekeres[[BR]]
     4Contact: szekerest@gmail.com[[BR]]
     5Status: Proposed
     6
     7== Summary ==
     8
     9This proposal provides support for changing the column name and the column type
     10in the OGR SQL select list.
     11
     12The main motivation of this change is to provide better control when transferring
     13the OGR_STYLE special field from each data source to the other.
     14For example we can use ogr2ogr for this purpose using the fillowing command line:
     15
     16{{{
     17ogr2ogr -f "ESRI Shapefile" -sql "select *, OGR_STYLE from rivers" rivers.shp rivers.tab
     18}}}
     19
     20The shape driver will truncate the OGR_STYLE field to 80 characters by default in length
     21that may not be enough to hold the actual value.
     22So as to fix this issue we might want to specify the desired length in the select list, like:
     23
     24{{{
     25ogr2ogr -f "ESRI Shapefile" -sql "select *, CAST(OGR_STYLE AS character(255)) from rivers" rivers.shp rivers.tab
     26}}}
     27
     28In some cases it would also be useful to change the name of the field in the target data source:
     29
     30{{{
     31ogr2ogr -f "ESRI Shapefile" -sql "select *, CAST(OGR_STYLE AS character(255)) AS 'STYLE' from rivers" rivers.shp rivers.tab
     32}}}
     33
     34== Main concepts ==
     35
     36To support these new features we will extend the current OGR SQL syntax. The proposed addition will keep the syntax
     37conform to the SQL92 specification:
     38
     39{{{
     40SELECT <field-list> FROM <table_def>
     41     [LEFT JOIN <table_def>
     42      ON [<table_ref>.]<key_field> = [<table_ref>.].<key_field>]*
     43     [WHERE <where-expr>]
     44     [ORDER BY <sort specification list>]
     45
     46<field-list> ::= <column-spec> [ { , <column-spec> }... ]
     47
     48<column-spec> ::= <field-spec> [ <as clause> ]
     49                 | CAST ( <field-spec> AS <data type> ) [ <as clause> ]
     50
     51<field-spec> ::= [DISTINCT] <field_ref>
     52                 | <field_func> ( [DISTINCT] <field-ref> )
     53                 | Count(*)
     54
     55<as clause> ::= [ AS ] <column_name>
     56
     57<data type> ::= character [ ( field_length ) ]
     58                | float [ ( field_length ) ]
     59                | integer [ ( field_length ) ]
     60
     61<field-func> ::= AVG | MAX | MIN | SUM | COUNT
     62
     63<field_ref>  ::= [<table_ref>.]field_name
     64
     65<sort specification list> ::=
     66              <sort specification> [ { <comma> <sort specification> }... ]
     67
     68<sort specification> ::= <sort key> [ <ordering specification> ]
     69
     70<sort key> ::=  <field_ref>
     71
     72<ordering specification> ::= ASC | DESC
     73
     74<table_def> ::= ['<datasource name>'.]table_name [table_alias]
     75
     76<table_ref> ::= table_name | table_alias
     77}}}
     78
     79== Implementation ==
     80
     81To implement the addition the following changes should be made in the OGR codebase:
     82
     831. In swq.h I'll have to add to 3 fields to swq_col_def to hold the field_alias the target_type
     84and the field_length.
     85
     862. In swq.c I'll have to change swq_select_preparse to take care of the field alias and the
     87CAST specification.
     88
     893. A new function (swq_parse_typename) will be added to parse the supported typenames.
     90
     914. In ogr_gensql.cpp the .ctor of OGRGenSQLResultsLayer will be changed to set up the field name and the
     92field length to the target data source
     93
     945. In ogr_gensql.cpp TranslateFeature will be modified to take care of the type change if specified.
     95
     96== Backward Compatibility ==
     97
     98The backward compatibility for the current SQL syntax will be retained. This addition
     99doesn't requre changes in the OGR C and SWIG API.
     100
     101== Documentation ==
     102
     103The OGR SQL document will be updated to reflect the new features.
     104I'll take care of updating the OGR Style Documentation with the support of transferring the
     105styles between the data sources.
     106
     107== Implementation Staffing ==
     108
     109Tamas Szekeres will implement the RFC in the development version.
     110
     111== References ==
     112
     113 * Tracking bug for this feature (containing all of the proposed code changes): #2171
     114
     115== Voting History ==
     116
     117None