Home › Forums › kdb+ › Using the partition type as a parameter › Reply To: Using the partition type as a parameter
-
It is advised to avoid using name of column or globals as function param names as much as possible. Here you are seeing issues as a result of this.
In a HDB the issues caused by this scoping confusion can differ from in memory tables.
This is due to map-reduce in the HDB, which means the query execution path is more complicated.
1. type error:
In the query path date would be expected to be a list but if the function local date atom is used a type error is being raised
q){[date] select cnt:count i from Orders where date=2024.07.15}[.z.d] //Error
q){[] select cnt:count i from Orders where date=2024.07.15}[.z.d] //Okay
2. count = 0:
You enlist the data param in one of the uses which means = returns a list and does not get the type error of query 1. However this list value does not make sense so an unexpected value is returned.
Returns the count of the table in the first partition of the HDB
q){[date] select cnt:count i from Orders where date=enlist 2024.07.15}[2024.07.15]
Same result
q){[date] select cnt:count i from Orders where date=2024.07.15}[enlist 2024.07.15]
Returns the counts of the first 2 partitions
q){[date] select cnt:{enlist count x}i from Orders where date=.z.d}[2#.z.d]
You don’t even need to put in dates as the date param is being compared to itself you can put anything in:
q){[date] select cnt:{enlist count x}i from Orders where date=1b}[11b]
3. Works: Not using date as a param name – no issues