Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: const aliases and read_xlsx alias #2657

Merged
merged 4 commits into from
Feb 21, 2024
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
10 changes: 10 additions & 0 deletions crates/sqlbuiltins/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub trait ConstBuiltinFunction: Sync + Send {
const DESCRIPTION: &'static str;
const EXAMPLE: &'static str;
const FUNCTION_TYPE: FunctionType;
const ALIASES: &'static [&'static str] = &[];

fn signature(&self) -> Option<Signature> {
None
}
Expand Down Expand Up @@ -137,18 +139,26 @@ where
fn name(&self) -> &str {
Self::NAME
}

fn sql_example(&self) -> Option<&str> {
Some(Self::EXAMPLE)
}

fn description(&self) -> Option<&str> {
Some(Self::DESCRIPTION)
}

fn function_type(&self) -> FunctionType {
Self::FUNCTION_TYPE
}

fn signature(&self) -> Option<Signature> {
self.signature()
}

fn aliases(&self) -> &[&str] {
Self::ALIASES
}
}

/// Builtin Functions available for all sessions.
Expand Down
2 changes: 2 additions & 0 deletions crates/sqlbuiltins/src/functions/table/excel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ impl ConstBuiltinFunction for ExcelScan {
const EXAMPLE: &'static str =
"SELECT * FROM read_excel('file:///path/to/file.xlsx', sheet_name => 'Sheet1')";
const FUNCTION_TYPE: FunctionType = FunctionType::TableReturning;
const ALIASES: &'static [&'static str] = &["read_xlsx"];

fn signature(&self) -> Option<Signature> {
let options: Fields = vec![
Field::new("sheet_name", DataType::Utf8, true),
Expand Down
8 changes: 7 additions & 1 deletion testdata/sqllogictests/xlsx.slt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ select count(*) from read_excel('./testdata/xlsx/userdata1.xlsx', has_header =>
----
1000

query 1
query I
select count(*) from read_excel('./testdata/xlsx/userdata1.xlsx', has_header => false);
----
1001


query I
select count(*) from read_xlsx('${PWD}/testdata/xlsx/userdata1.xlsx');
----
1000


# infer rows
statement ok
select count(*) from read_excel(
Expand Down
Loading