core: Add _where-*_ query predicate templates

These provide a more pleasent abstraction than having to reference CMP_OP_*
constants.

* core/test/core/vector/interpolate.xml: {t:when=>t:where-eq}.
* core/test/core/vector/table.xml: Likewise, but using the other variants
    where appropriate given the value of `@op'.
* core/vector/interpolate.xml: Likewise.
* core/vector/table.xml (_when_, _where_): Rename former to latter and
    provide deprecation warning.
  (_when-lt_, _when-lte_, _when-gt_, _when-gte_): Add abstractions.
* src/current/rater.xsd: Permit template variable as tenplate name.
master
Mike Gerwitz 2019-01-31 16:00:20 -05:00
parent 36a3e348b6
commit 11109d4361
6 changed files with 115 additions and 37 deletions

View File

@ -130,9 +130,9 @@
<rate yields="interpTableMaxFieldValue">
<t:query-first-field table="interp-query-field-test"
field="value">
<t:when field="key">
<t:where-eq field="key">
<c:value-of name="interpTableMaxKeyValue" />
</t:when>
</t:where-eq>
</t:query-first-field>
</rate>
</section>
@ -170,10 +170,10 @@
key="key"
step="INTERP_TABLE_STEP"
actual="#300">
<t:when field="pred">
<t:where-eq field="pred">
<c:const value="31" type="float"
desc="Test predicate value" />
</t:when>
</t:where-eq>
</t:interpolate-query-field>
</t:given>
@ -220,10 +220,10 @@
key="key"
step="INTERP_TABLE_STEP"
actual="#350">
<t:when field="pred">
<t:where-eq field="pred">
<c:const value="31" type="float"
desc="Test predicate value" />
</t:when>
</t:where-eq>
</t:interpolate-query-field>
</t:given>

View File

@ -122,9 +122,9 @@
<t:it desc="returns first row of multi-row result">
<t:given>
<t:query-first-field table="test-table" field="c">
<t:when field="a">
<t:where-eq field="a">
<c:value-of name="#1" />
</t:when>
</t:where-eq>
</t:query-first-field>
</t:given>
@ -137,12 +137,12 @@
<t:it desc="returns first row of single-row result">
<t:given>
<t:query-first-field table="test-table" field="c">
<t:when field="a">
<t:where-eq field="a">
<c:value-of name="#1" />
</t:when>
<t:when field="b">
</t:where-eq>
<t:where-eq field="b">
<c:value-of name="#12" />
</t:when>
</t:where-eq>
</t:query-first-field>
</t:given>
@ -160,9 +160,9 @@
<t:given>
<c:length-of>
<t:query-field table="test-table" field="c">
<t:when field="a">
<t:where-eq field="a">
<c:value-of name="#1" />
</t:when>
</t:where-eq>
</t:query-field>
</c:length-of>
</t:given>
@ -177,12 +177,12 @@
<t:given>
<c:car>
<t:query-field table="test-table" field="c">
<t:when field="a">
<t:where-eq field="a">
<c:value-of name="#1" />
</t:when>
<t:when field="b">
</t:where-eq>
<t:where-eq field="b">
<c:value-of name="#11" />
</t:when>
</t:where-eq>
</t:query-field>
</c:car>
</t:given>
@ -218,9 +218,9 @@
<c:values>
<c:value name="results" type="integer" set="vector">
<t:query-field table="test-table-seq" field="a">
<t:when field="a" op="CMP_OP_LT">
<t:where-lt field="a">
<c:value-of name="#5" />
</t:when>
</t:where-lt>
</t:query-field>
</c:value>
</c:values>
@ -244,9 +244,9 @@
<c:values>
<c:value name="results" type="integer" set="vector">
<t:query-field table="test-table-seq" field="a">
<t:when field="a" op="CMP_OP_LTE">
<t:where-lte field="a">
<c:value-of name="#5" />
</t:when>
</t:where-lte>
</t:query-field>
</c:value>
</c:values>
@ -270,9 +270,9 @@
<c:values>
<c:value name="results" type="integer" set="vector">
<t:query-field table="test-table-seq" field="a">
<t:when field="a" op="CMP_OP_GT">
<t:where-gt field="a">
<c:value-of name="#5" />
</t:when>
</t:where-gt>
</t:query-field>
</c:value>
</c:values>
@ -296,9 +296,9 @@
<c:values>
<c:value name="results" type="integer" set="vector">
<t:query-field table="test-table-seq" field="a">
<t:when field="a" op="CMP_OP_GTE">
<t:where-gte field="a">
<c:value-of name="#5" />
</t:when>
</t:where-gte>
</t:query-field>
</c:value>
</c:values>
@ -323,9 +323,9 @@
<t:given>
<c:length-of>
<t:query-row table="test-table">
<t:when field="a">
<t:where-eq field="a">
<c:value-of name="#1" />
</t:when>
</t:where-eq>
</t:query-row>
</c:length-of>
</t:given>
@ -343,12 +343,12 @@
<c:value name="first_row" type="integer" set="vector">
<c:car>
<t:query-row table="test-table">
<t:when field="a">
<t:where-eq field="a">
<c:value-of name="#1" />
</t:when>
<t:when field="b">
</t:where-eq>
<t:where-eq field="b">
<c:value-of name="#11" />
</t:when>
</t:where-eq>
</t:query-row>
</c:car>
</c:value>

View File

@ -202,10 +202,10 @@
<t:query-field table="@table@"
field="@field@">
<!-- query for upper and lower values for interpolation -->
<t:when field="@key@">
<t:where-eq field="@key@">
<c:value-of name="low" />
<c:value-of name="high" />
</t:when>
</t:where-eq>
<param-copy name="@values@" />
</t:query-field>

View File

@ -348,7 +348,45 @@
</template>
<template name="_when_" desc="Create field predicate for query definition">
There are a series of \tt{_where-*_} templates for query predicates that
are analogous to the \tt{_match-*_} and \tt{_when-*_} templates used in
other contexts.
<inline-template>
<for-each>
<set tplname="_where-eq_" op="CMP_OP_EQ" desc="equal" />
<set tplname="_where-lt_" op="CMP_OP_LT" desc="less than" />
<set tplname="_where-lte_" op="CMP_OP_LTE" desc="less than or equal to" />
<set tplname="_where-gt_" op="CMP_OP_GT" desc="greater than" />
<set tplname="_where-gte_" op="CMP_OP_GTE" desc="greater than or equal to" />
</for-each>
<template name="@tplname@" desc="Field predicate for table query ({@desc@})">
<param name="@values@" desc="Field value (provide only one node)" />
<param name="@id@" desc="Field index" />
<param name="@field@" desc="Field name (to be used with base)" />
<param name="@name@" desc="Field name (as a variable/constant)">
<text></text>
</param>
<param name="@seqvar@" desc="Var/constant containing whether field is sequential">
<text></text>
</param>
<t:where id="@id@" seqvar="@seqvar@"
field="@field@" name="@name@" op="@op@">
<expand-barrier>
<param-copy name="@values@" />
</expand-barrier>
</t:where>
</template>
</inline-template>
<template name="_where_" desc="Create field predicate for query definition">
<param name="@id@" desc="Field index" />
<param name="@values@" desc="Field value (provide only one node)" />
<param name="@sequential@" desc="Is data sequential?" />
@ -413,6 +451,46 @@
</template>
<!--
_when_ is deprecated in favor of _where-eq_.
This old template aimed to be consistent with the use of `when'
elsewhere (for cases and value predicates), but it was awkward in a
query abstraction.
-->
<template name="_when_"
desc="Create field predicate for query definition (deprecated;
use _where-*_)">
<param name="@values@" desc="Field value (provide only one node)" />
<param name="@id@" desc="Field index" />
<param name="@sequential@" desc="Is data sequential?" />
<param name="@field@" desc="Field name (to be used with base)" />
<param name="@name@" desc="Field name (as a variable/constant)">
<text></text>
</param>
<param name="@seqvar@" desc="Var/constant containing whether field is sequential">
<text></text>
</param>
<param name="@op@"
desc="Comparison operator (default CMP_OP_EQ; see CmpOp typedef)">
<text></text>
</param>
<warning>
_when_ is deprecated; use _where-eq_ instead
</warning>
<t:where id="@id@" sequential="@sequential@" seqvar="@seqvar@"
field="@field@" name="@name@" op="CMP_OP_EQ">
<param-copy name="@values@" />
</t:where>
</template>
<!--
These functions make the magic happen

View File

@ -150,7 +150,7 @@
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="_[a-zA-Z0-9@\{\}-]+_" />
<xs:pattern value="_[a-zA-Z0-9@\{\}-]+_|@[a-z][a-zA-Z0-9]*@" />
</xs:restriction>
</xs:simpleType>

View File

@ -145,7 +145,7 @@
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="_[a-zA-Z0-9@\{\}-]+_" />
<xs:pattern value="_[a-zA-Z0-9@\{\}-]+_|@[a-z][a-zA-Z0-9]*@" />
</xs:restriction>
</xs:simpleType>