feat(chalice): search sessions by session-attributes as global properties
This commit is contained in:
parent
fb9005d20d
commit
71f6858662
2 changed files with 22 additions and 1 deletions
|
|
@ -430,7 +430,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
||||||
is_not = False
|
is_not = False
|
||||||
if sh.is_negation_operator(f.operator):
|
if sh.is_negation_operator(f.operator):
|
||||||
is_not = True
|
is_not = True
|
||||||
if not f.is_predefined:
|
if f.is_property:
|
||||||
cast = get_col_cast(data_type=f.data_type, value=f.value)
|
cast = get_col_cast(data_type=f.data_type, value=f.value)
|
||||||
if is_any:
|
if is_any:
|
||||||
global_properties.append(f'isNotNull(e.properties.`{f.type}`)')
|
global_properties.append(f'isNotNull(e.properties.`{f.type}`)')
|
||||||
|
|
@ -573,6 +573,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
||||||
sh.multi_conditions(f"ms.base_referrer {op} toString(%({f_k})s)", f.value, is_not=is_not,
|
sh.multi_conditions(f"ms.base_referrer {op} toString(%({f_k})s)", f.value, is_not=is_not,
|
||||||
value_key=f_k))
|
value_key=f_k))
|
||||||
elif filter_type == schemas.FilterType.METADATA:
|
elif filter_type == schemas.FilterType.METADATA:
|
||||||
|
# to support old metadata-filter structure
|
||||||
# get metadata list only if you need it
|
# get metadata list only if you need it
|
||||||
if meta_keys is None:
|
if meta_keys is None:
|
||||||
meta_keys = metadata.get(project_id=project_id)
|
meta_keys = metadata.get(project_id=project_id)
|
||||||
|
|
@ -593,6 +594,23 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
||||||
sh.multi_conditions(
|
sh.multi_conditions(
|
||||||
f"ms.{metadata.index_to_colname(meta_keys[f.source])} {op} toString(%({f_k})s)",
|
f"ms.{metadata.index_to_colname(meta_keys[f.source])} {op} toString(%({f_k})s)",
|
||||||
f.value, is_not=is_not, value_key=f_k))
|
f.value, is_not=is_not, value_key=f_k))
|
||||||
|
elif filter_type.startswith(schemas.FilterType.METADATA):
|
||||||
|
# to support new metadata-filter structure
|
||||||
|
|
||||||
|
if is_any:
|
||||||
|
extra_constraints.append(f"isNotNull(s.{filter_type})")
|
||||||
|
ss_constraints.append(f"isNotNull(ms.{filter_type})")
|
||||||
|
elif is_undefined:
|
||||||
|
extra_constraints.append(f"isNull(s.{filter_type})")
|
||||||
|
ss_constraints.append(f"isNull(ms.{filter_type})")
|
||||||
|
else:
|
||||||
|
extra_constraints.append(
|
||||||
|
sh.multi_conditions(f"s.{filter_type} {op} toString(%({f_k})s)",
|
||||||
|
f.value, is_not=is_not, value_key=f_k))
|
||||||
|
ss_constraints.append(
|
||||||
|
sh.multi_conditions(f"ms.{filter_type} {op} toString(%({f_k})s)",
|
||||||
|
f.value, is_not=is_not, value_key=f_k))
|
||||||
|
|
||||||
elif filter_type in [schemas.FilterType.USER_ID, schemas.FilterType.USER_ID_MOBILE]:
|
elif filter_type in [schemas.FilterType.USER_ID, schemas.FilterType.USER_ID_MOBILE]:
|
||||||
if is_any:
|
if is_any:
|
||||||
extra_constraints.append('isNotNull(s.user_id)')
|
extra_constraints.append('isNotNull(s.user_id)')
|
||||||
|
|
|
||||||
|
|
@ -687,6 +687,9 @@ class SessionSearchFilterSchema(BaseModel):
|
||||||
source: Optional[Union[ErrorSource, str]] = Field(default=None)
|
source: Optional[Union[ErrorSource, str]] = Field(default=None)
|
||||||
# used for global-properties
|
# used for global-properties
|
||||||
data_type: Optional[PropertyType] = Field(default=PropertyType.STRING.value)
|
data_type: Optional[PropertyType] = Field(default=PropertyType.STRING.value)
|
||||||
|
# used to tell if the current filter is predefined or user-property having the same name
|
||||||
|
# used in case the user sends a property with the same name aas a predefined property
|
||||||
|
is_property: Optional[bool] = Field(default=False)
|
||||||
|
|
||||||
_remove_duplicate_values = field_validator('value', mode='before')(remove_duplicate_values)
|
_remove_duplicate_values = field_validator('value', mode='before')(remove_duplicate_values)
|
||||||
_single_to_list_values = field_validator('value', mode='before')(single_to_list)
|
_single_to_list_values = field_validator('value', mode='before')(single_to_list)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue