Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-01-31 16:00:20 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-02-04 10:22:46 -0500
commit11109d43612d924f80f74d0a4a847c7a102c6606 (patch)
treee772dd04bef3b5b7ee94cca2a91d8bac94a09508
parent36a3e348b6013798a85e30b443d3842c3849dbb7 (diff)
downloadtame-11109d43612d924f80f74d0a4a847c7a102c6606.tar.gz
tame-11109d43612d924f80f74d0a4a847c7a102c6606.tar.bz2
tame-11109d43612d924f80f74d0a4a847c7a102c6606.zip
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.
-rw-r--r--core/test/core/vector/interpolate.xml12
-rw-r--r--core/test/core/vector/table.xml52
-rw-r--r--core/vector/interpolate.xml4
-rw-r--r--core/vector/table.xml80
-rw-r--r--rater/rater.xsd2
-rw-r--r--src/current/rater.xsd2
6 files changed, 115 insertions, 37 deletions
diff --git a/core/test/core/vector/interpolate.xml b/core/test/core/vector/interpolate.xml
index 91b5b2e..edf3407 100644
--- a/core/test/core/vector/interpolate.xml
+++ b/core/test/core/vector/interpolate.xml
@@ -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>
diff --git a/core/test/core/vector/table.xml b/core/test/core/vector/table.xml
index df2b5e3..1491e11 100644
--- a/core/test/core/vector/table.xml
+++ b/core/test/core/vector/table.xml
@@ -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>
diff --git a/core/vector/interpolate.xml b/core/vector/interpolate.xml
index f8887ba..a2725f1 100644
--- a/core/vector/interpolate.xml
+++ b/core/vector/interpolate.xml
@@ -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>
diff --git a/core/vector/table.xml b/core/vector/table.xml
index 53c13a7..515f638 100644
--- a/core/vector/table.xml
+++ b/core/vector/table.xml
@@ -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
diff --git a/rater/rater.xsd b/rater/rater.xsd
index cbc7473..f2ad50f 100644
--- a/rater/rater.xsd
+++ b/rater/rater.xsd
@@ -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>
diff --git a/src/current/rater.xsd b/src/current/rater.xsd
index 86accc4..d2a6019 100644
--- a/src/current/rater.xsd
+++ b/src/current/rater.xsd
@@ -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>