Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/user/content/sql/show-create-connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ menu:
## Syntax

```sql
SHOW CREATE CONNECTION <connection_name>
SHOW [REDACTED] CREATE CONNECTION <connection_name>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a blurb on what [REDACTED] does?
We can single source that statement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a patch with the description of the REDACTED option. Feel free to update the description in the show_create_redacted_option.yml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you very much @kay-kim !

```

{{< yaml-table data="show_create_redacted_option" >}}

For available connection names, see [`SHOW CONNECTIONS`](/sql/show-connections).

## Examples
Expand Down
4 changes: 3 additions & 1 deletion doc/user/content/sql/show-create-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ menu:
## Syntax

```sql
SHOW CREATE INDEX <index_name>
SHOW [REDACTED] CREATE INDEX <index_name>
```

{{< yaml-table data="show_create_redacted_option" >}}

For available index names, see [`SHOW INDEXES`](/sql/show-indexes).

## Examples
Expand Down
4 changes: 3 additions & 1 deletion doc/user/content/sql/show-create-materialized-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ menu:
## Syntax

```sql
SHOW CREATE MATERIALIZED VIEW <view_name>
SHOW [REDACTED] CREATE MATERIALIZED VIEW <view_name>
```

{{< yaml-table data="show_create_redacted_option" >}}

For available materialized view names, see [`SHOW MATERIALIZED VIEWS`](/sql/show-materialized-views).

## Examples
Expand Down
4 changes: 3 additions & 1 deletion doc/user/content/sql/show-create-sink.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ menu:
## Syntax

```sql
SHOW CREATE SINK <sink_name>
SHOW [REDACTED] CREATE SINK <sink_name>
```

{{< yaml-table data="show_create_redacted_option" >}}

For available sink names, see [`SHOW SINKS`](/sql/show-sinks).

## Examples
Expand Down
4 changes: 3 additions & 1 deletion doc/user/content/sql/show-create-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ menu:
## Syntax

```sql
SHOW CREATE SOURCE <source_name>
SHOW [REDACTED] CREATE SOURCE <source_name>
```

{{< yaml-table data="show_create_redacted_option" >}}

For available source names, see [`SHOW SOURCES`](/sql/show-sources).

## Examples
Expand Down
4 changes: 3 additions & 1 deletion doc/user/content/sql/show-create-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ menu:
## Syntax

```sql
SHOW CREATE TABLE <table_name>
SHOW [REDACTED] CREATE TABLE <table_name>
```

{{< yaml-table data="show_create_redacted_option" >}}

For available table names, see [`SHOW TABLES`](/sql/show-tables).

## Examples
Expand Down
4 changes: 3 additions & 1 deletion doc/user/content/sql/show-create-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ menu:
## Syntax

```sql
SHOW CREATE VIEW <view_name>
SHOW [REDACTED] CREATE VIEW <view_name>
```

{{< yaml-table data="show_create_redacted_option" >}}

For available view names, see [`SHOW VIEWS`](/sql/show-views).

## Examples
Expand Down
7 changes: 7 additions & 0 deletions doc/user/data/show_create_redacted_option.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
columns:
- column: Option
- column: Description

rows:
- Option: "**REDACTED**"
Description: "If specified, literals will be redacted."
62 changes: 49 additions & 13 deletions src/sql-parser/src/ast/defs/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3561,98 +3561,134 @@ impl<T: AstInfo> AstDisplay for ShowColumnsStatement<T> {
}
impl_display_t!(ShowColumnsStatement);

/// `SHOW CREATE VIEW <view>`
/// `SHOW [REDACTED] CREATE VIEW <view>`
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ShowCreateViewStatement<T: AstInfo> {
pub view_name: T::ItemName,
pub redacted: bool,
}

impl<T: AstInfo> AstDisplay for ShowCreateViewStatement<T> {
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
f.write_str("SHOW CREATE VIEW ");
f.write_str("SHOW ");
if self.redacted {
f.write_str("REDACTED ");
}
f.write_str("CREATE VIEW ");
f.write_node(&self.view_name);
}
}
impl_display_t!(ShowCreateViewStatement);

/// `SHOW CREATE MATERIALIZED VIEW <name>`
/// `SHOW [REDACTED] CREATE MATERIALIZED VIEW <name>`
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ShowCreateMaterializedViewStatement<T: AstInfo> {
pub materialized_view_name: T::ItemName,
pub redacted: bool,
}

impl<T: AstInfo> AstDisplay for ShowCreateMaterializedViewStatement<T> {
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
f.write_str("SHOW CREATE MATERIALIZED VIEW ");
f.write_str("SHOW ");
if self.redacted {
f.write_str("REDACTED ");
}
f.write_str("CREATE MATERIALIZED VIEW ");
f.write_node(&self.materialized_view_name);
}
}
impl_display_t!(ShowCreateMaterializedViewStatement);

/// `SHOW CREATE SOURCE <source>`
/// `SHOW [REDACTED] CREATE SOURCE <source>`
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ShowCreateSourceStatement<T: AstInfo> {
pub source_name: T::ItemName,
pub redacted: bool,
}

impl<T: AstInfo> AstDisplay for ShowCreateSourceStatement<T> {
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
f.write_str("SHOW CREATE SOURCE ");
f.write_str("SHOW ");
if self.redacted {
f.write_str("REDACTED ");
}
f.write_str("CREATE SOURCE ");
f.write_node(&self.source_name);
}
}
impl_display_t!(ShowCreateSourceStatement);

