-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: log entries hogql * idiot fix * more like Java * fix * Update query snapshots --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ac6c0c3
commit 4ecfb63
Showing
3 changed files
with
242 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from typing import Dict, List | ||
|
||
from posthog.hogql import ast | ||
from posthog.hogql.database.models import ( | ||
Table, | ||
IntegerDatabaseField, | ||
StringDatabaseField, | ||
DateTimeDatabaseField, | ||
LazyTable, | ||
FieldOrTable, | ||
) | ||
|
||
LOG_ENTRIES_FIELDS: Dict[str, FieldOrTable] = { | ||
"team_id": IntegerDatabaseField(name="team_id"), | ||
"log_source": StringDatabaseField(name="log_source"), | ||
"log_source_id": StringDatabaseField(name="log_source_id"), | ||
"instance_id": StringDatabaseField(name="instance_id"), | ||
"timestamp": DateTimeDatabaseField(name="timestamp"), | ||
"message": StringDatabaseField(name="message"), | ||
"level": StringDatabaseField(name="level"), | ||
} | ||
|
||
|
||
class LogEntriesTable(Table): | ||
fields: Dict[str, FieldOrTable] = LOG_ENTRIES_FIELDS | ||
|
||
def to_printed_clickhouse(self, context): | ||
return "log_entries" | ||
|
||
def to_printed_hogql(self): | ||
return "log_entries" | ||
|
||
|
||
class ReplayConsoleLogsLogEntriesTable(LazyTable): | ||
fields: Dict[str, FieldOrTable] = LOG_ENTRIES_FIELDS | ||
|
||
def lazy_select(self, requested_fields: Dict[str, List[str]]): | ||
fields: List[ast.Expr] = [ast.Field(chain=["log_entries"] + chain) for name, chain in requested_fields.items()] | ||
|
||
return ast.SelectQuery( | ||
select=fields, | ||
select_from=ast.JoinExpr(table=ast.Field(chain=["log_entries"])), | ||
where=ast.CompareOperation( | ||
op=ast.CompareOperationOp.Eq, | ||
left=ast.Field(chain=["log_entries", "log_source"]), | ||
right=ast.Constant(value="session_replay"), | ||
), | ||
) | ||
|
||
def to_printed_clickhouse(self, context): | ||
return "console_logs_log_entries" | ||
|
||
def to_printed_hogql(self): | ||
return "console_logs_log_entries" | ||
|
||
|
||
class BatchExportLogEntriesTable(LazyTable): | ||
fields: Dict[str, FieldOrTable] = LOG_ENTRIES_FIELDS | ||
|
||
def lazy_select(self, requested_fields: Dict[str, List[str]]): | ||
fields: List[ast.Expr] = [ast.Field(chain=["log_entries"] + chain) for name, chain in requested_fields.items()] | ||
|
||
return ast.SelectQuery( | ||
select=fields, | ||
select_from=ast.JoinExpr(table=ast.Field(chain=["log_entries"])), | ||
where=ast.CompareOperation( | ||
op=ast.CompareOperationOp.Eq, | ||
left=ast.Field(chain=["log_entries", "log_source"]), | ||
right=ast.Constant(value="batch_export"), | ||
), | ||
) | ||
|
||
def to_printed_clickhouse(self, context): | ||
return "batch_export_log_entries" | ||
|
||
def to_printed_hogql(self): | ||
return "batch_export_log_entries" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters