Skip to content

Commit 6cf4a37

Browse files
authored
Merge pull request #31887 from ggevay/show-redacted-create
Implement `SHOW REDACTED CREATE ...`
2 parents 4d62976 + dbb814d commit 6cf4a37

File tree

14 files changed

+443
-47
lines changed

14 files changed

+443
-47
lines changed

doc/user/content/sql/show-create-connection.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ menu:
1111
## Syntax
1212

1313
```sql
14-
SHOW CREATE CONNECTION <connection_name>
14+
SHOW [REDACTED] CREATE CONNECTION <connection_name>
1515
```
1616

17+
{{< yaml-table data="show_create_redacted_option" >}}
18+
1719
For available connection names, see [`SHOW CONNECTIONS`](/sql/show-connections).
1820

1921
## Examples

doc/user/content/sql/show-create-index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ menu:
1111
## Syntax
1212

1313
```sql
14-
SHOW CREATE INDEX <index_name>
14+
SHOW [REDACTED] CREATE INDEX <index_name>
1515
```
1616

17+
{{< yaml-table data="show_create_redacted_option" >}}
18+
1719
For available index names, see [`SHOW INDEXES`](/sql/show-indexes).
1820

1921
## Examples

doc/user/content/sql/show-create-materialized-view.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ menu:
1111
## Syntax
1212

1313
```sql
14-
SHOW CREATE MATERIALIZED VIEW <view_name>
14+
SHOW [REDACTED] CREATE MATERIALIZED VIEW <view_name>
1515
```
1616

17+
{{< yaml-table data="show_create_redacted_option" >}}
18+
1719
For available materialized view names, see [`SHOW MATERIALIZED VIEWS`](/sql/show-materialized-views).
1820

1921
## Examples

doc/user/content/sql/show-create-sink.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ menu:
1111
## Syntax
1212

1313
```sql
14-
SHOW CREATE SINK <sink_name>
14+
SHOW [REDACTED] CREATE SINK <sink_name>
1515
```
1616

17+
{{< yaml-table data="show_create_redacted_option" >}}
18+
1719
For available sink names, see [`SHOW SINKS`](/sql/show-sinks).
1820

1921
## Examples

doc/user/content/sql/show-create-source.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ menu:
1111
## Syntax
1212

1313
```sql
14-
SHOW CREATE SOURCE <source_name>
14+
SHOW [REDACTED] CREATE SOURCE <source_name>
1515
```
1616

17+
{{< yaml-table data="show_create_redacted_option" >}}
18+
1719
For available source names, see [`SHOW SOURCES`](/sql/show-sources).
1820

1921
## Examples

doc/user/content/sql/show-create-table.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ menu:
1111
## Syntax
1212

1313
```sql
14-
SHOW CREATE TABLE <table_name>
14+
SHOW [REDACTED] CREATE TABLE <table_name>
1515
```
1616

17+
{{< yaml-table data="show_create_redacted_option" >}}
18+
1719
For available table names, see [`SHOW TABLES`](/sql/show-tables).
1820

1921
## Examples

doc/user/content/sql/show-create-view.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ menu:
1111
## Syntax
1212

1313
```sql
14-
SHOW CREATE VIEW <view_name>
14+
SHOW [REDACTED] CREATE VIEW <view_name>
1515
```
1616

17+
{{< yaml-table data="show_create_redacted_option" >}}
18+
1719
For available view names, see [`SHOW VIEWS`](/sql/show-views).
1820

1921
## Examples
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
columns:
2+
- column: Option
3+
- column: Description
4+
5+
rows:
6+
- Option: "**REDACTED**"
7+
Description: "If specified, literals will be redacted."

src/sql-parser/src/ast/defs/statement.rs

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,98 +3561,134 @@ impl<T: AstInfo> AstDisplay for ShowColumnsStatement<T> {
35613561
}
35623562
impl_display_t!(ShowColumnsStatement);
35633563

3564-
/// `SHOW CREATE VIEW <view>`
3564+
/// `SHOW [REDACTED] CREATE VIEW <view>`
35653565
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
35663566
pub struct ShowCreateViewStatement<T: AstInfo> {
35673567
pub view_name: T::ItemName,
3568+
pub redacted: bool,
35683569
}
35693570

35703571
impl<T: AstInfo> AstDisplay for ShowCreateViewStatement<T> {
35713572
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
3572-
f.write_str("SHOW CREATE VIEW ");
3573+
f.write_str("SHOW ");
3574+
if self.redacted {
3575+
f.write_str("REDACTED ");
3576+
}
3577+
f.write_str("CREATE VIEW ");
35733578
f.write_node(&self.view_name);
35743579
}
35753580
}
35763581
impl_display_t!(ShowCreateViewStatement);
35773582

3578-
/// `SHOW CREATE MATERIALIZED VIEW <name>`
3583+
/// `SHOW [REDACTED] CREATE MATERIALIZED VIEW <name>`
35793584
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
35803585
pub struct ShowCreateMaterializedViewStatement<T: AstInfo> {
35813586
pub materialized_view_name: T::ItemName,
3587+
pub redacted: bool,
35823588
}
35833589

