Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

buildInputs = buildInputs;
NIX_HARDENING_ENABLE = "";
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [
stdenv.cc.cc.lib
];
};
});
}
54 changes: 53 additions & 1 deletion src/catalog/src/system_schema/information_schema/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ use datatypes::vectors::{
};
use futures::TryStreamExt;
use snafu::{OptionExt, ResultExt};
use sql::ast::Ident;
use sql::dialect::GreptimeDbDialect;
use sql::parser::ParserContext;
use sql::statements::create::{CreateFlow, SqlOrTql};
use sql::statements::statement::Statement;
use store_api::storage::{ScanRequest, TableId};

use crate::CatalogManager;
Expand Down Expand Up @@ -121,6 +126,50 @@ impl InformationSchemaFlows {
))
}

/// Generates the CREATE FLOW statement for the flow_definition column
pub(crate) fn generate_show_create_flow(flow_info: &FlowInfoValue) -> Result<String> {
let mut parser_ctx = ParserContext::new(&GreptimeDbDialect {}, flow_info.raw_sql())
.map_err(BoxedError::new)
.context(InternalSnafu)?;

let query = parser_ctx
.parse_statement()
.map_err(BoxedError::new)
.context(InternalSnafu)?;

let raw_query = match &query {
Statement::Tql(_) => flow_info.raw_sql().clone(),
_ => query.to_string(),
};

let query = Box::new(
SqlOrTql::try_from_statement(query, &raw_query)
.map_err(BoxedError::new)
.context(InternalSnafu)?,
);

let comment = if flow_info.comment().is_empty() {
None
} else {
Some(flow_info.comment().clone())
};

let stmt = CreateFlow {
flow_name: sql::ast::ObjectName::from(vec![Ident::new(flow_info.flow_name())]),
sink_table_name: sql::ast::ObjectName::from(vec![Ident::new(
&flow_info.sink_table_name().table_name,
)]),
or_replace: false,
if_not_exists: true,
expire_after: flow_info.expire_after(),
eval_interval: flow_info.eval_interval(),
comment,
query,
};

Ok(stmt.to_string())
}

fn builder(&self) -> InformationSchemaFlowsBuilder {
InformationSchemaFlowsBuilder::new(
self.schema.clone(),
Expand Down Expand Up @@ -291,7 +340,10 @@ impl InformationSchemaFlowsBuilder {
.and_then(|state| state.state_size.get(&flow_id).map(|v| *v as u64)),
);
self.table_catalogs.push(Some(flow_info.catalog_name()));
self.raw_sqls.push(Some(flow_info.raw_sql()));
self.raw_sqls
.push(Some(&InformationSchemaFlows::generate_show_create_flow(
&flow_info,
)?));
self.comments.push(Some(flow_info.comment()));
self.expire_afters.push(flow_info.expire_after());
self.source_table_id_groups.push(Some(
Expand Down
Loading
Loading