|
| 1 | +# Saved SQL filter compatibility and conversion |
| 2 | + |
| 3 | +Dataset-scoped SQL filters and upstream SQL filters using `stream_name: "sql"` |
| 4 | +are both supported. Existing views are not automatically converted. New native |
| 5 | +Logs views keep their dataset-scoped format until the owner chooses **Convert to |
| 6 | +SQL view** in Saved views. Converted views still open in the original dataset; |
| 7 | +`explorer_state` retains their dataset, query controls, time range and display |
| 8 | +settings. Editing a converted view keeps it converted. |
| 9 | + |
| 10 | +The native explorer reads both formats. Classic filters without native explorer |
| 11 | +state remain visible under their original dataset, but cannot be opened or |
| 12 | +converted by the native explorer. The literal `sql` is a reserved dataset name, |
| 13 | +so it cannot collide with a user-created dataset. |
| 14 | + |
| 15 | +## Backend operation |
| 16 | + |
| 17 | +``` |
| 18 | +POST /api/v1/filters/{filter_id}/convert-to-sql |
| 19 | +``` |
| 20 | + |
| 21 | +The endpoint takes no JSON payload and returns the complete saved filter. It |
| 22 | +requires filter-update permission and an owner-or-admin check. Only SQL filters |
| 23 | +can be converted. The server copies the authorized stored record, preserving |
| 24 | +its ID, owner, query, time filter and extra metadata. Repeating the request is |
| 25 | +safe, including after an interrupted cleanup. Admin updates also preserve the |
| 26 | +original owner. |
| 27 | + |
| 28 | +Ordinary create and update requests accept a valid dataset name or, for SQL |
| 29 | +filters only, the literal `sql`. Path-like names remain invalid. A stale client |
| 30 | +cannot turn a converted SQL filter back into a dataset-scoped one by sending its |
| 31 | +old stream name. |
| 32 | + |
| 33 | +## Reconciliation and recovery |
| 34 | + |
| 35 | +Persistence uses `users/<owner>/filters/<stream>/<id>.json`. Conversion writes |
| 36 | +the `sql` copy first, updates the server cache, then removes obsolete copies of |
| 37 | +the same owner's filter ID. Cleanup failure returns an error, while the durable |
| 38 | +new copy remains available for retry. Deletion removes aliases before the |
| 39 | +current copy, so a successful deletion cannot leave an older copy to return on |
| 40 | +restart. |
| 41 | + |
| 42 | +Startup reconciliation groups records by owner and ID within each tenant. When |
| 43 | +both canonical SQL and legacy SQL copies exist, it deterministically keeps the |
| 44 | +canonical copy and removes obsolete SQL copies. A legacy record with no |
| 45 | +canonical copy is left in its existing format. Ambiguous legacy-only duplicates |
| 46 | +are selected deterministically without deleting the alternatives. Cleanup |
| 47 | +failures are logged and can be retried on the next startup or conversion; there |
| 48 | +is no one-time completion flag that could hide unfinished work. |
| 49 | + |
| 50 | +Older administrator edits could also leave the same filter ID under different |
| 51 | +owners. These records are retained independently. Each owner, including an |
| 52 | +administrator, can manage their own copy; an administrator without a copy can |
| 53 | +manage another owner's record only when the ID is unambiguous. The native |
| 54 | +Saved views selector distinguishes the owners' copies. |
| 55 | + |
| 56 | +A process-wide async lock serializes filter persistence and cache changes. |
| 57 | +This follows the existing single-query-server ownership model: it is not a |
| 58 | +distributed lock, and concurrent writes through multiple independent query |
| 59 | +servers sharing the same metastore are not coordinated by this change. |
| 60 | + |
| 61 | +Before a rollout, back up stored filter metadata and verify a legacy view can |
| 62 | +be opened, converted, edited, restarted and deleted without reappearing. A |
| 63 | +rollback to an older native UI will hide converted views because that UI only |
| 64 | +understands dataset-scoped records; keep this compatible UI when rolling back |
| 65 | +other changes. Conversion does not change log data or delete datasets. |
| 66 | + |
| 67 | +## Regression checks |
| 68 | + |
| 69 | +Run the isolated HTTP/restart smoke test against a newly built server: |
| 70 | + |
| 71 | +```sh |
| 72 | +PARSEABLE_BIN=/absolute/path/to/parseable python3 scripts/test-sql-filter-conversion.py |
| 73 | +``` |
| 74 | + |
| 75 | +It starts its own local-store process and temporary data directories; it does not |
| 76 | +contact an existing deployment. The fixture checks owner authorization, admin |
| 77 | +updates, conversion retries, stale-client edits, startup cleanup of an injected |
| 78 | +legacy duplicate, and delete followed by restart. Rust metastore tests also |
| 79 | +exercise cleanup failures, tenant isolation, and ambiguous legacy records. |
0 commit comments