mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
moved file from this repo to documentation repo (#2232)
This commit is contained in:
parent
3c56b0e63e
commit
297b4de815
1 changed files with 0 additions and 268 deletions
268
sql3/sql3.ebnf
268
sql3/sql3.ebnf
|
|
@ -1,268 +0,0 @@
|
|||
(*
|
||||
|
||||
sql3
|
||||
==========================
|
||||
|
||||
Document the SQL language support in FeatureBase
|
||||
|
||||
*)
|
||||
|
||||
sql3 = statement, [ ";" ] ;
|
||||
|
||||
statement = show_tables
|
||||
| show_columns
|
||||
| drop_table
|
||||
| create_table_stmt
|
||||
| alter_table_stmt
|
||||
| select_stmt
|
||||
| insert_stmt
|
||||
| bulk_insert_stmt
|
||||
| delete_stmt ;
|
||||
|
||||
(*
|
||||
|
||||
SHOW TABLES
|
||||
----------------
|
||||
Shows the tables within a FeatureBase instance.
|
||||
|
||||
*)
|
||||
show_tables = "SHOW", "TABLES" ;
|
||||
|
||||
(*
|
||||
|
||||
SHOW COLUMNS
|
||||
----------------
|
||||
Shows the columns on a FeatureBase table.
|
||||
|
||||
*)
|
||||
show_columns = "SHOW", "COLUMNS", "FROM", identifier ;
|
||||
|
||||
(*
|
||||
|
||||
DROP TABLE
|
||||
----------------
|
||||
Drops a FeatureBase table.
|
||||
|
||||
*)
|
||||
drop_table = "DROP", "TABLE", [ "IF", "EXISTS" ], identifier ;
|
||||
|
||||
|
||||
(*
|
||||
|
||||
CREATE TABLE
|
||||
----------------
|
||||
Creates a FeatureBase table.
|
||||
|
||||
*)
|
||||
create_table_stmt = "CREATE", "TABLE", [ "IF", "NOT", "EXISTS" ], identifier, "(", column_def, { ",", column_def }, ")", { table_options } ;
|
||||
|
||||
column_def = identifier, type_name, { column_constraint } ;
|
||||
|
||||
(*
|
||||
|
||||
Column Constraint
|
||||
----------------
|
||||
Constraints for a column:
|
||||
|
||||
MIN, MAX - min/max for int types
|
||||
|
||||
TIMEUNIT - 's', 'ms' etc.
|
||||
|
||||
TIMEQUANTUM - 'YMD' etc.
|
||||
|
||||
*)
|
||||
column_constraint =
|
||||
"MIN", integer_literal
|
||||
| "MAX", integer_literal
|
||||
| "TIMEUNIT", string_literal, [ "EPOCH", date_literal ]
|
||||
| "TIMEQUANTUM", string_literal, [ "TTL", string_literal ]
|
||||
| "CACHETYPE", ( "RANKED" | "LRU" ), [ "SIZE", integer_literal ] ;
|
||||
|
||||
table_options = "KEYPARTITIONS", integer_literal
|
||||
| "SHARDWIDTH", integer_literal ;
|
||||
|
||||
type_name = "INT"
|
||||
| "BOOL"
|
||||
| "TIMESTAMP"
|
||||
| "DECIMAL"
|
||||
| "STRING"
|
||||
| "STRINGSET"
|
||||
| "ID"
|
||||
| "IDSET" ;
|
||||
|
||||
(*
|
||||
|
||||
ALTER TABLE
|
||||
----------------
|
||||
Alters a FeatureBase table.
|
||||
|
||||
*)
|
||||
alter_table_stmt = "ALTER", "TABLE", ( add_column | drop_column | rename_column ) ;
|
||||
|
||||
add_column = "ADD", [ "COLUMN" ], column_def ;
|
||||
|
||||
drop_column = "DROP", [ "COLUMN" ], identifier ;
|
||||
|
||||
rename_column = "RENAME", [ "COLUMN" ], identifier, "TO", identifier ;
|
||||
|
||||
(*
|
||||
|
||||
INSERT
|
||||
----------------
|
||||
Inserts data into a FeatureBase table.
|
||||
|
||||
*)
|
||||
insert_stmt = ( "INSERT" | "REPLACE" ), "INTO", identifier, [ "(", identifier, { identifier, "," }, ")" ], "VALUES", "(", expr, { expr, "," }, ")" ;
|
||||
|
||||
(*
|
||||
|
||||
BULK INSERT
|
||||
----------------
|
||||
Bulk inserts data into a FeatureBase table.
|
||||
|
||||
*)
|
||||
bulk_insert_stmt = "BULK", "INSERT", identifier, "FROM", string_literal, [ "WITH", bulk_insert_option, { bulk_insert_option } ];
|
||||
|
||||
bulk_insert_option =
|
||||
"BATCHSIZE", integer_literal
|
||||
| "ROWSLIMIT", integer_literal
|
||||
| "FORMAT", "CSV"
|
||||
| bulk_insert_map_option ;
|
||||
|
||||
bulk_insert_map_option = "MAP", map_id_option | map_column_option ;
|
||||
|
||||
map_id_option = "_ID", "TO", ( "AUTOINCREMENT" | expr, { ",", expr } );
|
||||
|
||||
map_column_option = "OFFSET", integer_literal, "TO", column_name ;
|
||||
|
||||
(*
|
||||
|
||||
DELETE
|
||||
----------------
|
||||
Deletes data from a FeatureBase table.
|
||||
|
||||
*)
|
||||
delete_stmt = "DELETE" ;
|
||||
|
||||
(*
|
||||
|
||||
SELECT
|
||||
----------------
|
||||
Queries a FeatureBase table.
|
||||
|
||||
*)
|
||||
select_stmt = "SELECT", [ top_clause ], [ "DISTINCT" ], result_column, { ",", result_column }, [ from_clause ], [ where_clause ], [group_by_clause] ;
|
||||
|
||||
top_clause = ( "TOP" | "TOPN" ), "(", expr, ")" ;
|
||||
|
||||
result_column = expr, [ [ "AS" ], column_alias ]
|
||||
| "*"
|
||||
| identifier, ".", "*" ;
|
||||
|
||||
column_alias = identifier ;
|
||||
|
||||
from_clause = "FROM", table_or_subquery, { ",", table_or_subquery } ;
|
||||
|
||||
table_or_subquery =
|
||||
( identifier | table_valued_function ), [ [ "AS" ], table_alias ], [ table_option ]
|
||||
| "(", select_stmt, ")", [ [ "AS" ], table_alias ] ;
|
||||
|
||||
table_alias = identifier ;
|
||||
|
||||
table_option = "SHARDS", "(", integer_literal, { ",", integer_literal }, ")";
|
||||
|
||||
where_clause = "WHERE", expr ;
|
||||
|
||||
group_by_clause = "GROUP", "BY", expr, { ",", expr }, [ "HAVING", expr ] ;
|
||||
|
||||
(*
|
||||
|
||||
Expressions
|
||||
----------------
|
||||
|
||||
*)
|
||||
expr = integer_literal
|
||||
| string_literal
|
||||
| decimal_literal
|
||||
| set_literal
|
||||
| tuple_literal
|
||||
| date_literal
|
||||
| [ table_name, "." ], column_name
|
||||
| unary_op, expr
|
||||
| expr, binary_op, expr
|
||||
| function_call
|
||||
| "(", expr, ")"
|
||||
| "CAST", "(", expr, "AS", type_name, ")"
|
||||
| expr, [ "NOT" ], "LIKE", expr
|
||||
| expr, "IS", [ "NOT" ], "NULL"
|
||||
| expr, [ "NOT" ], "BETWEEN", expr, "AND", expr
|
||||
| expr, [ "NOT" ], "IN", "(", ( select_stmt | expr, { ",", expr } ), ")"
|
||||
| paren_select_stmt
|
||||
| case_expr ;
|
||||
|
||||
paren_select_stmt = "(", select_stmt, ")" ;
|
||||
|
||||
case_expr = "CASE", [ expr ], { "WHEN", expr, "THEN", expr }, [ "ELSE", expr ], "END" ;
|
||||
|
||||
unary_op = "-"
|
||||
| "+"
|
||||
| "!" ;
|
||||
|
||||
binary_op = "="
|
||||
| "!="
|
||||
| "<="
|
||||
| ">="
|
||||
| "&"
|
||||
| "|"
|
||||
| "<<"
|
||||
| ">>"
|
||||
| "+"
|
||||
| "-"
|
||||
| "*"
|
||||
| "/"
|
||||
| "%"
|
||||
| "||" ;
|
||||
|
||||
set_literal = "[", expr, { ",", expr }, "]" ;
|
||||
|
||||
tuple_literal = "{", expr, { ",", expr }, "}" ;
|
||||
|
||||
date_literal = rfc_3339
|
||||
| "CURRENT_DATE"
|
||||
| "CURRENT_TIMESTAMP" ;
|
||||
|
||||
table_name = identifier ;
|
||||
|
||||
column_name = identifier ;
|
||||
|
||||
function_call = agg_function
|
||||
| non_agg_function
|
||||
| table_valued_function ;
|
||||
|
||||
agg_function = ( "AVG" | "COUNT" | "MAX" | "MIN" | "SUM" ), "(", ( ( [ "DISTINCT" ], expr ) | "*" ), ")"
|
||||
| "PERCENTILE", "(", expr, ",", expr, ")" ;
|
||||
|
||||
non_agg_function =
|
||||
"SETCONTAINS" , "(", expr, ",", expr, ")"
|
||||
| "SETCONTAINSALL" , "(", expr, ",", expr, ")"
|
||||
| "SETCONTAINSANY" , "(", expr, ",", expr, ")"
|
||||
| "DATEPART" , "(", expr, ",", expr, ")" ;
|
||||
|
||||
table_valued_function =
|
||||
"SUBTABLE" , "(", table_name, ".", column_name, ")";
|
||||
|
||||
|
||||
identifier = letter , { letter | digit | "_" } ;
|
||||
|
||||
letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
|
||||
| "H" | "I" | "J" | "K" | "L" | "M" | "N"
|
||||
| "O" | "P" | "Q" | "R" | "S" | "T" | "U"
|
||||
| "V" | "W" | "X" | "Y" | "Z" | "a" | "b"
|
||||
| "c" | "d" | "e" | "f" | "g" | "h" | "i"
|
||||
| "j" | "k" | "l" | "m" | "n" | "o" | "p"
|
||||
| "q" | "r" | "s" | "t" | "u" | "v" | "w"
|
||||
| "x" | "y" | "z" ;
|
||||
|
||||
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
|
||||
|
||||
|
||||
Loading…
Add table
Reference in a new issue