Skip to content

Commit

Permalink
feat: support show functions (#9398)
Browse files Browse the repository at this point in the history
  • Loading branch information
yezizp2012 committed Apr 24, 2023
1 parent b021f23 commit 27e9dae
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
14 changes: 14 additions & 0 deletions e2e_test/udf/python.slt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ create function jsonb_access(jsonb, int) returns jsonb language python as jsonb_
statement ok
create function jsonb_concat(jsonb[]) returns jsonb language python as jsonb_concat using link 'http://localhost:8815';

query TTTTT rowsort
show functions
----
array_access varchar[], integer varchar python http://localhost:8815
extract_tcp_info bytea struct<src_ip varchar,dst_ip varchar,src_port smallint,dst_port smallint> python http://localhost:8815
gcd integer, integer integer python http://localhost:8815
gcd integer, integer, integer integer python http://localhost:8815
hex_to_dec varchar numeric python http://localhost:8815
int_42 (empty) integer python http://localhost:8815
jsonb_access jsonb, integer jsonb python http://localhost:8815
jsonb_concat jsonb[] jsonb python http://localhost:8815
series integer integer python http://localhost:8815
series2 integer struct<x integer,y varchar> python http://localhost:8815

query I
select int_42();
----
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/catalog/schema_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ impl SchemaCatalog {
self.view_by_name.values()
}

pub fn iter_function(&self) -> impl Iterator<Item = &Arc<FunctionCatalog>> {
self.function_by_name.values().flat_map(|v| v.values())
}

pub fn iter_connections(&self) -> impl Iterator<Item = &Arc<ConnectionCatalog>> {
self.connection_by_name.values()
}
Expand Down
47 changes: 47 additions & 0 deletions src/frontend/src/handler/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,53 @@ pub fn handle_show_object(handler_args: HandlerArgs, command: ShowObject) -> Res
],
));
}
ShowObject::Function { schema } => {
let rows = catalog_reader
.get_schema_by_name(session.database(), &schema_or_default(&schema))?
.iter_function()
.map(|t| {
Row::new(vec![
Some(t.name.clone().into()),
Some(t.arg_types.iter().map(|t| t.to_string()).join(", ").into()),
Some(t.return_type.to_string().into()),
Some(t.language.clone().into()),
Some(t.link.clone().into()),
])
})
.collect_vec();
return Ok(PgResponse::new_for_stream(
StatementType::SHOW_COMMAND,
None,
rows.into(),
vec![
PgFieldDescriptor::new(
"Name".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Arguments".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Return Type".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Language".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Link".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
],
));
}
};

let rows = names
Expand Down
2 changes: 2 additions & 0 deletions src/sqlparser/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ pub enum ShowObject {
Sink { schema: Option<Ident> },
Columns { table: ObjectName },
Connection { schema: Option<Ident> },
Function { schema: Option<Ident> },
}

impl fmt::Display for ShowObject {
Expand Down Expand Up @@ -796,6 +797,7 @@ impl fmt::Display for ShowObject {
ShowObject::Sink { schema } => write!(f, "SINKS{}", fmt_schema(schema)),
ShowObject::Columns { table } => write!(f, "COLUMNS FROM {}", table),
ShowObject::Connection { schema } => write!(f, "CONNECTIONS{}", fmt_schema(schema)),
ShowObject::Function { schema } => write!(f, "FUNCTIONS{}", fmt_schema(schema)),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/sqlparser/src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ define_keywords!(
FROM,
FULL,
FUNCTION,
FUNCTIONS,
FUSION,
GET,
GLOBAL,
Expand Down
5 changes: 5 additions & 0 deletions src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3676,6 +3676,11 @@ impl Parser {
schema: self.parse_from_and_identifier()?,
}));
}
Keyword::FUNCTIONS => {
return Ok(Statement::ShowObjects(ShowObject::Function {
schema: self.parse_from_and_identifier()?,
}));
}
_ => {}
}
}
Expand Down

0 comments on commit 27e9dae

Please sign in to comment.