35843590
impl<T: AstInfo> AstDisplay for ShowCreateMaterializedViewStatement<T> {
35853591
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
3586-
f.write_str("SHOW CREATE MATERIALIZED VIEW ");
3592+
f.write_str("SHOW ");
3593+
if self.redacted {
3594+
f.write_str("REDACTED ");
3595+
}
3596+
f.write_str("CREATE MATERIALIZED VIEW ");
35873597
f.write_node(&self.materialized_view_name);
35883598
}
35893599
}
35903600
impl_display_t!(ShowCreateMaterializedViewStatement);
35913601

3592-
/// `SHOW CREATE SOURCE <source>`
3602+
/// `SHOW [REDACTED] CREATE SOURCE <source>`
35933603
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
35943604
pub struct ShowCreateSourceStatement<T: AstInfo> {
35953605
pub source_name: T::ItemName,
3606+
pub redacted: bool,
35963607
}
35973608

35983609
impl<T: AstInfo> AstDisplay for ShowCreateSourceStatement<T> {
35993610
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
3600-
f.write_str("SHOW CREATE SOURCE ");
3611+
f.write_str("SHOW ");
3612+
if self.redacted {
3613+
f.write_str("REDACTED ");
3614+
}
3615+
f.write_str("CREATE SOURCE ");
36013616
f.write_node(&self.source_name);
36023617
}
36033618
}
36043619
impl_display_t!(ShowCreateSourceStatement);
36053620

3606-
/// `SHOW CREATE TABLE <table>`
3621+
/// `SHOW [REDACTED] CREATE TABLE <table>`
36073622
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
36083623
pub struct ShowCreateTableStatement<T: AstInfo> {
36093624
pub table_name: T::ItemName,
3625+
pub redacted: bool,
36103626
}
36113627

36123628
impl<T: AstInfo> AstDisplay for ShowCreateTableStatement<T> {
36133629
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
3614-
f.write_str("SHOW CREATE TABLE ");
3630+
f.write_str("SHOW ");
3631+
if self.redacted {
3632+
f.write_str("REDACTED ");
3633+
}
3634+
f.write_str("CREATE TABLE ");
36153635
f.write_node(&self.table_name);
36163636
}
36173637
}
36183638
impl_display_t!(ShowCreateTableStatement);
36193639

3620-
/// `SHOW CREATE SINK <sink>`
3640+
/// `SHOW [REDACTED] CREATE SINK <sink>`
36213641
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
36223642
pub struct ShowCreateSinkStatement<T: AstInfo> {
36233643
pub sink_name: T::ItemName,
3644+
pub redacted: bool,
36243645
}
36253646

36263647
impl<T: AstInfo> AstDisplay for ShowCreateSinkStatement<T> {
36273648
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
3628-
f.write_str("SHOW CREATE SINK ");
3649+
f.write_str("SHOW ");
3650+
if self.redacted {
3651+
f.write_str("REDACTED ");
3652+
}
3653+
f.write_str("CREATE SINK ");
36293654
f.write_node(&self.sink_name);
36303655
}
36313656
}
36323657
impl_display_t!(ShowCreateSinkStatement);
36333658

3634-
/// `SHOW CREATE INDEX <index>`
3659+
/// `SHOW [REDACTED] CREATE INDEX <index>`
36353660
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
36363661
pub struct ShowCreateIndexStatement<T: AstInfo> {
36373662
pub index_name: T::ItemName,
3663+
pub redacted: bool,
36383664
}
36393665

36403666
impl<T: AstInfo> AstDisplay for ShowCreateIndexStatement<T> {
36413667
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
3642-
f.write_str("SHOW CREATE INDEX ");
3668+
f.write_str("SHOW ");
3669+
if self.redacted {
3670+
f.write_str("REDACTED ");
3671+
}
3672+
f.write_str("CREATE INDEX ");
36433673
f.write_node(&self.index_name);
36443674
}
36453675
}
36463676
impl_display_t!(ShowCreateIndexStatement);
36473677

3678+
/// `SHOW [REDACTED] CREATE CONNECTION <connection>`
36483679
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
36493680
pub struct ShowCreateConnectionStatement<T: AstInfo> {
36503681
pub connection_name: T::ItemName,
3682+
pub redacted: bool,
36513683
}
36523684

36533685
impl<T: AstInfo> AstDisplay for ShowCreateConnectionStatement<T> {
36543686
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
3655-
f.write_str("SHOW CREATE CONNECTION ");
3687+
f.write_str("SHOW ");
3688+
if self.redacted {
3689+
f.write_str("REDACTED ");
3690+
}
3691+
f.write_str("CREATE CONNECTION ");
36563692
f.write_node(&self.connection_name);
36573693
}
36583694
}

src/sql-parser/src/ast/display.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ where
6767
}
6868

6969
/// Describes the context in which to print an AST.
70+
///
71+
/// TODO: Currently, only the simple format can be redacted, but, ideally, whether it's redacted and
72+
/// whether it's stable would be orthogonal settings.
7073
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
7174
pub enum FormatMode {
7275
/// Simple is the normal way of printing for human consumption. Identifiers are quoted only if
73-
/// necessary and sensative information is redacted.
76+
/// necessary and sensitive information is not redacted.
7477
Simple,
75-
/// SimpleRedacted is like Simple, but strips out string and number literals.
78+
/// SimpleRedacted is like Simple, but strips out literals, e.g. strings and numbers.
7679
/// This makes SQL queries be "usage data", rather than "customer data" according to our
7780
/// data management policy, allowing us to introspect it.
7881
SimpleRedacted,

0 commit comments

Comments
 (0)