-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Update sql doc #6025
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
Merged
Merged
Update sql doc #6025
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,12 +313,13 @@ impl FromStr for BuiltinScalarFunction { | |
// math functions | ||
"abs" => BuiltinScalarFunction::Abs, | ||
"acos" => BuiltinScalarFunction::Acos, | ||
"asin" => BuiltinScalarFunction::Asin, | ||
"atan" => BuiltinScalarFunction::Atan, | ||
"acosh" => BuiltinScalarFunction::Acosh, | ||
"asin" => BuiltinScalarFunction::Asin, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
"asinh" => BuiltinScalarFunction::Asinh, | ||
"atan" => BuiltinScalarFunction::Atan, | ||
"atanh" => BuiltinScalarFunction::Atanh, | ||
"atan2" => BuiltinScalarFunction::Atan2, | ||
"cbrt" => BuiltinScalarFunction::Cbrt, | ||
"ceil" => BuiltinScalarFunction::Ceil, | ||
"cos" => BuiltinScalarFunction::Cos, | ||
"cosh" => BuiltinScalarFunction::Cosh, | ||
|
@@ -330,21 +331,19 @@ impl FromStr for BuiltinScalarFunction { | |
"log2" => BuiltinScalarFunction::Log2, | ||
"pi" => BuiltinScalarFunction::Pi, | ||
"power" | "pow" => BuiltinScalarFunction::Power, | ||
"random" => BuiltinScalarFunction::Random, | ||
"round" => BuiltinScalarFunction::Round, | ||
"signum" => BuiltinScalarFunction::Signum, | ||
"sin" => BuiltinScalarFunction::Sin, | ||
"sinh" => BuiltinScalarFunction::Sinh, | ||
"sqrt" => BuiltinScalarFunction::Sqrt, | ||
"cbrt" => BuiltinScalarFunction::Cbrt, | ||
"tan" => BuiltinScalarFunction::Tan, | ||
"tanh" => BuiltinScalarFunction::Tanh, | ||
"trunc" => BuiltinScalarFunction::Trunc, | ||
|
||
// conditional functions | ||
"coalesce" => BuiltinScalarFunction::Coalesce, | ||
|
||
// array functions | ||
"make_array" => BuiltinScalarFunction::MakeArray, | ||
"nullif" => BuiltinScalarFunction::NullIf, | ||
|
||
// string functions | ||
"ascii" => BuiltinScalarFunction::Ascii, | ||
|
@@ -355,51 +354,61 @@ impl FromStr for BuiltinScalarFunction { | |
"concat" => BuiltinScalarFunction::Concat, | ||
"concat_ws" => BuiltinScalarFunction::ConcatWithSeparator, | ||
"chr" => BuiltinScalarFunction::Chr, | ||
"current_date" => BuiltinScalarFunction::CurrentDate, | ||
"current_time" => BuiltinScalarFunction::CurrentTime, | ||
"date_part" | "datepart" => BuiltinScalarFunction::DatePart, | ||
"date_trunc" | "datetrunc" => BuiltinScalarFunction::DateTrunc, | ||
"date_bin" => BuiltinScalarFunction::DateBin, | ||
"initcap" => BuiltinScalarFunction::InitCap, | ||
"left" => BuiltinScalarFunction::Left, | ||
"length" => BuiltinScalarFunction::CharacterLength, | ||
"lower" => BuiltinScalarFunction::Lower, | ||
"lpad" => BuiltinScalarFunction::Lpad, | ||
"ltrim" => BuiltinScalarFunction::Ltrim, | ||
"md5" => BuiltinScalarFunction::MD5, | ||
"nullif" => BuiltinScalarFunction::NullIf, | ||
"octet_length" => BuiltinScalarFunction::OctetLength, | ||
"random" => BuiltinScalarFunction::Random, | ||
"regexp_replace" => BuiltinScalarFunction::RegexpReplace, | ||
"repeat" => BuiltinScalarFunction::Repeat, | ||
"replace" => BuiltinScalarFunction::Replace, | ||
"reverse" => BuiltinScalarFunction::Reverse, | ||
"right" => BuiltinScalarFunction::Right, | ||
"rpad" => BuiltinScalarFunction::Rpad, | ||
"rtrim" => BuiltinScalarFunction::Rtrim, | ||
"sha224" => BuiltinScalarFunction::SHA224, | ||
"sha256" => BuiltinScalarFunction::SHA256, | ||
"sha384" => BuiltinScalarFunction::SHA384, | ||
"sha512" => BuiltinScalarFunction::SHA512, | ||
"digest" => BuiltinScalarFunction::Digest, | ||
"split_part" => BuiltinScalarFunction::SplitPart, | ||
"starts_with" => BuiltinScalarFunction::StartsWith, | ||
"strpos" => BuiltinScalarFunction::Strpos, | ||
"substr" => BuiltinScalarFunction::Substr, | ||
"to_hex" => BuiltinScalarFunction::ToHex, | ||
"to_timestamp" => BuiltinScalarFunction::ToTimestamp, | ||
"to_timestamp_millis" => BuiltinScalarFunction::ToTimestampMillis, | ||
"to_timestamp_micros" => BuiltinScalarFunction::ToTimestampMicros, | ||
"to_timestamp_seconds" => BuiltinScalarFunction::ToTimestampSeconds, | ||
"now" => BuiltinScalarFunction::Now, | ||
"translate" => BuiltinScalarFunction::Translate, | ||
"trim" => BuiltinScalarFunction::Trim, | ||
"upper" => BuiltinScalarFunction::Upper, | ||
"uuid" => BuiltinScalarFunction::Uuid, | ||
|
||
// regex functions | ||
"regexp_match" => BuiltinScalarFunction::RegexpMatch, | ||
"struct" => BuiltinScalarFunction::Struct, | ||
"regexp_replace" => BuiltinScalarFunction::RegexpReplace, | ||
|
||
// time/date functions | ||
"now" => BuiltinScalarFunction::Now, | ||
"current_date" => BuiltinScalarFunction::CurrentDate, | ||
"current_time" => BuiltinScalarFunction::CurrentTime, | ||
"date_bin" => BuiltinScalarFunction::DateBin, | ||
"date_trunc" | "datetrunc" => BuiltinScalarFunction::DateTrunc, | ||
"date_part" | "datepart" => BuiltinScalarFunction::DatePart, | ||
"to_timestamp" => BuiltinScalarFunction::ToTimestamp, | ||
"to_timestamp_millis" => BuiltinScalarFunction::ToTimestampMillis, | ||
"to_timestamp_micros" => BuiltinScalarFunction::ToTimestampMicros, | ||
"to_timestamp_seconds" => BuiltinScalarFunction::ToTimestampSeconds, | ||
"from_unixtime" => BuiltinScalarFunction::FromUnixtime, | ||
|
||
// hashing functions | ||
"digest" => BuiltinScalarFunction::Digest, | ||
"md5" => BuiltinScalarFunction::MD5, | ||
"sha224" => BuiltinScalarFunction::SHA224, | ||
"sha256" => BuiltinScalarFunction::SHA256, | ||
"sha384" => BuiltinScalarFunction::SHA384, | ||
"sha512" => BuiltinScalarFunction::SHA512, | ||
|
||
// other functions | ||
"struct" => BuiltinScalarFunction::Struct, | ||
"arrow_typeof" => BuiltinScalarFunction::ArrowTypeof, | ||
|
||
// array functions | ||
"make_array" => BuiltinScalarFunction::MakeArray, | ||
|
||
_ => { | ||
return Err(DataFusionError::Plan(format!( | ||
"There is no built-in function named {name}" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,32 @@ | |
|
||
# DDL | ||
|
||
## CREATE DATABASE | ||
|
||
Create catalog with specified name. | ||
|
||
<pre> | ||
CREATE DATABASE [ IF NOT EXISTS ] <i><b>catalog</i></b> | ||
</pre> | ||
|
||
```sql | ||
-- create catalog cat | ||
CREATE DATABASE cat; | ||
``` | ||
|
||
## CREATE SCHEMA | ||
|
||
Create schema under specified catalog, or the default DataFusion catalog if not specified. | ||
|
||
<pre> | ||
CREATE SCHEMA [ IF NOT EXISTS ] [ <i><b>catalog.</i></b> ] <b><i>schema_name</i></b> | ||
</pre> | ||
|
||
```sql | ||
-- create schema emu under catalog cat | ||
CREATE SCHEMA cat.emu; | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know this worked ❤️ but I tried it out
|
||
|
||
## CREATE EXTERNAL TABLE | ||
|
||
Parquet data sources can be registered by executing a `CREATE EXTERNAL TABLE` SQL statement. It is not necessary | ||
|
@@ -67,7 +93,7 @@ When creating an output from a data source that is already ordered by an express | |
the data using the `WITH ORDER` clause. This applies even if the expression used for sorting is complex, | ||
allowing for greater flexibility. | ||
|
||
Here's an example of how to use `WITH ORDER` query | ||
Here's an example of how to use `WITH ORDER` clause. | ||
|
||
```sql | ||
CREATE EXTERNAL TABLE test ( | ||
|
@@ -91,14 +117,14 @@ WITH ORDER (c2 ASC, c5 + c8 DESC NULL FIRST) | |
LOCATION '/path/to/aggregate_test_100.csv'; | ||
``` | ||
|
||
where `WITH ORDER` clause specifies the sort order: | ||
Where `WITH ORDER` clause specifies the sort order: | ||
|
||
```sql | ||
WITH ORDER (sort_expression1 [ASC | DESC] [NULLS { FIRST | LAST }] | ||
[, sort_expression2 [ASC | DESC] [NULLS { FIRST | LAST }] ...]) | ||
``` | ||
|
||
### Cautions When Using the WITH ORDER Clause | ||
### Cautions when using the WITH ORDER Clause | ||
|
||
- It's important to understand that using the `WITH ORDER` clause in the `CREATE EXTERNAL TABLE` statement only specifies the order in which the data should be read from the external file. If the data in the file is not already sorted according to the specified order, then the results may not be correct. | ||
|
||
|
@@ -153,7 +179,7 @@ DROP TABLE IF EXISTS nonexistent_table; | |
View is a virtual table based on the result of a SQL query. It can be created from an existing table or values list. | ||
|
||
<pre> | ||
CREATE VIEW <i><b>view_name</b></i> AS statement; | ||
CREATE [ OR REPLACE ] VIEW <i><b>view_name</b></i> AS statement; | ||
</pre> | ||
|
||
```sql | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just reorganizing, to be similar to how it looks in the sql doc, and group them together here a bit better