def attempt_map( self, expression: SubscriptableReference, children_translator: SnubaClickhouseStrictTranslator, ) -> Optional[FunctionCall]: if expression.column.column_name in self.subscript_names: return identity(Literal(None, None), expression.alias) else: return None
def attempt_map( self, expression: FunctionCall, children_translator: SnubaClickhouseStrictTranslator, ) -> Optional[FunctionCall]: if self.function_match.match(expression): return identity(Literal(None, None), expression.alias) return None
def attempt_map( self, expression: Column, children_translator: SnubaClickhouseStrictTranslator, ) -> Optional[FunctionCall]: if expression.column_name in self.columns: return identity( Literal(None, None), expression.alias or qualified_column( expression.column_name, expression.table_name or ""), ) else: return None
def attempt_map( self, expression: FunctionCall, children_translator: SnubaClickhouseStrictTranslator, ) -> Optional[FunctionCall]: parameters = tuple( p.accept(children_translator) for p in expression.parameters) for param in parameters: # All impossible columns will have been converted to the identity function. # So we know that if a function has the identity function as a parameter, we can # collapse the entire expression. fmatch = self.function_match.match(param) if fmatch is not None: return identity(Literal(None, None), expression.alias) return None
def attempt_map( self, expression: CurriedFunctionCall, children_translator: SnubaClickhouseStrictTranslator, ) -> Optional[Union[CurriedFunctionCall, FunctionCall]]: internal_function = expression.internal_function.accept( children_translator) assert isinstance(internal_function, FunctionCall) # mypy parameters = tuple( p.accept(children_translator) for p in expression.parameters) for param in parameters: # All impossible columns that have been converted to NULL will be the identity function. # So we know that if a function has the identity function as a parameter, we can # collapse the entire expression. fmatch = self.function_match.match(param) if fmatch is not None: return identity(Literal(None, None), expression.alias) return None
def attempt_map( self, expression: FunctionCall, children_translator: SnubaClickhouseStrictTranslator, ) -> Optional[FunctionCall]: # HACK: Quick fix to avoid this function dropping important conditions from the query logical_functions = {"and", "or", "xor"} if expression.function_name in logical_functions: return None parameters = tuple( p.accept(children_translator) for p in expression.parameters) for param in parameters: # All impossible columns will have been converted to the identity function. # So we know that if a function has the identity function as a parameter, we can # collapse the entire expression. fmatch = self.function_match.match(param) if fmatch is not None: return identity(Literal(None, None), expression.alias) return None
Column, CurriedFunctionCall, Expression, FunctionCall, Literal, ) test_data = [ pytest.param( Column(None, None, "group_id"), Literal(None, 0), id="basic column translation", ), pytest.param( Column(None, None, "primary_hash"), identity(Literal(None, None), "primary_hash"), id="basic event translation", ), pytest.param( FunctionCall(None, "isHandled", (Literal(None, 1), )), identity(Literal(None, None), None), id="none function mapper", ), pytest.param( FunctionCall("alias", "foo", (Column(None, None, "primary_hash"), )), identity(Literal(None, None), "alias"), id="if null function mapper", ), pytest.param( FunctionCall( "alias",