Skip to content

Commit e6d4620

Browse files
authored
Merge branch 'main' into refactor/planner-native-records
2 parents 713ace3 + 5c70edd commit e6d4620

106 files changed

Lines changed: 4653 additions & 547 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/sqlbuild-cli/src/argv/command_table.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6853,6 +6853,7 @@
68536853
"json",
68546854
"csv"
68556855
],
6856+
"help": "long (default) for reading, json for programs, csv for export; table is deprecated",
68566857
"mutex_group": 0,
68576858
"group": 1
68586859
},
@@ -7017,6 +7018,19 @@
70177018
"help": "with --backend warehouse, describe one relation",
70187019
"group": 1
70197020
},
7021+
{
7022+
"kind": "store_true",
7023+
"options": [
7024+
"--ddl"
7025+
],
7026+
"dest": "recall_ddl",
7027+
"nargs": 0,
7028+
"const": true,
7029+
"default": false,
7030+
"help": "print the SQL that creates the Recall store or brings it up to this version",
7031+
"mutex_group": 0,
7032+
"group": 1
7033+
},
70207034
{
70217035
"kind": "store",
70227036
"options": [
@@ -7030,6 +7044,7 @@
70307044
"json",
70317045
"csv"
70327046
],
7047+
"help": "long (default) for reading, json for programs, csv for export; table is deprecated",
70337048
"mutex_group": 0,
70347049
"group": 1
70357050
},

‎crates/sqlbuild-cli/src/argv/constants.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(crate) const INT_CONVERTER: &str = "int";
6363
pub(crate) const PATH_CONVERTER: &str = "Path";
6464

6565
/// Every `CliNamespace` attribute with a default, in declaration order.
66-
pub(crate) const CLI_NAMESPACE_DEFAULTS: [(&str, NamespaceDefault); 176] = [
66+
pub(crate) const CLI_NAMESPACE_DEFAULTS: [(&str, NamespaceDefault); 177] = [
6767
("command", NamespaceDefault::None),
6868
("project_dir", NamespaceDefault::None),
6969
("dbt_project_dir", NamespaceDefault::None),
@@ -221,6 +221,7 @@ pub(crate) const CLI_NAMESPACE_DEFAULTS: [(&str, NamespaceDefault); 176] = [
221221
("recall_max_cell_bytes", NamespaceDefault::None),
222222
("recall_state", NamespaceDefault::Bool(false)),
223223
("recall_relation", NamespaceDefault::None),
224+
("recall_ddl", NamespaceDefault::Bool(false)),
224225
("recall_invocation", NamespaceDefault::Text("last")),
225226
("recall_stream", NamespaceDefault::Text("combined")),
226227
("recall_tail", NamespaceDefault::None),

‎crates/sqlbuild-cli/src/dispatch/constants.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ pub(crate) const QUERY_ROUTE: Route = routed(
420420
},
421421
);
422422

423-
const RECALL_ARGUMENTS: [Field; 13] = [
423+
const RECALL_ARGUMENTS: [Field; 14] = [
424424
PROJECT_DIR,
425425
SELECTED_TARGET,
426426
same("recall_command"),
@@ -434,6 +434,7 @@ const RECALL_ARGUMENTS: [Field; 13] = [
434434
attr("invocation", "recall_invocation"),
435435
attr("stream", "recall_stream"),
436436
attr("tail", "recall_tail"),
437+
attr("ddl", "recall_ddl"),
437438
];
438439
pub(crate) const RECALL_ROUTE: Route = routed(
439440
"run_recall",

‎crates/sqlbuild-cli/src/dispatch/main/invocation_policy.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ use crate::dispatch::constants::{
66
};
77
use crate::dispatch::models::{CommandFacts, InvocationPolicy};
88

9-
/// Whether the command creates a project, is observed, checks skill freshness and is recorded; only observed commands are recorded, so every recorded invocation has terminal events.
9+
/// Whether the command creates a project, is observed, checks skill freshness, is recorded and has its streams captured; only observed commands are recorded, so every recorded invocation has terminal events. `sqb recall` only reads history, so it publishes no lifecycle events, runs no sinks and keeps no compute logs.
1010
#[must_use]
1111
pub fn invocation_policy(facts: &CommandFacts) -> InvocationPolicy {
1212
let command: &str = facts.command.as_deref().unwrap_or_default();
1313
let creates_project: bool = PROJECT_CREATING_COMMANDS.contains(&command)
1414
|| (command == DBT_COMMAND_NAME
1515
&& facts.subcommand.as_deref() == Some(DBT_INIT_SUBCOMMAND));
1616
let raw_query_diff: bool = command == DIFF_COMMAND_NAME && facts.raw_query_diff;
17-
let observed: bool = !creates_project && !raw_query_diff;
17+
let reads_history: bool = command == RECALL_COMMAND_NAME;
18+
let observed: bool = !creates_project && !raw_query_diff && !reads_history;
1819
InvocationPolicy {
1920
creates_project,
2021
observed,
2122
maintains_skills: !SKILL_EXEMPT_COMMANDS.contains(&command) && !raw_query_diff,
22-
recalled: observed && !command.is_empty() && command != RECALL_COMMAND_NAME,
23+
recalled: observed && !command.is_empty(),
24+
captured: !creates_project && !reads_history,
2325
}
2426
}

‎crates/sqlbuild-cli/src/dispatch/models.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub struct InvocationPolicy {
121121
pub maintains_skills: bool,
122122
/// Whether Recall records the invocation; `sqb recall` never records itself.
123123
pub recalled: bool,
124+
/// Whether compute logs capture the process streams; read-only `sqb recall` skips them.
125+
pub captured: bool,
124126
}
125127

126128
/// What a failed command reports: its fallback error code and the debug log message.

‎crates/sqlbuild-cli/src/dispatch/tests/test_invocation_policy.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn given_parsed_command_when_choosing_services_then_matches_python_entry_rules()
1414
observed: true,
1515
maintains_skills: true,
1616
recalled: true,
17+
captured: true,
1718
},
1819
},
1920
InvocationPolicyTestCase {
@@ -24,6 +25,7 @@ fn given_parsed_command_when_choosing_services_then_matches_python_entry_rules()
2425
observed: false,
2526
maintains_skills: true,
2627
recalled: false,
28+
captured: false,
2729
},
2830
},
2931
InvocationPolicyTestCase {
@@ -34,6 +36,7 @@ fn given_parsed_command_when_choosing_services_then_matches_python_entry_rules()
3436
observed: false,
3537
maintains_skills: false,
3638
recalled: false,
39+
captured: false,
3740
},
3841
},
3942
InvocationPolicyTestCase {
@@ -47,16 +50,18 @@ fn given_parsed_command_when_choosing_services_then_matches_python_entry_rules()
4750
observed: false,
4851
maintains_skills: false,
4952
recalled: false,
53+
captured: true,
5054
},
5155
},
5256
InvocationPolicyTestCase {
53-
description: "recall reads history and is never recorded itself",
57+
description: "recall only reads history: no events, sinks, recording or compute logs",
5458
facts: facts("recall", Some("query")),
5559
expected_policy: InvocationPolicy {
5660
creates_project: false,
57-
observed: true,
61+
observed: false,
5862
maintains_skills: true,
5963
recalled: false,
64+
captured: false,
6065
},
6166
},
6267
];

