Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(errors): Add YAML definitions for new features columns #6724

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ query_processors:
hash_map_name: _tags_hash_map
killswitch: tags_hash_map_enabled
- processor: EmptyTagConditionProcessor
args:
column_name: tags.key
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: tags
Expand Down
58 changes: 58 additions & 0 deletions snuba/datasets/configuration/events/entities/events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ schema:
inner_type: { type: UInt, args: { size: 64 } },
},
},
{
name: features,
type: Nested,
args:
{
subcolumns:
[{ name: key, type: String }, { name: value, type: String }],
},
},
{
name: _features_hash_map,
type: Array,
args:
{
schema_modifiers: [readonly],
inner_type: { type: UInt, args: { size: 64 } },
},
},
{
name: contexts,
type: Nested,
Expand Down Expand Up @@ -297,6 +315,18 @@ storages:
from_col_name: tags_value
to_function_name: arrayJoin
to_function_column: tags.value
- mapper: ColumnToFunctionOnColumn
args:
from_table_name: null
from_col_name: features_key
to_function_name: arrayJoin
to_function_column: features.key
- mapper: ColumnToFunctionOnColumn
args:
from_table_name: null
from_col_name: features_value
to_function_name: arrayJoin
to_function_column: features.value
subscriptables:
- mapper: SubscriptableMapper
args:
Expand All @@ -314,6 +344,14 @@ storages:
to_nested_col_name: contexts
value_subcolumn_name: value
nullable: false
- mapper: SubscriptableMapper
args:
from_column_table: null
from_column_name: features
to_nested_col_table: null
to_nested_col_name: features
value_subcolumn_name: value
nullable: false
- storage: errors
is_writable: true
translation_mappers:
Expand Down Expand Up @@ -408,6 +446,18 @@ storages:
from_col_name: tags_value
to_function_name: arrayJoin
to_function_column: tags.value
- mapper: ColumnToFunctionOnColumn
args:
from_table_name: null
from_col_name: features_key
to_function_name: arrayJoin
to_function_column: features.key
- mapper: ColumnToFunctionOnColumn
args:
from_table_name: null
from_col_name: features_value
to_function_name: arrayJoin
to_function_column: features.value
subscriptables:
- mapper: SubscriptableMapper
args:
Expand All @@ -425,6 +475,14 @@ storages:
to_nested_col_name: contexts
value_subcolumn_name: value
nullable: false
- mapper: SubscriptableMapper
args:
from_column_table: null
from_column_name: features
to_nested_col_table: null
to_nested_col_name: features
value_subcolumn_name: value
nullable: false
storage_selector:
selector: ErrorsQueryStorageSelector
query_processors:
Expand Down
31 changes: 31 additions & 0 deletions snuba/datasets/configuration/events/storages/errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ schema:
inner_type: { type: UInt, args: { size: 64 } },
},
},
{
name: features,
type: Nested,
args:
{
subcolumns:
[{ name: key, type: String }, { name: value, type: String }],
},
},
{
name: _features_hash_map,
type: Array,
args:
{
schema_modifiers: [readonly],
inner_type: { type: UInt, args: { size: 64 } },
},
},
{
name: contexts,
type: Nested,
Expand Down Expand Up @@ -310,10 +328,23 @@ query_processors:
column_name: tags
hash_map_name: _tags_hash_map
killswitch: events_tags_hash_map_enabled
- processor: MappingOptimizer
args:
column_name: features
hash_map_name: _features_hash_map
killswitch: events_features_hash_map_enabled
- processor: EmptyTagConditionProcessor
args:
column_name: tags.key.key
- processor: EmptyTagConditionProcessor
args:
column_name: features.key
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: tags
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: features
- processor: PrewhereProcessor
args:
omit_if_final:
Expand Down
28 changes: 28 additions & 0 deletions snuba/datasets/configuration/events/storages/errors_ro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ schema:
inner_type: { type: UInt, args: { size: 64 } },
},
},
{
name: features,
type: Nested,
args:
{
subcolumns:
[{ name: key, type: String }, { name: value, type: String }],
},
},
{
name: _features_hash_map,
type: Array,
args:
{
schema_modifiers: [readonly],
inner_type: { type: UInt, args: { size: 64 } },
},
},
{
name: contexts,
type: Nested,
Expand Down Expand Up @@ -306,10 +324,20 @@ query_processors:
column_name: tags
hash_map_name: _tags_hash_map
killswitch: events_tags_hash_map_enabled
- processor: MappingOptimizer
args:
column_name: features
hash_map_name: _features_hash_map
killswitch: events_features_hash_map_enabled
- processor: EmptyTagConditionProcessor
args:
column_name: tags.key
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: tags
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: features
- processor: PrewhereProcessor
args:
omit_if_final:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ query_processors:
hash_map_name: _tags_hash_map
killswitch: tags_hash_map_enabled
- processor: EmptyTagConditionProcessor
args:
column_name: tags.key
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: tags
Expand Down
2 changes: 2 additions & 0 deletions snuba/datasets/configuration/replays/storages/replays.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ query_processors:
hash_map_name: _tags_hash_map
killswitch: tags_hash_map_enabled
- processor: EmptyTagConditionProcessor
args:
column_name: tags.key
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: tags
Expand Down
2 changes: 2 additions & 0 deletions snuba/datasets/configuration/spans/storages/spans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ query_processors:
hash_map_name: _measurements_hash_map
killswitch: measurements_hash_map_enabled
- processor: EmptyTagConditionProcessor
args:
column_name: tags.key
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ query_processors:
hash_map_name: _tags_hash_map
killswitch: tags_hash_map_enabled
- processor: EmptyTagConditionProcessor
args:
column_name: tags.key
- processor: ArrayJoinKeyValueOptimizer
args:
column_name: tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ class EmptyTagConditionProcessor(ClickhouseQueryProcessor):
the `has` function.
"""

def __init__(self, column_name: str) -> None:
self.column_name = column_name

def process_query(self, query: Query, query_settings: QuerySettings) -> None:
def process_condition(exp: Expression) -> Expression:
result = CONDITION_PATTERN.match(exp)
if result is not None:
key_column = result.optional_string(KEY_COL_MAPPING_PARAM)
if key_column == "tags.key":
if key_column == self.column_name:
rhs = result.optional_string(KEY_MAPPING_PARAM)
table_name = result.optional_string(TABLE_MAPPING_PARAM)
replacement = FunctionCall(
exp.alias,
"has",
(Column(None, table_name, "tags.key"), Literal(None, rhs)),
(
Column(None, table_name, self.column_name),
Literal(None, rhs),
),
)

assert isinstance(exp, FunctionCall)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,12 @@ def test_useless_has_condition(

# change the existence expression to be a has(tags, 'my_tag') expression for boh queries
# this allows reuse of the previous test cases
EmptyTagConditionProcessor().process_query(input_query, HTTPQuerySettings())
EmptyTagConditionProcessor().process_query(expected_query, HTTPQuerySettings())
EmptyTagConditionProcessor("tags.key").process_query(
input_query, HTTPQuerySettings()
)
EmptyTagConditionProcessor("tags.key").process_query(
expected_query, HTTPQuerySettings()
)

MappingOptimizer(
column_name="tags",
Expand Down
Loading