Using the applyFilter parameter in the C# API¶
Supported operators¶
For the list of comparison operators available in kdb see here. In addition to these, we support the operators
Syntax for the applyFilter parameter¶
The applyFilter parameter takes an object array as its value. The format of this object array is:
new object[] { Operator, ColumnName, ValueToFilter }
The types of the expected elements in the object array are:
Operatoris a Char typeColumnNameis a String typeValueToFilterdepends on the datatype stored in the column calledColumnName
See here for a mapping from kdb datatypes to .NET datatypes.
The datatype in a QueryResult can be determined using the ColumnType method in the QueryResult class. Alternatively, if the name of the schema is known, the datatypes can be determined using the GetCompatibleTypes method in the Service class.
Examples¶
Filtering for a single value¶
To filter based on a single value, we generally use the = operator. The exception to this rule is when filtering for a kdb+ string; in this case we use in. This is because a string is a compound type in kdb+, where as the other examples are primitive datatypes.
Numeric type columns¶
parameters["applyFilter"] = new object[] { "=".ToCharArray(), "OrderID", 1234 };
C# string/kdb+ symbol type columns¶
parameters["applyFilter"] = new object[] { "=".ToCharArray(), "EventTypeCode", "abcd" };
Boolean type columns¶
parameters["applyFilter"] = new object[] { "=".ToCharArray(), "AllOrNoneIndicator", true };
C# character array/kdb+ string type columns¶
// Note the use of 'in' instead for '=', since its more than on Char it must be converted to a Char array
parameters["applyFilter"] = new object[] { "in".ToCharArray(), "AccountID", "SingleID".ToCharArray() };
Filtering for multiple values¶
To filter using multiple values, we need to use the in operator; the other parameters in the dictionary are omitted in the examples.
// C# String / kdb+ symbol types
parameters["applyFilter"] = new object[] { "in".ToCharArray(), "EventTypeCode", new String[] { "abcd", "efgh"} };
// C# char array / kdb+ string types
parameters["applyFilter"] = new object[] { "in".ToCharArray(), "OrderID", new char[][] { "id1".ToCharArray(), "id2".ToCharArray(), "id3".ToCharArray() } };
// C# double / kdb+ float types
parameters["applyFilter"] = new object[] { "in".ToCharArray(), "OrderID", new double[] { 1.0 2.0 3.0 4.0 } };
Combining multiple filters in a single query¶
If you want to apply multiple filters in a single query, you can combine the individual filter object arrays into one larger object array.
For example,
parameters["applyFilter"] = new object[]
{
new object[] { "in".ToCharArray(), "OrderID", new double[] { 1.0 2.0 3.0 4.0 } },
new object[] { "in".ToCharArray(), "EventTypeCode", new String[] { "abcd", "efgh"} },
new object[] { "<=".ToCharArray(), "OrderID", 2000 }
};
Performance considerations¶
For important things to consider when using the applyFilter parameter see here