/// `SHOW CREATE TABLE <table>`
/// `SHOW [REDACTED] CREATE TABLE <table>`
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ShowCreateTableStatement<T: AstInfo> {
pub table_name: T::ItemName,
pub redacted: bool,
}

impl<T: AstInfo> AstDisplay for ShowCreateTableStatement<T> {
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
f.write_str("SHOW CREATE TABLE ");
f.write_str("SHOW ");
if self.redacted {
f.write_str("REDACTED ");
}
f.write_str("CREATE TABLE ");
f.write_node(&self.table_name);
}
}
impl_display_t!(ShowCreateTableStatement);

/// `SHOW CREATE SINK <sink>`
/// `SHOW [REDACTED] CREATE SINK <sink>`
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ShowCreateSinkStatement<T: AstInfo> {
pub sink_name: T::ItemName,
pub redacted: bool,
}

impl<T: AstInfo> AstDisplay for ShowCreateSinkStatement<T> {
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
f.write_str("SHOW CREATE SINK ");
f.write_str("SHOW ");
if self.redacted {
f.write_str("REDACTED ");
}
f.write_str("CREATE SINK ");
f.write_node(&self.sink_name);
}
}
impl_display_t!(ShowCreateSinkStatement);

/// `SHOW CREATE INDEX <index>`
/// `SHOW [REDACTED] CREATE INDEX <index>`
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ShowCreateIndexStatement<T: AstInfo> {
pub index_name: T::ItemName,
pub redacted: bool,
}

impl<T: AstInfo> AstDisplay for ShowCreateIndexStatement<T> {
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
f.write_str("SHOW CREATE INDEX ");
f.write_str("SHOW ");
if self.redacted {
f.write_str("REDACTED ");
}
f.write_str("CREATE INDEX ");
f.write_node(&self.index_name);
}
}
impl_display_t!(ShowCreateIndexStatement);

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

impl<T: AstInfo> AstDisplay for ShowCreateConnectionStatement<T> {
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
f.write_str("SHOW CREATE CONNECTION ");
f.write_str("SHOW ");
if self.redacted {
f.write_str("REDACTED ");
}
f.write_str("CREATE CONNECTION ");
f.write_node(&self.connection_name);
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/sql-parser/src/ast/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ where
}

/// Describes the context in which to print an AST.
///
/// TODO: Currently, only the simple format can be redacted, but, ideally, whether it's redacted and
/// whether it's stable would be orthogonal settings.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum FormatMode {
/// Simple is the normal way of printing for human consumption. Identifiers are quoted only if
/// necessary and sensative information is redacted.
/// necessary and sensitive information is not redacted.
Simple,
/// SimpleRedacted is like Simple, but strips out string and number literals.
/// SimpleRedacted is like Simple, but strips out literals, e.g. strings and numbers.
/// This makes SQL queries be "usage data", rather than "customer data" according to our
/// data management policy, allowing us to introspect it.
SimpleRedacted,
Expand Down
22 changes: 22 additions & 0 deletions src/sql-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7720,6 +7720,14 @@ impl<'a> Parser<'a> {
}

fn parse_show(&mut self) -> Result<ShowStatement<Raw>, ParserError> {
let redacted = self.parse_keyword(REDACTED);
if redacted && !self.peek_keyword(CREATE) {
return parser_err!(
self,
self.peek_pos(),
"SHOW REDACTED is only supported for SHOW REDACTED CREATE ..."
);
}
if self.parse_one_of_keywords(&[COLUMNS, FIELDS]).is_some() {
self.parse_show_columns()
} else if self.parse_keyword(OBJECTS) {
Expand Down Expand Up @@ -7860,36 +7868,50 @@ impl<'a> Parser<'a> {
} else if self.parse_keywords(&[CREATE, VIEW]) {
Ok(ShowStatement::ShowCreateView(ShowCreateViewStatement {
view_name: self.parse_raw_name()?,
redacted,
}))
} else if self.parse_keywords(&[CREATE, MATERIALIZED, VIEW]) {
Ok(ShowStatement::ShowCreateMaterializedView(
ShowCreateMaterializedViewStatement {
materialized_view_name: self.parse_raw_name()?,
redacted,
},
))
} else if self.parse_keywords(&[CREATE, SOURCE]) {
Ok(ShowStatement::ShowCreateSource(ShowCreateSourceStatement {
source_name: self.parse_raw_name()?,
redacted,
}))
} else if self.parse_keywords(&[CREATE, TABLE]) {
Ok(ShowStatement::ShowCreateTable(ShowCreateTableStatement {
table_name: self.parse_raw_name()?,
redacted,
}))
} else if self.parse_keywords(&[CREATE, SINK]) {
Ok(ShowStatement::ShowCreateSink(ShowCreateSinkStatement {
sink_name: self.parse_raw_name()?,
redacted,
}))
} else if self.parse_keywords(&[CREATE, INDEX]) {
Ok(ShowStatement::ShowCreateIndex(ShowCreateIndexStatement {
index_name: self.parse_raw_name()?,
redacted,
}))
} else if self.parse_keywords(&[CREATE, CONNECTION]) {
Ok(ShowStatement::ShowCreateConnection(
ShowCreateConnectionStatement {
connection_name: self.parse_raw_name()?,
redacted,
},
))
} else if self.parse_keywords(&[CREATE, CLUSTER]) {
if redacted {
return parser_err!(
self,
self.peek_prev_pos(),
"SHOW REDACTED CREATE CLUSTER is not supported"
);
}
Ok(ShowStatement::ShowCreateCluster(
ShowCreateClusterStatement {
cluster_name: RawClusterName::Unresolved(self.parse_identifier()?),
Expand Down
Loading