From b3c0653b252f10e19b0d789210310e3a73079a7b Mon Sep 17 00:00:00 2001 From: Karl Gutwin Date: Thu, 4 Jul 2024 10:49:57 -0400 Subject: [PATCH 1/5] Add 'prqlc debug json-schema' command --- Cargo.lock | 64 +++++++++++++++++++++++ Cargo.toml | 1 + prqlc/prqlc-parser/Cargo.toml | 1 + prqlc/prqlc-parser/src/generic.rs | 7 +-- prqlc/prqlc-parser/src/lexer/lr/token.rs | 12 +++-- prqlc/prqlc-parser/src/parser/pr/expr.rs | 24 +++++---- prqlc/prqlc-parser/src/parser/pr/ident.rs | 3 +- prqlc/prqlc-parser/src/parser/pr/ops.rs | 3 ++ prqlc/prqlc-parser/src/parser/pr/stmt.rs | 20 +++---- prqlc/prqlc-parser/src/parser/pr/types.rs | 11 ++-- prqlc/prqlc-parser/src/span.rs | 3 +- prqlc/prqlc/Cargo.toml | 1 + prqlc/prqlc/src/cli/mod.rs | 30 ++++++++++- prqlc/prqlc/src/ir/generic.rs | 9 ++-- prqlc/prqlc/src/ir/pl/expr.rs | 11 ++-- prqlc/prqlc/src/ir/pl/extra.rs | 11 ++-- prqlc/prqlc/src/ir/pl/lineage.rs | 7 +-- prqlc/prqlc/src/ir/pl/stmt.rs | 15 +++--- prqlc/prqlc/src/ir/rq/expr.rs | 10 ++-- prqlc/prqlc/src/ir/rq/ids.rs | 5 +- prqlc/prqlc/src/ir/rq/mod.rs | 18 ++++--- prqlc/prqlc/src/ir/rq/transform.rs | 9 ++-- prqlc/prqlc/src/semantic/reporting.rs | 5 +- 23 files changed, 199 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 927635522936..844ba26f0dc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1186,6 +1186,12 @@ dependencies = [ "strum 0.25.0", ] +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + [[package]] name = "either" version = "1.12.0" @@ -2875,6 +2881,7 @@ dependencies = [ "regex", "rstest", "rusqlite", + "schemars", "semver", "serde", "serde_json", @@ -2929,6 +2936,7 @@ dependencies = [ "insta", "itertools 0.13.0", "log", + "schemars", "semver", "serde", "serde_json", @@ -3144,6 +3152,26 @@ dependencies = [ "bitflags 2.5.0", ] +[[package]] +name = "ref-cast" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf0a6f84d5f1d581da8b41b47ec8600871962f2a528115b542b362d4b744931" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "regex" version = "1.10.5" @@ -3450,6 +3478,31 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "schemars" +version = "1.0.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec9b1e7918a904d86cb6de7147ff4da21f12ac1462c8049e12b30a8846f4699e" +dependencies = [ + "dyn-clone", + "ref-cast", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "1.0.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2730d5d2dbaf504ab238832cad00b0bdd727436583c7b05f9328e65fee2b475" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.68", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -3530,6 +3583,17 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "serde_json" version = "1.0.120" diff --git a/Cargo.toml b/Cargo.toml index 6105551559c5..b0b8d6a3f5fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ insta = {version = "1.39.0", features = ["colors", "glob", "yaml"]} insta-cmd = "0.6.0" itertools = "0.13.0" log = "0.4.22" +schemars = "1.0.0-alpha.2" semver = {version = "1.0.23", features = ["serde"]} serde = {version = "1.0.203", features = ["derive"]} serde_json = "1.0.120" diff --git a/prqlc/prqlc-parser/Cargo.toml b/prqlc/prqlc-parser/Cargo.toml index da8cc82830b6..2ebef88be120 100644 --- a/prqlc/prqlc-parser/Cargo.toml +++ b/prqlc/prqlc-parser/Cargo.toml @@ -16,6 +16,7 @@ doctest = false enum-as-inner = {workspace = true} itertools = {workspace = true} log = {workspace = true} +schemars = {workspace = true} semver = {version = "1.0.23", features = ["serde"]} serde = {workspace = true} serde_yaml = {workspace = true, optional = true} diff --git a/prqlc/prqlc-parser/src/generic.rs b/prqlc/prqlc-parser/src/generic.rs index 67838d19bcd8..aa1ab7745cb6 100644 --- a/prqlc/prqlc-parser/src/generic.rs +++ b/prqlc/prqlc-parser/src/generic.rs @@ -5,10 +5,11 @@ // could consider rolling back to only concrete implementations to delayer the // code. use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; /// Inclusive-inclusive range. /// Missing bound means unbounded range. -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] pub struct Range { pub start: Option, pub end: Option, @@ -37,7 +38,7 @@ impl Range { } } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub enum InterpolateItem { String(String), Expr { @@ -68,7 +69,7 @@ impl InterpolateItem { } } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub struct SwitchCase { pub condition: T, pub value: T, diff --git a/prqlc/prqlc-parser/src/lexer/lr/token.rs b/prqlc/prqlc-parser/src/lexer/lr/token.rs index 9062991190ac..c8518a87138d 100644 --- a/prqlc/prqlc-parser/src/lexer/lr/token.rs +++ b/prqlc/prqlc-parser/src/lexer/lr/token.rs @@ -1,13 +1,14 @@ use enum_as_inner::EnumAsInner; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; -#[derive(Clone, PartialEq, Serialize, Deserialize, Eq)] +#[derive(Clone, PartialEq, Serialize, Deserialize, Eq, JsonSchema)] pub struct Token { pub kind: TokenKind, pub span: std::ops::Range, } -#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, JsonSchema)] pub enum TokenKind { NewLine, @@ -15,7 +16,8 @@ pub enum TokenKind { Keyword(String), #[cfg_attr( feature = "serde_yaml", - serde(with = "serde_yaml::with::singleton_map") + serde(with = "serde_yaml::with::singleton_map"), + schemars(with = "Literal"), )] Literal(Literal), Param(String), @@ -64,7 +66,7 @@ pub enum TokenKind { LineWrap(Vec), } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr)] +#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema)] pub enum Literal { Null, Integer(i64), @@ -86,7 +88,7 @@ impl TokenKind { } } // Compound units, such as "2 days 3 hours" can be represented as `2days + 3hours` -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] pub struct ValueAndUnit { pub n: i64, // Do any DBs use floats or decimals for this? pub unit: String, // Could be an enum IntervalType, diff --git a/prqlc/prqlc-parser/src/parser/pr/expr.rs b/prqlc/prqlc-parser/src/parser/pr/expr.rs index 70fd7038647c..e44d1fd206a9 100644 --- a/prqlc/prqlc-parser/src/parser/pr/expr.rs +++ b/prqlc/prqlc-parser/src/parser/pr/expr.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use enum_as_inner::EnumAsInner; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use crate::generic; use crate::lexer::lr::Literal; @@ -23,7 +24,7 @@ impl Expr { /// Expr is anything that has a value and thus a type. /// Most of these can contain other [Expr] themselves; literals should be [ExprKind::Literal]. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct Expr { #[serde(flatten)] pub kind: ExprKind, @@ -35,7 +36,7 @@ pub struct Expr { pub alias: Option, } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr)] +#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema)] pub enum ExprKind { Ident(String), @@ -47,7 +48,8 @@ pub enum ExprKind { }, #[cfg_attr( feature = "serde_yaml", - serde(with = "serde_yaml::with::singleton_map") + serde(with = "serde_yaml::with::singleton_map"), + schemars(with = "Literal"), )] Literal(Literal), Pipeline(Pipeline), @@ -81,28 +83,28 @@ impl ExprKind { } } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub enum IndirectionKind { Name(String), Position(i64), Star, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct BinaryExpr { pub left: Box, pub op: BinOp, pub right: Box, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct UnaryExpr { pub op: UnOp, pub expr: Box, } /// Function call. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct FuncCall { pub name: Box, pub args: Vec, @@ -112,7 +114,7 @@ pub struct FuncCall { /// Function called with possibly missing positional arguments. /// May also contain environment that is needed to evaluate the body. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct Func { /// Type requirement for the function body expression. pub return_ty: Option, @@ -130,7 +132,7 @@ pub struct Func { pub generic_type_params: Vec, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct FuncParam { pub name: String, @@ -140,7 +142,7 @@ pub struct FuncParam { pub default_value: Option>, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct GenericTypeParam { /// Assigned name of this generic type argument. pub name: String, @@ -149,7 +151,7 @@ pub struct GenericTypeParam { } /// A value and a series of functions that are to be applied to that value one after another. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct Pipeline { pub exprs: Vec, } diff --git a/prqlc/prqlc-parser/src/parser/pr/ident.rs b/prqlc/prqlc-parser/src/parser/pr/ident.rs index cdbb18dc7cf9..655c107288c2 100644 --- a/prqlc/prqlc-parser/src/parser/pr/ident.rs +++ b/prqlc/prqlc-parser/src/parser/pr/ident.rs @@ -1,10 +1,11 @@ use std::fmt::Write; use serde::{ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer}; +use schemars::JsonSchema; /// A name. Generally columns, tables, functions, variables. /// This is glorified way of writing a "vec with at least one element". -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, JsonSchema)] pub struct Ident { pub path: Vec, pub name: String, diff --git a/prqlc/prqlc-parser/src/parser/pr/ops.rs b/prqlc/prqlc-parser/src/parser/pr/ops.rs index b41e65267ab9..fbe76133e19f 100644 --- a/prqlc/prqlc-parser/src/parser/pr/ops.rs +++ b/prqlc/prqlc-parser/src/parser/pr/ops.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; #[derive( Debug, @@ -11,6 +12,7 @@ use serde::{Deserialize, Serialize}; Deserialize, strum::Display, strum::EnumString, + JsonSchema, )] pub enum UnOp { #[strum(to_string = "-")] @@ -34,6 +36,7 @@ pub enum UnOp { Deserialize, strum::Display, strum::EnumString, + JsonSchema, )] pub enum BinOp { #[strum(to_string = "*")] diff --git a/prqlc/prqlc-parser/src/parser/pr/stmt.rs b/prqlc/prqlc-parser/src/parser/pr/stmt.rs index a4f1685ca37a..cbb887164884 100644 --- a/prqlc/prqlc-parser/src/parser/pr/stmt.rs +++ b/prqlc/prqlc-parser/src/parser/pr/stmt.rs @@ -3,19 +3,21 @@ use std::collections::HashMap; use enum_as_inner::EnumAsInner; use semver::VersionReq; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use crate::parser::pr::ident::Ident; use crate::parser::pr::{Expr, Ty}; use crate::span::Span; -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default, JsonSchema)] pub struct QueryDef { + #[schemars(with = "String")] pub version: Option, #[serde(default)] pub other: HashMap, } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub enum VarDefKind { Let, Into, @@ -24,7 +26,7 @@ pub enum VarDefKind { // The following code is tested by the tests_misc crate to match stmt.rs in prql_compiler. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct Stmt { #[serde(flatten)] pub kind: StmtKind, @@ -35,7 +37,7 @@ pub struct Stmt { pub annotations: Vec, } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub enum StmtKind { QueryDef(Box), VarDef(VarDef), @@ -44,7 +46,7 @@ pub enum StmtKind { ImportDef(ImportDef), } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct VarDef { pub kind: VarDefKind, pub name: String, @@ -54,25 +56,25 @@ pub struct VarDef { pub ty: Option, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct TypeDef { pub name: String, pub value: Option, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct ModuleDef { pub name: String, pub stmts: Vec, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct ImportDef { pub alias: Option, pub name: Ident, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct Annotation { pub expr: Box, } diff --git a/prqlc/prqlc-parser/src/parser/pr/types.rs b/prqlc/prqlc-parser/src/parser/pr/types.rs index 195a10892955..7519b89ff4a8 100644 --- a/prqlc/prqlc-parser/src/parser/pr/types.rs +++ b/prqlc/prqlc-parser/src/parser/pr/types.rs @@ -1,12 +1,13 @@ use enum_as_inner::EnumAsInner; use serde::{Deserialize, Serialize}; use strum::AsRefStr; +use schemars::JsonSchema; use crate::lexer::lr::Literal; use crate::parser::pr::ident::Ident; use crate::span::Span; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct Ty { pub kind: TyKind, @@ -16,7 +17,7 @@ pub struct Ty { pub name: Option, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner, AsRefStr)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner, AsRefStr, JsonSchema)] pub enum TyKind { /// Identifier that still needs to be resolved. Ident(Ident), @@ -60,7 +61,7 @@ impl TyKind { } } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner, JsonSchema)] pub enum TyTupleField { /// Named tuple element. Single(Option, Option), @@ -72,7 +73,7 @@ pub enum TyTupleField { /// Built-in sets. #[derive( - Debug, Clone, Serialize, Deserialize, PartialEq, Eq, strum::EnumString, strum::Display, + Debug, Clone, Serialize, Deserialize, PartialEq, Eq, strum::EnumString, strum::Display, JsonSchema, )] pub enum PrimitiveSet { #[strum(to_string = "int")] @@ -92,7 +93,7 @@ pub enum PrimitiveSet { } // Type of a function -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct TyFunc { pub name_hint: Option, pub params: Vec>, diff --git a/prqlc/prqlc-parser/src/span.rs b/prqlc/prqlc-parser/src/span.rs index 37f216239cdd..eebb81e67795 100644 --- a/prqlc/prqlc-parser/src/span.rs +++ b/prqlc/prqlc-parser/src/span.rs @@ -4,8 +4,9 @@ use std::ops::{Add, Range, Sub}; use chumsky::Stream; use serde::de::Visitor; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; -#[derive(Clone, PartialEq, Eq, Copy)] +#[derive(Clone, PartialEq, Eq, Copy, JsonSchema)] pub struct Span { pub start: usize, pub end: usize, diff --git a/prqlc/prqlc/Cargo.toml b/prqlc/prqlc/Cargo.toml index 431b20169e07..0599c992c02e 100644 --- a/prqlc/prqlc/Cargo.toml +++ b/prqlc/prqlc/Cargo.toml @@ -48,6 +48,7 @@ enum-as-inner = {workspace = true} itertools = {workspace = true} log = {workspace = true} regex = "1.10.5" +schemars = {workspace = true} semver = {workspace = true} # serde is required for the `from_text` feature of PRQL, so we can't really put # it behind a feature. diff --git a/prqlc/prqlc/src/cli/mod.rs b/prqlc/prqlc/src/cli/mod.rs index 030204ed694b..fbb7c3021d8f 100644 --- a/prqlc/prqlc/src/cli/mod.rs +++ b/prqlc/prqlc/src/cli/mod.rs @@ -7,7 +7,7 @@ mod watch; use std::collections::HashMap; use std::env; use std::fs::File; -use std::io::{BufWriter, Read, Write}; +use std::io::{self, BufWriter, Read, Write}; use std::ops::Range; use std::path::{Path, PathBuf}; use std::process::exit; @@ -24,12 +24,14 @@ use clio::has_extension; use clio::Output; use is_terminal::IsTerminal; use itertools::Itertools; +use schemars::schema_for; use prqlc::debug; use prqlc::internal::pl_to_lineage; -use prqlc::ir::pl; +use prqlc::ir::{pl, rq}; use prqlc::pr; use prqlc::semantic; +use prqlc::semantic::reporting::FrameCollector; use prqlc::{pl_to_prql, pl_to_rq_tree, prql_to_pl, prql_to_pl_tree, prql_to_tokens, rq_to_sql}; use prqlc::{Options, SourceTree, Target}; @@ -206,6 +208,12 @@ enum DebugCommand { /// Print info about the AST data structure Ast, + + /// Print JSON Schema + JsonSchema { + #[arg(value_enum, long)] + schema_type: SchemaType, + }, } /// Experimental commands are prone to change @@ -266,6 +274,13 @@ enum Format { Yaml, } +#[derive(clap::ValueEnum, Clone, Debug)] +enum SchemaType { + Pl, + Rq, + Lineage, +} + impl Command { /// Entrypoint called by [`main`] pub fn run(&mut self) -> Result<()> { @@ -309,6 +324,17 @@ impl Command { prqlc::ir::pl::print_mem_sizes(); Ok(()) } + Command::Debug(DebugCommand::JsonSchema { schema_type }) => { + let schema = match schema_type { + SchemaType::Pl => schema_for!(pl::ModuleDef), + SchemaType::Rq => schema_for!(rq::RelationalQuery), + SchemaType::Lineage => schema_for!(FrameCollector), + }; + io::stdout().write_all( + &serde_json::to_string_pretty(&schema)?.into_bytes() + )?; + Ok(()) + } _ => self.run_io_command(), } } diff --git a/prqlc/prqlc/src/ir/generic.rs b/prqlc/prqlc/src/ir/generic.rs index f27d946c28c8..98b587d62ef0 100644 --- a/prqlc/prqlc/src/ir/generic.rs +++ b/prqlc/prqlc/src/ir/generic.rs @@ -1,27 +1,28 @@ use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use crate::pr; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] pub struct ColumnSort { pub direction: SortDirection, pub column: T, } -#[derive(Debug, Clone, Serialize, Default, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Default, Deserialize, PartialEq, Eq, JsonSchema)] pub enum SortDirection { #[default] Asc, Desc, } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub struct WindowFrame { pub kind: WindowKind, pub range: pr::generic::Range, } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub enum WindowKind { Rows, Range, diff --git a/prqlc/prqlc/src/ir/pl/expr.rs b/prqlc/prqlc/src/ir/pl/expr.rs index bb6bd4068755..4848763d7322 100644 --- a/prqlc/prqlc/src/ir/pl/expr.rs +++ b/prqlc/prqlc/src/ir/pl/expr.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use enum_as_inner::EnumAsInner; use prqlc_parser::generic; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use super::{Lineage, TransformCall}; use crate::codegen::write_ty; @@ -10,7 +11,7 @@ use crate::pr::{GenericTypeParam, Ident, Literal, Span, Ty}; /// Expr is anything that has a value and thus a type. /// Most of these can contain other [Expr] themselves; literals should be [ExprKind::Literal]. -#[derive(Clone, PartialEq, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct Expr { #[serde(flatten)] pub kind: ExprKind, @@ -51,7 +52,7 @@ pub struct Expr { pub flatten: bool, } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr)] +#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema)] pub enum ExprKind { Ident(Ident), All { @@ -82,7 +83,7 @@ pub enum ExprKind { } /// Function call. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct FuncCall { pub name: Box, pub args: Vec, @@ -92,7 +93,7 @@ pub struct FuncCall { /// Function called with possibly missing positional arguments. /// May also contain environment that is needed to evaluate the body. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct Func { /// Name of the function. Used for user-facing messages only. pub name_hint: Option, @@ -120,7 +121,7 @@ pub struct Func { pub env: HashMap, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct FuncParam { pub name: String, diff --git a/prqlc/prqlc/src/ir/pl/extra.rs b/prqlc/prqlc/src/ir/pl/extra.rs index ec6aef3d059b..76e5a771a88b 100644 --- a/prqlc/prqlc/src/ir/pl/extra.rs +++ b/prqlc/prqlc/src/ir/pl/extra.rs @@ -1,5 +1,6 @@ use enum_as_inner::EnumAsInner; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use crate::ir::generic::WindowKind; use crate::ir::pl::{Expr, ExprKind, Func, FuncCall, Ident, Range}; @@ -16,7 +17,7 @@ impl FuncCall { } /// An expression that may have already been converted to a type. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumAsInner)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumAsInner, JsonSchema)] pub enum TyOrExpr { Ty(Ty), Expr(Box), @@ -34,7 +35,7 @@ pub type WindowFrame = crate::ir::generic::WindowFrame>; pub type ColumnSort = crate::ir::generic::ColumnSort>; /// FuncCall with better typing. Returns the modified table. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct TransformCall { pub input: Box, @@ -53,7 +54,7 @@ pub struct TransformCall { pub sort: Vec, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner, JsonSchema)] pub enum TransformKind { Derive { assigns: Box, @@ -92,7 +93,7 @@ pub enum TransformKind { } /// A reference to a table that is not in scope of this query. -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub enum TableExternRef { /// Actual table in a database, that we can refer to by name in SQL LocalTable(Ident), @@ -104,7 +105,7 @@ pub enum TableExternRef { // TODO: add other sources such as files, URLs } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub enum JoinSide { Inner, Left, diff --git a/prqlc/prqlc/src/ir/pl/lineage.rs b/prqlc/prqlc/src/ir/pl/lineage.rs index 7e3cd8676c31..4403459a4abb 100644 --- a/prqlc/prqlc/src/ir/pl/lineage.rs +++ b/prqlc/prqlc/src/ir/pl/lineage.rs @@ -4,12 +4,13 @@ use std::fmt::{Debug, Display, Formatter}; use enum_as_inner::EnumAsInner; use itertools::{Itertools, Position}; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use super::Ident; /// Represents the object that is manipulated by the pipeline transforms. /// Similar to a view in a database or a data frame. -#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub struct Lineage { pub columns: Vec, @@ -20,7 +21,7 @@ pub struct Lineage { pub prev_columns: Vec, } -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub struct LineageInput { /// Id of the node in AST that declares this input. pub id: usize, @@ -32,7 +33,7 @@ pub struct LineageInput { pub table: Ident, } -#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, EnumAsInner)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, EnumAsInner, JsonSchema)] pub enum LineageColumn { Single { name: Option, diff --git a/prqlc/prqlc/src/ir/pl/stmt.rs b/prqlc/prqlc/src/ir/pl/stmt.rs index b5b29923e010..8050ccb5d144 100644 --- a/prqlc/prqlc/src/ir/pl/stmt.rs +++ b/prqlc/prqlc/src/ir/pl/stmt.rs @@ -1,5 +1,6 @@ use enum_as_inner::EnumAsInner; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use crate::pr::Ident; use crate::pr::QueryDef; @@ -7,7 +8,7 @@ use crate::pr::{Span, Ty}; use super::expr::Expr; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct Stmt { #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, @@ -20,7 +21,7 @@ pub struct Stmt { pub annotations: Vec, } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub enum StmtKind { QueryDef(Box), VarDef(VarDef), @@ -29,7 +30,7 @@ pub enum StmtKind { ImportDef(ImportDef), } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct VarDef { pub name: String, pub value: Option>, @@ -38,25 +39,25 @@ pub struct VarDef { pub ty: Option, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct TypeDef { pub name: String, pub value: Option, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct ModuleDef { pub name: String, pub stmts: Vec, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct ImportDef { pub alias: Option, pub name: Ident, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct Annotation { pub expr: Box, } diff --git a/prqlc/prqlc/src/ir/rq/expr.rs b/prqlc/prqlc/src/ir/rq/expr.rs index e4d60783cd2d..a2851f75928b 100644 --- a/prqlc/prqlc/src/ir/rq/expr.rs +++ b/prqlc/prqlc/src/ir/rq/expr.rs @@ -1,12 +1,13 @@ use enum_as_inner::EnumAsInner; use prqlc_parser::lexer::lr::Literal; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use super::CId; use crate::{pr, Span}; /// Analogous to [crate::ir::pl::Expr], but with fewer kinds. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct Expr { pub kind: ExprKind, pub span: Option, @@ -16,14 +17,15 @@ pub(super) type Range = pr::generic::Range; pub(super) type InterpolateItem = pr::generic::InterpolateItem; pub(super) type SwitchCase = pr::generic::SwitchCase; -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumAsInner)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumAsInner, JsonSchema)] pub enum ExprKind { ColumnRef(CId), // https://github.com/dtolnay/serde-yaml/issues/363 // We should repeat this if we encounter any other nested enums. #[cfg_attr( feature = "serde_yaml", - serde(with = "serde_yaml::with::singleton_map") + serde(with = "serde_yaml::with::singleton_map"), + schemars(with = "Literal") )] Literal(Literal), @@ -42,7 +44,7 @@ pub enum ExprKind { Array(Vec), } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub enum UnOp { Neg, Not, diff --git a/prqlc/prqlc/src/ir/rq/ids.rs b/prqlc/prqlc/src/ir/rq/ids.rs index faced8329f5d..50e8d71e0f84 100644 --- a/prqlc/prqlc/src/ir/rq/ids.rs +++ b/prqlc/prqlc/src/ir/rq/ids.rs @@ -1,7 +1,8 @@ use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; /// Column id -#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Ord, PartialOrd)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Ord, PartialOrd, JsonSchema)] pub struct CId(usize); impl CId { @@ -23,7 +24,7 @@ impl std::fmt::Debug for CId { } /// Table id -#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)] pub struct TId(usize); impl TId { diff --git a/prqlc/prqlc/src/ir/rq/mod.rs b/prqlc/prqlc/src/ir/rq/mod.rs index 00172efb9911..c3940d6a6100 100644 --- a/prqlc/prqlc/src/ir/rq/mod.rs +++ b/prqlc/prqlc/src/ir/rq/mod.rs @@ -4,6 +4,7 @@ use enum_as_inner::EnumAsInner; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; pub use expr::{Expr, ExprKind, UnOp}; use expr::{InterpolateItem, Range, SwitchCase}; @@ -22,7 +23,7 @@ mod ids; mod transform; mod utils; -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct RelationalQuery { pub def: QueryDef, @@ -30,7 +31,7 @@ pub struct RelationalQuery { pub relation: Relation, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct Relation { pub kind: RelationKind, @@ -39,11 +40,12 @@ pub struct Relation { pub columns: Vec, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumAsInner)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumAsInner, JsonSchema)] pub enum RelationKind { #[cfg_attr( feature = "serde_yaml", - serde(with = "serde_yaml::with::singleton_map") + serde(with = "serde_yaml::with::singleton_map"), + schemars(with = "TableExternRef") )] ExternRef(TableExternRef), Pipeline(Vec), @@ -55,7 +57,7 @@ pub enum RelationKind { }, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct RelationLiteral { /// Column names pub columns: Vec, @@ -63,7 +65,7 @@ pub struct RelationLiteral { pub rows: Vec>, } -#[derive(Debug, PartialEq, Clone, Eq, Hash, Serialize, Deserialize, EnumAsInner)] +#[derive(Debug, PartialEq, Clone, Eq, Hash, Serialize, Deserialize, EnumAsInner, JsonSchema)] pub enum RelationColumn { /// A single column that may have a name. /// Unnamed columns cannot be referenced. @@ -73,7 +75,7 @@ pub enum RelationColumn { Wildcard, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct TableDecl { /// An id for this table, unique within all tables in this query. pub id: TId, @@ -85,7 +87,7 @@ pub struct TableDecl { pub relation: Relation, } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)] pub struct TableRef { /// Referenced table pub source: TId, diff --git a/prqlc/prqlc/src/ir/rq/transform.rs b/prqlc/prqlc/src/ir/rq/transform.rs index 80f43922a6c8..a04e630e12a0 100644 --- a/prqlc/prqlc/src/ir/rq/transform.rs +++ b/prqlc/prqlc/src/ir/rq/transform.rs @@ -1,5 +1,6 @@ use enum_as_inner::EnumAsInner; use serde::{Deserialize, Serialize}; +use schemars::JsonSchema; use super::*; use crate::ir::generic::ColumnSort; @@ -7,7 +8,7 @@ use crate::ir::generic::WindowFrame; use crate::ir::pl::JoinSide; /// Transformation of a table. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner, JsonSchema)] pub enum Transform { From(TableRef), Compute(Compute), @@ -28,14 +29,14 @@ pub enum Transform { Loop(Vec), } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct Take { pub range: Range, pub partition: Vec, pub sort: Vec>, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] pub struct Compute { pub id: CId, pub expr: Expr, @@ -50,7 +51,7 @@ pub struct Compute { } /// Transformation of a table. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Default)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Default, JsonSchema)] pub struct Window { pub frame: WindowFrame, pub partition: Vec, diff --git a/prqlc/prqlc/src/semantic/reporting.rs b/prqlc/prqlc/src/semantic/reporting.rs index 33a90d16e717..7a5a5d4e5e8f 100644 --- a/prqlc/prqlc/src/semantic/reporting.rs +++ b/prqlc/prqlc/src/semantic/reporting.rs @@ -3,6 +3,7 @@ use std::ops::Range; use ariadne::{Color, Label, Report, ReportBuilder, ReportKind, Source}; use serde::Serialize; +use schemars::JsonSchema; use crate::ir::decl::{DeclKind, Module, RootModule, TableDecl, TableExpr}; use crate::ir::pl; @@ -162,7 +163,7 @@ pub fn collect_frames(expr: pl::Expr) -> FrameCollector { collector } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, JsonSchema)] pub struct ExprGraphNode { /// Node unique ID pub id: usize, @@ -195,7 +196,7 @@ pub struct ExprGraphNode { pub parent: Option, } -#[derive(Serialize)] +#[derive(Serialize, JsonSchema)] pub struct FrameCollector { /// Each transformation step in the main pipeline corresponds to a single /// frame. This holds the output columns at each frame, as well as the span From 2ee892670c675d7a6473b8b87dc918af9e248c8f Mon Sep 17 00:00:00 2001 From: Karl Gutwin Date: Thu, 4 Jul 2024 10:50:39 -0400 Subject: [PATCH 2/5] cargo fmt --- prqlc/prqlc-parser/src/generic.rs | 2 +- prqlc/prqlc-parser/src/lexer/lr/token.rs | 8 +++++--- prqlc/prqlc-parser/src/parser/pr/expr.rs | 8 +++++--- prqlc/prqlc-parser/src/parser/pr/ident.rs | 2 +- prqlc/prqlc-parser/src/parser/pr/ops.rs | 2 +- prqlc/prqlc-parser/src/parser/pr/stmt.rs | 2 +- prqlc/prqlc-parser/src/parser/pr/types.rs | 12 ++++++++++-- prqlc/prqlc-parser/src/span.rs | 2 +- prqlc/prqlc/src/cli/mod.rs | 4 +--- prqlc/prqlc/src/ir/generic.rs | 2 +- prqlc/prqlc/src/ir/pl/expr.rs | 6 ++++-- prqlc/prqlc/src/ir/pl/extra.rs | 6 ++++-- prqlc/prqlc/src/ir/pl/lineage.rs | 2 +- prqlc/prqlc/src/ir/pl/stmt.rs | 2 +- prqlc/prqlc/src/ir/rq/expr.rs | 2 +- prqlc/prqlc/src/ir/rq/ids.rs | 2 +- prqlc/prqlc/src/ir/rq/mod.rs | 2 +- prqlc/prqlc/src/ir/rq/transform.rs | 6 ++++-- prqlc/prqlc/src/semantic/reporting.rs | 2 +- 19 files changed, 45 insertions(+), 29 deletions(-) diff --git a/prqlc/prqlc-parser/src/generic.rs b/prqlc/prqlc-parser/src/generic.rs index aa1ab7745cb6..029df39976a5 100644 --- a/prqlc/prqlc-parser/src/generic.rs +++ b/prqlc/prqlc-parser/src/generic.rs @@ -4,8 +4,8 @@ // hasn't been used much since, and I'm not sure carries its weight. So we // could consider rolling back to only concrete implementations to delayer the // code. -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; /// Inclusive-inclusive range. /// Missing bound means unbounded range. diff --git a/prqlc/prqlc-parser/src/lexer/lr/token.rs b/prqlc/prqlc-parser/src/lexer/lr/token.rs index c8518a87138d..d900917e42d1 100644 --- a/prqlc/prqlc-parser/src/lexer/lr/token.rs +++ b/prqlc/prqlc-parser/src/lexer/lr/token.rs @@ -1,6 +1,6 @@ use enum_as_inner::EnumAsInner; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; #[derive(Clone, PartialEq, Serialize, Deserialize, Eq, JsonSchema)] pub struct Token { @@ -17,7 +17,7 @@ pub enum TokenKind { #[cfg_attr( feature = "serde_yaml", serde(with = "serde_yaml::with::singleton_map"), - schemars(with = "Literal"), + schemars(with = "Literal") )] Literal(Literal), Param(String), @@ -66,7 +66,9 @@ pub enum TokenKind { LineWrap(Vec), } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema)] +#[derive( + Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema, +)] pub enum Literal { Null, Integer(i64), diff --git a/prqlc/prqlc-parser/src/parser/pr/expr.rs b/prqlc/prqlc-parser/src/parser/pr/expr.rs index e44d1fd206a9..d4eb8d8c8a26 100644 --- a/prqlc/prqlc-parser/src/parser/pr/expr.rs +++ b/prqlc/prqlc-parser/src/parser/pr/expr.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use enum_as_inner::EnumAsInner; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use crate::generic; use crate::lexer::lr::Literal; @@ -36,7 +36,9 @@ pub struct Expr { pub alias: Option, } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema)] +#[derive( + Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema, +)] pub enum ExprKind { Ident(String), @@ -49,7 +51,7 @@ pub enum ExprKind { #[cfg_attr( feature = "serde_yaml", serde(with = "serde_yaml::with::singleton_map"), - schemars(with = "Literal"), + schemars(with = "Literal") )] Literal(Literal), Pipeline(Pipeline), diff --git a/prqlc/prqlc-parser/src/parser/pr/ident.rs b/prqlc/prqlc-parser/src/parser/pr/ident.rs index 655c107288c2..9f7422a6e7f7 100644 --- a/prqlc/prqlc-parser/src/parser/pr/ident.rs +++ b/prqlc/prqlc-parser/src/parser/pr/ident.rs @@ -1,7 +1,7 @@ use std::fmt::Write; -use serde::{ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer}; use schemars::JsonSchema; +use serde::{ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer}; /// A name. Generally columns, tables, functions, variables. /// This is glorified way of writing a "vec with at least one element". diff --git a/prqlc/prqlc-parser/src/parser/pr/ops.rs b/prqlc/prqlc-parser/src/parser/pr/ops.rs index fbe76133e19f..3ac108b9a307 100644 --- a/prqlc/prqlc-parser/src/parser/pr/ops.rs +++ b/prqlc/prqlc-parser/src/parser/pr/ops.rs @@ -1,5 +1,5 @@ -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; #[derive( Debug, diff --git a/prqlc/prqlc-parser/src/parser/pr/stmt.rs b/prqlc/prqlc-parser/src/parser/pr/stmt.rs index cbb887164884..faf208a4939b 100644 --- a/prqlc/prqlc-parser/src/parser/pr/stmt.rs +++ b/prqlc/prqlc-parser/src/parser/pr/stmt.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; use enum_as_inner::EnumAsInner; +use schemars::JsonSchema; use semver::VersionReq; use serde::{Deserialize, Serialize}; -use schemars::JsonSchema; use crate::parser::pr::ident::Ident; use crate::parser::pr::{Expr, Ty}; diff --git a/prqlc/prqlc-parser/src/parser/pr/types.rs b/prqlc/prqlc-parser/src/parser/pr/types.rs index 7519b89ff4a8..dacb610acf92 100644 --- a/prqlc/prqlc-parser/src/parser/pr/types.rs +++ b/prqlc/prqlc-parser/src/parser/pr/types.rs @@ -1,7 +1,7 @@ use enum_as_inner::EnumAsInner; +use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use strum::AsRefStr; -use schemars::JsonSchema; use crate::lexer::lr::Literal; use crate::parser::pr::ident::Ident; @@ -73,7 +73,15 @@ pub enum TyTupleField { /// Built-in sets. #[derive( - Debug, Clone, Serialize, Deserialize, PartialEq, Eq, strum::EnumString, strum::Display, JsonSchema, + Debug, + Clone, + Serialize, + Deserialize, + PartialEq, + Eq, + strum::EnumString, + strum::Display, + JsonSchema, )] pub enum PrimitiveSet { #[strum(to_string = "int")] diff --git a/prqlc/prqlc-parser/src/span.rs b/prqlc/prqlc-parser/src/span.rs index eebb81e67795..6df543712706 100644 --- a/prqlc/prqlc-parser/src/span.rs +++ b/prqlc/prqlc-parser/src/span.rs @@ -2,9 +2,9 @@ use std::fmt::{self, Debug, Formatter}; use std::ops::{Add, Range, Sub}; use chumsky::Stream; +use schemars::JsonSchema; use serde::de::Visitor; use serde::{Deserialize, Serialize}; -use schemars::JsonSchema; #[derive(Clone, PartialEq, Eq, Copy, JsonSchema)] pub struct Span { diff --git a/prqlc/prqlc/src/cli/mod.rs b/prqlc/prqlc/src/cli/mod.rs index fbb7c3021d8f..c5887ba97b93 100644 --- a/prqlc/prqlc/src/cli/mod.rs +++ b/prqlc/prqlc/src/cli/mod.rs @@ -330,9 +330,7 @@ impl Command { SchemaType::Rq => schema_for!(rq::RelationalQuery), SchemaType::Lineage => schema_for!(FrameCollector), }; - io::stdout().write_all( - &serde_json::to_string_pretty(&schema)?.into_bytes() - )?; + io::stdout().write_all(&serde_json::to_string_pretty(&schema)?.into_bytes())?; Ok(()) } _ => self.run_io_command(), diff --git a/prqlc/prqlc/src/ir/generic.rs b/prqlc/prqlc/src/ir/generic.rs index 98b587d62ef0..1f8d52f0eb5b 100644 --- a/prqlc/prqlc/src/ir/generic.rs +++ b/prqlc/prqlc/src/ir/generic.rs @@ -1,5 +1,5 @@ -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use crate::pr; diff --git a/prqlc/prqlc/src/ir/pl/expr.rs b/prqlc/prqlc/src/ir/pl/expr.rs index 4848763d7322..e0b8eb7bd1b4 100644 --- a/prqlc/prqlc/src/ir/pl/expr.rs +++ b/prqlc/prqlc/src/ir/pl/expr.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use enum_as_inner::EnumAsInner; use prqlc_parser::generic; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use super::{Lineage, TransformCall}; use crate::codegen::write_ty; @@ -52,7 +52,9 @@ pub struct Expr { pub flatten: bool, } -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema)] +#[derive( + Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, JsonSchema, +)] pub enum ExprKind { Ident(Ident), All { diff --git a/prqlc/prqlc/src/ir/pl/extra.rs b/prqlc/prqlc/src/ir/pl/extra.rs index 76e5a771a88b..2fd5cd265738 100644 --- a/prqlc/prqlc/src/ir/pl/extra.rs +++ b/prqlc/prqlc/src/ir/pl/extra.rs @@ -1,6 +1,6 @@ use enum_as_inner::EnumAsInner; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use crate::ir::generic::WindowKind; use crate::ir::pl::{Expr, ExprKind, Func, FuncCall, Ident, Range}; @@ -54,7 +54,9 @@ pub struct TransformCall { pub sort: Vec, } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner, JsonSchema)] +#[derive( + Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner, JsonSchema, +)] pub enum TransformKind { Derive { assigns: Box, diff --git a/prqlc/prqlc/src/ir/pl/lineage.rs b/prqlc/prqlc/src/ir/pl/lineage.rs index 4403459a4abb..21a64ebfb3d4 100644 --- a/prqlc/prqlc/src/ir/pl/lineage.rs +++ b/prqlc/prqlc/src/ir/pl/lineage.rs @@ -3,8 +3,8 @@ use std::fmt::{Debug, Display, Formatter}; use enum_as_inner::EnumAsInner; use itertools::{Itertools, Position}; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use super::Ident; diff --git a/prqlc/prqlc/src/ir/pl/stmt.rs b/prqlc/prqlc/src/ir/pl/stmt.rs index 8050ccb5d144..f128f1798170 100644 --- a/prqlc/prqlc/src/ir/pl/stmt.rs +++ b/prqlc/prqlc/src/ir/pl/stmt.rs @@ -1,6 +1,6 @@ use enum_as_inner::EnumAsInner; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use crate::pr::Ident; use crate::pr::QueryDef; diff --git a/prqlc/prqlc/src/ir/rq/expr.rs b/prqlc/prqlc/src/ir/rq/expr.rs index a2851f75928b..d9db9790505c 100644 --- a/prqlc/prqlc/src/ir/rq/expr.rs +++ b/prqlc/prqlc/src/ir/rq/expr.rs @@ -1,7 +1,7 @@ use enum_as_inner::EnumAsInner; use prqlc_parser::lexer::lr::Literal; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use super::CId; use crate::{pr, Span}; diff --git a/prqlc/prqlc/src/ir/rq/ids.rs b/prqlc/prqlc/src/ir/rq/ids.rs index 50e8d71e0f84..e37fa4776c0f 100644 --- a/prqlc/prqlc/src/ir/rq/ids.rs +++ b/prqlc/prqlc/src/ir/rq/ids.rs @@ -1,5 +1,5 @@ -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; /// Column id #[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Ord, PartialOrd, JsonSchema)] diff --git a/prqlc/prqlc/src/ir/rq/mod.rs b/prqlc/prqlc/src/ir/rq/mod.rs index c3940d6a6100..82676147e905 100644 --- a/prqlc/prqlc/src/ir/rq/mod.rs +++ b/prqlc/prqlc/src/ir/rq/mod.rs @@ -3,8 +3,8 @@ //! Strictly typed AST for describing relational queries. use enum_as_inner::EnumAsInner; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; pub use expr::{Expr, ExprKind, UnOp}; use expr::{InterpolateItem, Range, SwitchCase}; diff --git a/prqlc/prqlc/src/ir/rq/transform.rs b/prqlc/prqlc/src/ir/rq/transform.rs index a04e630e12a0..87dc7abf39bb 100644 --- a/prqlc/prqlc/src/ir/rq/transform.rs +++ b/prqlc/prqlc/src/ir/rq/transform.rs @@ -1,6 +1,6 @@ use enum_as_inner::EnumAsInner; -use serde::{Deserialize, Serialize}; use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use super::*; use crate::ir::generic::ColumnSort; @@ -8,7 +8,9 @@ use crate::ir::generic::WindowFrame; use crate::ir::pl::JoinSide; /// Transformation of a table. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner, JsonSchema)] +#[derive( + Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner, JsonSchema, +)] pub enum Transform { From(TableRef), Compute(Compute), diff --git a/prqlc/prqlc/src/semantic/reporting.rs b/prqlc/prqlc/src/semantic/reporting.rs index 7a5a5d4e5e8f..472bb883c179 100644 --- a/prqlc/prqlc/src/semantic/reporting.rs +++ b/prqlc/prqlc/src/semantic/reporting.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use std::ops::Range; use ariadne::{Color, Label, Report, ReportBuilder, ReportKind, Source}; -use serde::Serialize; use schemars::JsonSchema; +use serde::Serialize; use crate::ir::decl::{DeclKind, Module, RootModule, TableDecl, TableExpr}; use crate::ir::pl; From c1acb8cd6f29428961f28d2bea239fa52a130c4f Mon Sep 17 00:00:00 2001 From: Karl Gutwin Date: Thu, 4 Jul 2024 10:52:43 -0400 Subject: [PATCH 3/5] cargo insta review --- .../integration__cli__shell_completion-2.snap | 38 ++++++----- .../integration__cli__shell_completion-3.snap | 20 ++++++ .../integration__cli__shell_completion-4.snap | 38 +++++++++++ .../integration__cli__shell_completion.snap | 65 ++++++++++++++++++- 4 files changed, 143 insertions(+), 18 deletions(-) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-2.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-2.snap index 6b6820e8d565..ca1b65ebe6f9 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-2.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-2.snap @@ -49,14 +49,15 @@ complete -c prqlc -n "__fish_seen_subcommand_from collect" -l color -d 'Controls complete -c prqlc -n "__fish_seen_subcommand_from collect" -s v -l verbose -d 'Increase logging verbosity' complete -c prqlc -n "__fish_seen_subcommand_from collect" -s q -l quiet -d 'Silences logging output' complete -c prqlc -n "__fish_seen_subcommand_from collect" -s h -l help -d 'Print help (see more with \'--help\')' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -l color -d 'Controls when to use color' -r -f -a "{auto '',always '',never ''}" -complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -s v -l verbose -d 'Increase logging verbosity' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -s q -l quiet -d 'Silences logging output' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -s h -l help -d 'Print help (see more with \'--help\')' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -f -a "annotate" -d 'Parse, resolve & combine source with comments annotating relation type' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -f -a "lineage" -d 'Output column-level lineage graph' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -f -a "ast" -d 'Print info about the AST data structure' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -l color -d 'Controls when to use color' -r -f -a "{auto '',always '',never ''}" +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -s v -l verbose -d 'Increase logging verbosity' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -s q -l quiet -d 'Silences logging output' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -s h -l help -d 'Print help (see more with \'--help\')' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "annotate" -d 'Parse, resolve & combine source with comments annotating relation type' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "lineage" -d 'Output column-level lineage graph' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "ast" -d 'Print info about the AST data structure' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "json-schema" -d 'Print JSON Schema' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from annotate" -l color -d 'Controls when to use color' -r -f -a "{auto '',always '',never ''}" complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from annotate" -s v -l verbose -d 'Increase logging verbosity' complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from annotate" -s q -l quiet -d 'Silences logging output' @@ -70,10 +71,16 @@ complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcomm complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from ast" -s v -l verbose -d 'Increase logging verbosity' complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from ast" -s q -l quiet -d 'Silences logging output' complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from ast" -s h -l help -d 'Print help (see more with \'--help\')' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -f -a "annotate" -d 'Parse, resolve & combine source with comments annotating relation type' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -f -a "lineage" -d 'Output column-level lineage graph' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -f -a "ast" -d 'Print info about the AST data structure' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -l schema-type -r -f -a "{pl '',rq '',lineage ''}" +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -l color -d 'Controls when to use color' -r -f -a "{auto '',always '',never ''}" +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -s v -l verbose -d 'Increase logging verbosity' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -s q -l quiet -d 'Silences logging output' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -s h -l help -d 'Print help (see more with \'--help\')' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "annotate" -d 'Parse, resolve & combine source with comments annotating relation type' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "lineage" -d 'Output column-level lineage graph' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "ast" -d 'Print info about the AST data structure' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "json-schema" -d 'Print JSON Schema' +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' complete -c prqlc -n "__fish_seen_subcommand_from experimental; and not __fish_seen_subcommand_from doc; and not __fish_seen_subcommand_from help" -l color -d 'Controls when to use color' -r -f -a "{auto '',always '',never ''}" complete -c prqlc -n "__fish_seen_subcommand_from experimental; and not __fish_seen_subcommand_from doc; and not __fish_seen_subcommand_from help" -s v -l verbose -d 'Increase logging verbosity' complete -c prqlc -n "__fish_seen_subcommand_from experimental; and not __fish_seen_subcommand_from doc; and not __fish_seen_subcommand_from help" -s q -l quiet -d 'Silences logging output' @@ -119,9 +126,10 @@ complete -c prqlc -n "__fish_seen_subcommand_from help; and not __fish_seen_subc complete -c prqlc -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from parse; and not __fish_seen_subcommand_from lex; and not __fish_seen_subcommand_from fmt; and not __fish_seen_subcommand_from collect; and not __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from experimental; and not __fish_seen_subcommand_from compile; and not __fish_seen_subcommand_from watch; and not __fish_seen_subcommand_from list-targets; and not __fish_seen_subcommand_from shell-completion; and not __fish_seen_subcommand_from help" -f -a "list-targets" -d 'Show available compile target names' complete -c prqlc -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from parse; and not __fish_seen_subcommand_from lex; and not __fish_seen_subcommand_from fmt; and not __fish_seen_subcommand_from collect; and not __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from experimental; and not __fish_seen_subcommand_from compile; and not __fish_seen_subcommand_from watch; and not __fish_seen_subcommand_from list-targets; and not __fish_seen_subcommand_from shell-completion; and not __fish_seen_subcommand_from help" -f -a "shell-completion" -d 'Print a shell completion for supported shells' complete -c prqlc -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from parse; and not __fish_seen_subcommand_from lex; and not __fish_seen_subcommand_from fmt; and not __fish_seen_subcommand_from collect; and not __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from experimental; and not __fish_seen_subcommand_from compile; and not __fish_seen_subcommand_from watch; and not __fish_seen_subcommand_from list-targets; and not __fish_seen_subcommand_from shell-completion; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' -complete -c prqlc -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast" -f -a "annotate" -d 'Parse, resolve & combine source with comments annotating relation type' -complete -c prqlc -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast" -f -a "lineage" -d 'Output column-level lineage graph' -complete -c prqlc -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast" -f -a "ast" -d 'Print info about the AST data structure' +complete -c prqlc -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema" -f -a "annotate" -d 'Parse, resolve & combine source with comments annotating relation type' +complete -c prqlc -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema" -f -a "lineage" -d 'Output column-level lineage graph' +complete -c prqlc -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema" -f -a "ast" -d 'Print info about the AST data structure' +complete -c prqlc -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from debug; and not __fish_seen_subcommand_from annotate; and not __fish_seen_subcommand_from lineage; and not __fish_seen_subcommand_from ast; and not __fish_seen_subcommand_from json-schema" -f -a "json-schema" -d 'Print JSON Schema' complete -c prqlc -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from experimental; and not __fish_seen_subcommand_from doc" -f -a "doc" -d 'Generate Markdown documentation' ----- stderr ----- diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-3.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-3.snap index 9c10d46ca509..ecf49d29a2c6 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-3.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-3.snap @@ -113,6 +113,7 @@ Register-ArgumentCompleter -Native -CommandName 'prqlc' -ScriptBlock { [CompletionResult]::new('annotate', 'annotate', [CompletionResultType]::ParameterValue, 'Parse, resolve & combine source with comments annotating relation type') [CompletionResult]::new('lineage', 'lineage', [CompletionResultType]::ParameterValue, 'Output column-level lineage graph') [CompletionResult]::new('ast', 'ast', [CompletionResultType]::ParameterValue, 'Print info about the AST data structure') + [CompletionResult]::new('json-schema', 'json-schema', [CompletionResultType]::ParameterValue, 'Print JSON Schema') [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') break } @@ -147,10 +148,22 @@ Register-ArgumentCompleter -Native -CommandName 'prqlc' -ScriptBlock { [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')') break } + 'prqlc;debug;json-schema' { + [CompletionResult]::new('--schema-type', 'schema-type', [CompletionResultType]::ParameterName, 'schema-type') + [CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'Controls when to use color') + [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Increase logging verbosity') + [CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Increase logging verbosity') + [CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Silences logging output') + [CompletionResult]::new('--quiet', 'quiet', [CompletionResultType]::ParameterName, 'Silences logging output') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')') + break + } 'prqlc;debug;help' { [CompletionResult]::new('annotate', 'annotate', [CompletionResultType]::ParameterValue, 'Parse, resolve & combine source with comments annotating relation type') [CompletionResult]::new('lineage', 'lineage', [CompletionResultType]::ParameterValue, 'Output column-level lineage graph') [CompletionResult]::new('ast', 'ast', [CompletionResultType]::ParameterValue, 'Print info about the AST data structure') + [CompletionResult]::new('json-schema', 'json-schema', [CompletionResultType]::ParameterValue, 'Print JSON Schema') [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') break } @@ -163,6 +176,9 @@ Register-ArgumentCompleter -Native -CommandName 'prqlc' -ScriptBlock { 'prqlc;debug;help;ast' { break } + 'prqlc;debug;help;json-schema' { + break + } 'prqlc;debug;help;help' { break } @@ -276,6 +292,7 @@ Register-ArgumentCompleter -Native -CommandName 'prqlc' -ScriptBlock { [CompletionResult]::new('annotate', 'annotate', [CompletionResultType]::ParameterValue, 'Parse, resolve & combine source with comments annotating relation type') [CompletionResult]::new('lineage', 'lineage', [CompletionResultType]::ParameterValue, 'Output column-level lineage graph') [CompletionResult]::new('ast', 'ast', [CompletionResultType]::ParameterValue, 'Print info about the AST data structure') + [CompletionResult]::new('json-schema', 'json-schema', [CompletionResultType]::ParameterValue, 'Print JSON Schema') break } 'prqlc;help;debug;annotate' { @@ -287,6 +304,9 @@ Register-ArgumentCompleter -Native -CommandName 'prqlc' -ScriptBlock { 'prqlc;help;debug;ast' { break } + 'prqlc;help;debug;json-schema' { + break + } 'prqlc;help;experimental' { [CompletionResult]::new('doc', 'doc', [CompletionResultType]::ParameterValue, 'Generate Markdown documentation') break diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-4.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-4.snap index 667a5459b9a5..726d0b97a41d 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-4.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-4.snap @@ -165,6 +165,18 @@ _arguments "${_arguments_options[@]}" \ '--help[Print help (see more with '\''--help'\'')]' \ && ret=0 ;; +(json-schema) +_arguments "${_arguments_options[@]}" \ +'--schema-type=[]:SCHEMA_TYPE:(pl rq lineage)' \ +'--color=[Controls when to use color]:WHEN:(auto always never)' \ +'*-v[Increase logging verbosity]' \ +'*--verbose[Increase logging verbosity]' \ +'(-v --verbose)*-q[Silences logging output]' \ +'(-v --verbose)*--quiet[Silences logging output]' \ +'-h[Print help (see more with '\''--help'\'')]' \ +'--help[Print help (see more with '\''--help'\'')]' \ +&& ret=0 +;; (help) _arguments "${_arguments_options[@]}" \ ":: :_prqlc__debug__help_commands" \ @@ -189,6 +201,10 @@ _arguments "${_arguments_options[@]}" \ _arguments "${_arguments_options[@]}" \ && ret=0 ;; +(json-schema) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; (help) _arguments "${_arguments_options[@]}" \ && ret=0 @@ -369,6 +385,10 @@ _arguments "${_arguments_options[@]}" \ (ast) _arguments "${_arguments_options[@]}" \ && ret=0 +;; +(json-schema) +_arguments "${_arguments_options[@]}" \ +&& ret=0 ;; esac ;; @@ -496,6 +516,7 @@ _prqlc__debug_commands() { 'annotate:Parse, resolve & combine source with comments annotating relation type' \ 'lineage:Output column-level lineage graph' \ 'ast:Print info about the AST data structure' \ +'json-schema:Print JSON Schema' \ 'help:Print this message or the help of the given subcommand(s)' \ ) _describe -t commands 'prqlc debug commands' commands "$@" @@ -506,6 +527,7 @@ _prqlc__help__debug_commands() { 'annotate:Parse, resolve & combine source with comments annotating relation type' \ 'lineage:Output column-level lineage graph' \ 'ast:Print info about the AST data structure' \ +'json-schema:Print JSON Schema' \ ) _describe -t commands 'prqlc help debug commands' commands "$@" } @@ -555,6 +577,7 @@ _prqlc__debug__help_commands() { 'annotate:Parse, resolve & combine source with comments annotating relation type' \ 'lineage:Output column-level lineage graph' \ 'ast:Print info about the AST data structure' \ +'json-schema:Print JSON Schema' \ 'help:Print this message or the help of the given subcommand(s)' \ ) _describe -t commands 'prqlc debug help commands' commands "$@" @@ -599,6 +622,21 @@ _prqlc__help__help_commands() { local commands; commands=() _describe -t commands 'prqlc help help commands' commands "$@" } +(( $+functions[_prqlc__debug__help__json-schema_commands] )) || +_prqlc__debug__help__json-schema_commands() { + local commands; commands=() + _describe -t commands 'prqlc debug help json-schema commands' commands "$@" +} +(( $+functions[_prqlc__debug__json-schema_commands] )) || +_prqlc__debug__json-schema_commands() { + local commands; commands=() + _describe -t commands 'prqlc debug json-schema commands' commands "$@" +} +(( $+functions[_prqlc__help__debug__json-schema_commands] )) || +_prqlc__help__debug__json-schema_commands() { + local commands; commands=() + _describe -t commands 'prqlc help debug json-schema commands' commands "$@" +} (( $+functions[_prqlc__help__lex_commands] )) || _prqlc__help__lex_commands() { local commands; commands=() diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion.snap index 043a01beee3c..f4d26705d418 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion.snap @@ -71,6 +71,9 @@ _prqlc() { prqlc__debug,help) cmd="prqlc__debug__help" ;; + prqlc__debug,json-schema) + cmd="prqlc__debug__json__schema" + ;; prqlc__debug,lineage) cmd="prqlc__debug__lineage" ;; @@ -83,6 +86,9 @@ _prqlc() { prqlc__debug__help,help) cmd="prqlc__debug__help__help" ;; + prqlc__debug__help,json-schema) + cmd="prqlc__debug__help__json__schema" + ;; prqlc__debug__help,lineage) cmd="prqlc__debug__help__lineage" ;; @@ -137,6 +143,9 @@ _prqlc() { prqlc__help__debug,ast) cmd="prqlc__help__debug__ast" ;; + prqlc__help__debug,json-schema) + cmd="prqlc__help__debug__json__schema" + ;; prqlc__help__debug,lineage) cmd="prqlc__help__debug__lineage" ;; @@ -216,7 +225,7 @@ _prqlc() { return 0 ;; prqlc__debug) - opts="-v -q -h --color --verbose --quiet --help annotate lineage ast help" + opts="-v -q -h --color --verbose --quiet --help annotate lineage ast json-schema help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -270,7 +279,7 @@ _prqlc() { return 0 ;; prqlc__debug__help) - opts="annotate lineage ast help" + opts="annotate lineage ast json-schema help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -325,6 +334,20 @@ _prqlc() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; + prqlc__debug__help__json__schema) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; prqlc__debug__help__lineage) opts="" if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then @@ -339,6 +362,28 @@ _prqlc() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; + prqlc__debug__json__schema) + opts="-v -q -h --schema-type --color --verbose --quiet --help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --schema-type) + COMPREPLY=($(compgen -W "pl rq lineage" -- "${cur}")) + return 0 + ;; + --color) + COMPREPLY=($(compgen -W "auto always never" -- "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; prqlc__debug__lineage) opts="-v -q -h --format --color --verbose --quiet --help [INPUT] [OUTPUT] [MAIN_PATH]" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then @@ -500,7 +545,7 @@ _prqlc() { return 0 ;; prqlc__help__debug) - opts="annotate lineage ast" + opts="annotate lineage ast json-schema" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -541,6 +586,20 @@ _prqlc() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; + prqlc__help__debug__json__schema) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; prqlc__help__debug__lineage) opts="" if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then From 1fd782d493d2e5c104aed78cf4cd3b8300b5c0f1 Mon Sep 17 00:00:00 2001 From: Karl Gutwin Date: Thu, 4 Jul 2024 23:29:11 -0400 Subject: [PATCH 4/5] add test, rename cli param and enum --- CHANGELOG.md | 4 ++++ prqlc/prqlc/src/cli/mod.rs | 14 +++++------ prqlc/prqlc/tests/integration/cli.rs | 23 +++++++++++++++++++ .../integration__cli__shell_completion-2.snap | 2 +- .../integration__cli__shell_completion-3.snap | 2 +- .../integration__cli__shell_completion-4.snap | 2 +- .../integration__cli__shell_completion.snap | 4 ++-- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae9f70ad3379..db5733887080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ **Features**: +- Added `prqlc debug json-schema` command to auto-generate JSON Schema + representations of commonly exposed IR types such as PL and RQ. + (@kgutwin, #4698) + **Fixes**: - Using `in` with an empty array pattern (e.g. `expr | in []`) will now output a diff --git a/prqlc/prqlc/src/cli/mod.rs b/prqlc/prqlc/src/cli/mod.rs index c5887ba97b93..55bd42c3af3b 100644 --- a/prqlc/prqlc/src/cli/mod.rs +++ b/prqlc/prqlc/src/cli/mod.rs @@ -212,7 +212,7 @@ enum DebugCommand { /// Print JSON Schema JsonSchema { #[arg(value_enum, long)] - schema_type: SchemaType, + ir_type: IntermediateRepr, }, } @@ -275,7 +275,7 @@ enum Format { } #[derive(clap::ValueEnum, Clone, Debug)] -enum SchemaType { +enum IntermediateRepr { Pl, Rq, Lineage, @@ -324,11 +324,11 @@ impl Command { prqlc::ir::pl::print_mem_sizes(); Ok(()) } - Command::Debug(DebugCommand::JsonSchema { schema_type }) => { - let schema = match schema_type { - SchemaType::Pl => schema_for!(pl::ModuleDef), - SchemaType::Rq => schema_for!(rq::RelationalQuery), - SchemaType::Lineage => schema_for!(FrameCollector), + Command::Debug(DebugCommand::JsonSchema { ir_type }) => { + let schema = match ir_type { + IntermediateRepr::Pl => schema_for!(pl::ModuleDef), + IntermediateRepr::Rq => schema_for!(rq::RelationalQuery), + IntermediateRepr::Lineage => schema_for!(FrameCollector), }; io::stdout().write_all(&serde_json::to_string_pretty(&schema)?.into_bytes())?; Ok(()) diff --git a/prqlc/prqlc/tests/integration/cli.rs b/prqlc/prqlc/tests/integration/cli.rs index 87e12036c330..1be3d2e05eb7 100644 --- a/prqlc/prqlc/tests/integration/cli.rs +++ b/prqlc/prqlc/tests/integration/cli.rs @@ -534,6 +534,29 @@ fn debug() { .stderr(std::process::Stdio::null()) .status() .unwrap(); + +} + +// The output of `prqlc debug json-schema` is long, so rather than +// comparing the full output as a snapshot, we just verify that the +// standard output parses as JSON and check a couple top-level keys. +#[test] +fn debug_json_schema() { + use serde_json::Value; + + let output = prqlc_command() + .args(["debug", "json-schema", "--ir-type", "pl"]) + .output() + .unwrap(); + + assert!(output.status.success()); + + let stdout = std::str::from_utf8(&output.stdout).unwrap(); + let parsed: Value = serde_json::from_str(stdout).unwrap(); + + assert_eq!(parsed["$schema"], "https://json-schema.org/draft/2020-12/schema"); + assert_eq!(parsed["type"], "object"); + assert_eq!(parsed["title"], "ModuleDef"); } #[test] diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-2.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-2.snap index ca1b65ebe6f9..cdd6db7eca17 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-2.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-2.snap @@ -71,7 +71,7 @@ complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcomm complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from ast" -s v -l verbose -d 'Increase logging verbosity' complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from ast" -s q -l quiet -d 'Silences logging output' complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from ast" -s h -l help -d 'Print help (see more with \'--help\')' -complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -l schema-type -r -f -a "{pl '',rq '',lineage ''}" +complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -l ir-type -r -f -a "{pl '',rq '',lineage ''}" complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -l color -d 'Controls when to use color' -r -f -a "{auto '',always '',never ''}" complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -s v -l verbose -d 'Increase logging verbosity' complete -c prqlc -n "__fish_seen_subcommand_from debug; and __fish_seen_subcommand_from json-schema" -s q -l quiet -d 'Silences logging output' diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-3.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-3.snap index ecf49d29a2c6..c1e11e354ccb 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-3.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-3.snap @@ -149,7 +149,7 @@ Register-ArgumentCompleter -Native -CommandName 'prqlc' -ScriptBlock { break } 'prqlc;debug;json-schema' { - [CompletionResult]::new('--schema-type', 'schema-type', [CompletionResultType]::ParameterName, 'schema-type') + [CompletionResult]::new('--ir-type', 'ir-type', [CompletionResultType]::ParameterName, 'ir-type') [CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'Controls when to use color') [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Increase logging verbosity') [CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Increase logging verbosity') diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-4.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-4.snap index 726d0b97a41d..7025de96b48f 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-4.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion-4.snap @@ -167,7 +167,7 @@ _arguments "${_arguments_options[@]}" \ ;; (json-schema) _arguments "${_arguments_options[@]}" \ -'--schema-type=[]:SCHEMA_TYPE:(pl rq lineage)' \ +'--ir-type=[]:IR_TYPE:(pl rq lineage)' \ '--color=[Controls when to use color]:WHEN:(auto always never)' \ '*-v[Increase logging verbosity]' \ '*--verbose[Increase logging verbosity]' \ diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion.snap index f4d26705d418..22e14b2ce6ff 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__shell_completion.snap @@ -363,13 +363,13 @@ _prqlc() { return 0 ;; prqlc__debug__json__schema) - opts="-v -q -h --schema-type --color --verbose --quiet --help" + opts="-v -q -h --ir-type --color --verbose --quiet --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 fi case "${prev}" in - --schema-type) + --ir-type) COMPREPLY=($(compgen -W "pl rq lineage" -- "${cur}")) return 0 ;; From 0cedb6413a608f97103d3b483451de4c3d3a3188 Mon Sep 17 00:00:00 2001 From: Karl Gutwin Date: Thu, 4 Jul 2024 23:30:08 -0400 Subject: [PATCH 5/5] cargo fmt and pre-commit --- CHANGELOG.md | 4 ++-- prqlc/prqlc/tests/integration/cli.rs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db5733887080..895205328bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,8 @@ **Features**: - Added `prqlc debug json-schema` command to auto-generate JSON Schema - representations of commonly exposed IR types such as PL and RQ. - (@kgutwin, #4698) + representations of commonly exposed IR types such as PL and RQ. (@kgutwin, + #4698) **Fixes**: diff --git a/prqlc/prqlc/tests/integration/cli.rs b/prqlc/prqlc/tests/integration/cli.rs index 1be3d2e05eb7..1cd2c0ecec12 100644 --- a/prqlc/prqlc/tests/integration/cli.rs +++ b/prqlc/prqlc/tests/integration/cli.rs @@ -534,7 +534,6 @@ fn debug() { .stderr(std::process::Stdio::null()) .status() .unwrap(); - } // The output of `prqlc debug json-schema` is long, so rather than @@ -543,7 +542,7 @@ fn debug() { #[test] fn debug_json_schema() { use serde_json::Value; - + let output = prqlc_command() .args(["debug", "json-schema", "--ir-type", "pl"]) .output() @@ -554,7 +553,10 @@ fn debug_json_schema() { let stdout = std::str::from_utf8(&output.stdout).unwrap(); let parsed: Value = serde_json::from_str(stdout).unwrap(); - assert_eq!(parsed["$schema"], "https://json-schema.org/draft/2020-12/schema"); + assert_eq!( + parsed["$schema"], + "https://json-schema.org/draft/2020-12/schema" + ); assert_eq!(parsed["type"], "object"); assert_eq!(parsed["title"], "ModuleDef"); }