| 123456789101112131415161718192021222324252627282930313233343536 |
- """Exact text-number comparison for query filtering and indexed ordering."""
- _parse_number = None
- def number(value):
- # Lazy import avoids objects -> index helpers -> customs -> storage cycles.
- global _parse_number
- if _parse_number is None:
- from .customs.engine.numbers import number as parser
- _parse_number = parser
- return _parse_number(value)
- CALENDAR = {'YEAR','WEEK','年度','月度','ISO年','ISO周','归属年','归属月','选样年度','排名','记录数'}
- def decimal_compare(a,b):
- left,right=number(a),number(b)
- if left is None or right is None:return None
- return (left>right)-(left<right)
- def decimal_collation(a,b):
- left,right=number(a),number(b)
- if left is None or right is None:
- if left is None and right is None:return (a>b)-(a<b)
- return -1 if left is None else 1
- return (left>right)-(left<right)
- def register_precision(db):
- db.create_function('decimal_cmp',2,decimal_compare,deterministic=True)
- db.create_collation('DECIMAL_VALUE',decimal_collation)
- def numeric_field(column):
- return column in {'MONORSUM','MONORSUM_USD','COUNT','amount','quantity'} or any(k in column for k in ('金额','数量','单价','价格','指数','占比','环比','权重'))
|