‎crates/sqlbuild-config/src/recall/constants.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
33
pub const RECALL_SECTION: &str = "recall";
44
/// Keys `[recall]` and `targets.<name>.recall` accept, sorted.
5-
pub const RECALL_KEYS: [&str; 6] = [
6-
"connection",
5+
pub const RECALL_KEYS: [&str; 7] = [
76
"diagnostics_min_severity",
87
"enabled",
98
"max_output_bytes",
9+
"read_connection",
1010
"retention",
1111
"shutdown_timeout",
12+
"write_connection",
1213
];
14+
/// The single store key `write_connection` and `read_connection` replaced.
15+
pub const REMOVED_CONNECTION_KEY: &str = "connection";
1316
/// The diagnostic severities a Recall store can keep from, least severe first.
1417
pub const RECALL_SEVERITIES: [&str; 6] = ["trace", "debug", "info", "warning", "error", "critical"];
1518
/// The longest shutdown flush budget, in milliseconds.

‎crates/sqlbuild-config/src/recall/main/recall_section.rs‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
use crate::models::ConfigValue;
44
use crate::recall::_helpers::values::{non_empty, output_bytes, retention_days, timeout_ms};
5-
use crate::recall::constants::{MAX_RETENTION_DAYS, RECALL_KEYS, RECALL_SEVERITIES};
5+
use crate::recall::constants::{
6+
MAX_RETENTION_DAYS, RECALL_KEYS, RECALL_SEVERITIES, REMOVED_CONNECTION_KEY,
7+
};
68
use crate::recall::models::RecallSection;
79

810
/// The settings of `value`, or the message naming its first problem at `label`.
@@ -20,7 +22,13 @@ pub fn recall_section(value: &ConfigValue, label: &str) -> Result<RecallSection,
2022
ConfigValue::Bool(flag) => section.enabled = Some(*flag),
2123
_ => return Err(format!("{label}.enabled must be true or false")),
2224
},
23-
"connection" => section.connection = Some(non_empty(value, label, key)?.to_owned()),
25+
"write_connection" => {
26+
section.write_connection = Some(non_empty(value, label, key)?.to_owned());
27+
}
28+
"read_connection" => {
29+
section.read_connection = Some(non_empty(value, label, key)?.to_owned());
30+
}
31+
REMOVED_CONNECTION_KEY => return Err(removed_connection(value, label)),
2432
"retention" => {
2533
let text = non_empty(value, label, key)?;
2634
section.retention_days = Some(retention_days(text).ok_or_else(|| {
@@ -67,3 +75,17 @@ pub fn recall_section(value: &ConfigValue, label: &str) -> Result<RecallSection,
6775
}
6876
Ok(section)
6977
}
78+
79+
/// The message for the removed `connection` key, naming its replacements.
80+
fn removed_connection(value: &ConfigValue, label: &str) -> String {
81+
let name: String = match value {
82+
ConfigValue::String(name) if !name.trim().is_empty() => name.trim().to_owned(),
83+
_ => "<name>".to_owned(),
84+
};
85+
format!(
86+
"{label}.connection was replaced by write_connection and read_connection: set \
87+
write_connection = \"{name}\" and read_connection = \"{name}\" (or a separate \
88+
read-only connection), or only read_connection to read shared history while this \
89+
machine records to the local store"
90+
)
91+
}

‎crates/sqlbuild-config/src/recall/models.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#[derive(Clone, Debug, Default, PartialEq, Eq)]
55
pub struct RecallSection {
66
pub enabled: Option<bool>,
7-
pub connection: Option<String>,
7+
/// The connection every command writes its history to; the merged settings must also set `read_connection`.
8+
pub write_connection: Option<String>,
9+
/// The connection `sqb recall query`, `schema` and `output` read.
10+
pub read_connection: Option<String>,
811
pub retention_days: Option<u32>,
912
pub shutdown_timeout_ms: Option<u64>,
1013
pub diagnostics_min_severity: Option<String>,

‎crates/sqlbuild-config/src/recall/tests/test_recall_section.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,31 @@ fn given_valid_sections_when_validated_then_settings_are_typed() {
1111
description: "every key is typed and trimmed",
1212
value: table(&[
1313
("enabled", ConfigValue::Bool(false)),
14-
("connection", text(" history ")),
14+
("write_connection", text(" history_writer ")),
15+
("read_connection", text("history_reader")),
1516
("retention", text("720h")),
1617
("shutdown_timeout", text("1500ms")),
1718
("diagnostics_min_severity", text("debug")),
1819
("max_output_bytes", ConfigValue::Integer(4_194_304)),
1920
]),
2021
expected_section: RecallSection {
2122
enabled: Some(false),
22-
connection: Some("history".to_owned()),
23+
write_connection: Some("history_writer".to_owned()),
24+
read_connection: Some("history_reader".to_owned()),
2325
retention_days: Some(30),
2426
shutdown_timeout_ms: Some(1500),
2527
diagnostics_min_severity: Some("debug".to_owned()),
2628
max_output_bytes: Some(4_194_304),
2729
},
2830
},
31+
ValidSectionTestCase {
32+
description: "a read connection alone reads shared history",
33+
value: table(&[("read_connection", text("history_reader"))]),
34+
expected_section: RecallSection {
35+
read_connection: Some("history_reader".to_owned()),
36+
..RecallSection::default()
37+
},
38+
},
2939
ValidSectionTestCase {
3040
description: "zero output bytes means record everything",
3141
value: table(&[("max_output_bytes", ConfigValue::Integer(0))]),
@@ -66,6 +76,14 @@ fn given_invalid_sections_when_validated_then_the_message_names_the_key() {
6676
label: "recall",
6777
expected_message_prefix: "recall.max_output_bytes must be",
6878
},
79+
InvalidSectionTestCase {
80+
description: "the removed connection key names its replacements",
81+
value: table(&[("connection", text("history"))]),
82+
label: "targets.prod.recall",
83+
expected_message_prefix: "targets.prod.recall.connection was replaced by write_connection \
84+
and read_connection: set write_connection = \"history\" and \
85+
read_connection = \"history\"",
86+
},
6987
InvalidSectionTestCase {
7088
description: "unknown keys are listed",
7189
value: table(&[("mode", text("x"))]),

0 commit comments

Comments
 (0)