Query for UDFs
You can include User Defined Fields (UDFs) in your table query.
- For range and quantile UDFs:
- Add a
udfs
section where you define the structure of the range or quantile - Include your UDF in the
dimensions
.
- Add a
- For other UDF formats, include a
where
clause in your query.
For more details about range and quantile UDFs, see Ranges and Quantiles.
Range UDFs
Following is an example of a table query that defines a range UDF:
{
"database" : "str:database:bank",
"measures" : [ "str:count:bank:F_Customer" ],
"udfs": {
"myRange":{
"type": "RANGE",
"from": 1,
"to": 500,
"increment": 100,
"measure": "str:measure:bank:F_Customer:Cust_Profit",
"label": "My Range",
"toInclusive": true
}
},
"dimensions" : [
[ "str:field:bank:F_Customer:Gender" ], [ "str:udf:myRange" ]
]
}
Where:
myRange | This is an ID for the UDF; you can replace it with any string. You need to use this ID in the | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type | Set to RANGE for a range UDF. | ||||||||||||||
from | The starting value for the set of ranges. | ||||||||||||||
to | The end value for the set of ranges. | ||||||||||||||
increment | The size of each range. | ||||||||||||||
measure | The Open Data ID of the measure you want to create a range for. This needs to match the ID format this is returned by the /schema endpoint. | ||||||||||||||
label | A label (display name) for the UDF that will be returned in the query results. | ||||||||||||||
toInclusive | Set this to either
|
Quantile UDFs
Following is an example of a table query that defines a quantile UDF:
{
"database" : "str:database:bank",
"measures" : [ "str:count:bank:F_Customer" ],
"udfs": {
"myRange": {
"type": "QUANTILE",
"label": "My Quantile",
"measure": "str:measure:bank:F_Customer:Cust_Profit",
"distribution": "str:count:bank:F_Customer",
"ranges": 5
}
},
"dimensions" : [
[ "str:field:bank:F_Customer:Gender" ], [ "str:udf:myRange" ]
]
}
Where:
myRange | This is an ID for the UDF; you can replace it with any string. You need to use this ID in the |
---|---|
type | Set to QUANTILE for a quantile UDF. |
label | A label (display name) for the UDF that will be returned in the query results. |
measure | The Open Data ID of the measure you want to create a quantile for. This needs to match the ID format this is returned by the /schema endpoint. |
distribution | The measure or count to use to determine the distribution of the quantile. This can be any measure or count, but must return positive values for all records. It is equivalent to the Equal Distribution Of setting in SuperWEB2. See Ranges and Quantiles for more details. |
ranges | The number of quantile ranges to create. By default you can choose between 2 and 10, but these limits can be configured by the administrator on a per-dataset basis using the SuperADMIN ranges command. |
Other UDFs (Where Clause)
For other UDF types, you can include a where
clause in your query. Following are some examples of valid queries. See below for details of the query format.
Example: Single UDF - Individuals who are Male or Married
{
"database": "str:database:bank",
"measures": [ "str:count:bank:F_Customer" ],
"where": {
"operator": "OR",
"conditions": [
{
"operator": "EQUAL",
"field": "str:field:bank:F_Customer:Gender",
"value": "Male"
},
{
"operator": "EQUAL",
"field": "str:field:bank:F_Customer:Marital_Status",
"value": "Married"
}
]
}
}
Example: Individuals who are Single or Unmarried and live in postcodes 2000 or 3000
{
"database": "str:database:bank",
"measures": [ "str:count:bank:F_Customer" ],
"dimensions": [
[ "str:valueset:bank:F_Customer:Area:C_State" ]
],
"where": {
"operator": "AND",
"conditions": [
{
"operator": "IN",
"field": "str:valueset:bank:F_Customer:Area:C_State",
"values": [ "Victoria", "New South Wales" ]
},
{
"operator": "IN",
"field": "str:valueset:bank:F_Customer:Area:C_Geography_0",
"values": [ "2000", "3000" ]
},
{
"operator": "IN",
"field": "str:field:bank:F_Customer:Marital_Status",
"values": [ "Single", "Unmarried" ]
}
]
}
}
Example: Using Greater Than and Less Than
{
"database": "str:database:bank",
"measures": [ "str:count:bank:F_Customer" ],
"dimensions": [["str:valueset:bank:F_Customer:Gender:C_Gender"]],
"where": {
"operator": "OR",
"conditions": [
{
"operator": "GREATER_THAN",
"field": "str:measure:bank:F_Account:Acc_Profit",
"value": 10
},
{
"operator": "LESS_THAN",
"field": "str:measure:bank:F_Account:Avg_Acc_Balance",
"value": -20
}
]
}
}
Example: Use of BETWEEN Operator
{
"database": "str:database:bank",
"measures": [ "str:count:bank:F_Customer" ],
"dimensions": [["str:valueset:bank:F_Customer:Gender:C_Gender"]],
"where": {
"operator": "OR",
"conditions": [
{
"operator": "BETWEEN",
"field": "str:measure:bank:F_Account:Acc_Profit",
"value1": 10,
"value2": 20
}
]
}
}
Where Clause Query Format
operator | The logical operator applied to the conditions. One of the following:
| ||||||
---|---|---|---|---|---|---|---|
conditions | A list of conditions:
|