pub struct ParserContext<'a> {
pub(crate) parser: Parser<'a>,
pub(crate) sql: &'a str,
}
Expand description
GrepTime SQL parser context, a simple wrapper for Datafusion SQL parser.
Fields§
§parser: Parser<'a>
§sql: &'a str
Implementations§
source§impl ParserContext<'_>
impl ParserContext<'_>
sourcepub fn new<'a>(
dialect: &'a dyn Dialect,
sql: &'a str,
) -> Result<ParserContext<'a>>
pub fn new<'a>( dialect: &'a dyn Dialect, sql: &'a str, ) -> Result<ParserContext<'a>>
Construct a new ParserContext.
sourcepub fn parser_query(&mut self) -> Result<Box<Query>>
pub fn parser_query(&mut self) -> Result<Box<Query>>
Parses parser context to Query.
sourcepub fn create_with_dialect(
sql: &str,
dialect: &dyn Dialect,
_opts: ParseOptions,
) -> Result<Vec<Statement>>
pub fn create_with_dialect( sql: &str, dialect: &dyn Dialect, _opts: ParseOptions, ) -> Result<Vec<Statement>>
Parses SQL with given dialect
pub fn parse_table_name(sql: &str, dialect: &dyn Dialect) -> Result<ObjectName>
pub(crate) fn intern_parse_table_name(&mut self) -> Result<ObjectName>
pub fn parse_function(sql: &str, dialect: &dyn Dialect) -> Result<Expr>
sourcepub fn parse_statement(&mut self) -> Result<Statement>
pub fn parse_statement(&mut self) -> Result<Statement>
Parses parser context to a set of statements.
sourcepub fn parse_mysql_prepare_stmt(
sql: &str,
dialect: &dyn Dialect,
) -> Result<(String, String)>
pub fn parse_mysql_prepare_stmt( sql: &str, dialect: &dyn Dialect, ) -> Result<(String, String)>
Parses MySQL style ‘PREPARE stmt_name FROM stmt’ into a (stmt_name, stmt) tuple.
sourcepub fn parse_mysql_execute_stmt(
sql: &str,
dialect: &dyn Dialect,
) -> Result<(String, Vec<Expr>)>
pub fn parse_mysql_execute_stmt( sql: &str, dialect: &dyn Dialect, ) -> Result<(String, Vec<Expr>)>
Parses MySQL style ‘EXECUTE stmt_name USING param_list’ into a stmt_name string and a list of parameters.
sourcepub fn parse_mysql_deallocate_stmt(
sql: &str,
dialect: &dyn Dialect,
) -> Result<String>
pub fn parse_mysql_deallocate_stmt( sql: &str, dialect: &dyn Dialect, ) -> Result<String>
Parses MySQL style ‘DEALLOCATE stmt_name’ into a stmt_name string.
sourcepub fn unsupported<T>(&self, keyword: String) -> Result<T>
pub fn unsupported<T>(&self, keyword: String) -> Result<T>
Raises an “unsupported statement” error.
pub(crate) fn expected<T>( &self, expected: &str, found: TokenWithLocation, ) -> Result<T>
pub fn matches_keyword(&mut self, expected: Keyword) -> bool
pub fn consume_token(&mut self, expected: &str) -> bool
pub(crate) fn peek_token_as_string(&self) -> String
sourcepub fn canonicalize_identifier(ident: Ident) -> Ident
pub fn canonicalize_identifier(ident: Ident) -> Ident
Canonicalize the identifier to lowercase if it’s not quoted.
sourcepub fn canonicalize_object_name(object_name: ObjectName) -> ObjectName
pub fn canonicalize_object_name(object_name: ObjectName) -> ObjectName
Like [canonicalize_identifier] but for ObjectName.
sourcepub(crate) fn parse_object_name(&mut self) -> Result<ObjectName, ParserError>
pub(crate) fn parse_object_name(&mut self) -> Result<ObjectName, ParserError>
Simply a shortcut for sqlparser’s same name method parse_object_name
,
but with constant argument “false”.
Because the argument is always “false” for us (it’s introduced by BigQuery),
we don’t want to write it again and again.
sourcepub(crate) fn parse_identifier(&mut self) -> Result<Ident, ParserError>
pub(crate) fn parse_identifier(&mut self) -> Result<Ident, ParserError>
Simply a shortcut for sqlparser’s same name method parse_identifier
,
but with constant argument “false”.
Because the argument is always “false” for us (it’s introduced by BigQuery),
we don’t want to write it again and again.
source§impl ParserContext<'_>
impl ParserContext<'_>
admin
extension parser: admin function(arg1, arg2, ...)
or admin function
sourcepub(crate) fn parse_admin_command(&mut self) -> Result<Statement>
pub(crate) fn parse_admin_command(&mut self) -> Result<Statement>
Parse admin function(arg1, arg2, ...)
or admin function
statement
source§impl ParserContext<'_>
impl ParserContext<'_>
pub(crate) fn parse_alter(&mut self) -> Result<Statement>
fn parse_alter_table(&mut self) -> Result<AlterTable>
fn parse_alter_table_add(&mut self) -> Result<AlterTableOperation>
fn parse_alter_table_modify(&mut self) -> Result<AlterTableOperation>
fn parse_alter_column_fulltext( &mut self, column_name: Ident, ) -> Result<AlterTableOperation>
source§impl ParserContext<'_>
impl ParserContext<'_>
pub(crate) fn parse_copy(&mut self) -> Result<Statement>
fn parser_copy_database(&mut self) -> Result<CopyDatabase>
fn parse_copy_table(&mut self) -> Result<CopyTable>
fn parse_copy_parameters( &mut self, ) -> Result<(HashMap<String, String>, HashMap<String, String>, String, Option<u64>)>
source§impl<'a> ParserContext<'a>
impl<'a> ParserContext<'a>
Parses create table statement
pub(crate) fn parse_create(&mut self) -> Result<Statement>
sourcefn parse_create_view(&mut self, or_replace: bool) -> Result<Statement>
fn parse_create_view(&mut self, or_replace: bool) -> Result<Statement>
Parse CREAVE VIEW
statement.
fn parse_view_columns(&mut self) -> Result<Vec<Ident>>
fn parse_create_external_table(&mut self) -> Result<Statement>
fn parse_create_database(&mut self) -> Result<Statement>
fn parse_create_table(&mut self) -> Result<Statement>
sourcefn parse_create_flow(&mut self, or_replace: bool) -> Result<Statement>
fn parse_create_flow(&mut self, or_replace: bool) -> Result<Statement>
“CREATE FLOW” clause
fn parse_if_not_exist(&mut self) -> Result<bool>
fn parse_create_table_options(&mut self) -> Result<OptionMap>
sourcefn parse_partitions(&mut self) -> Result<Option<Partitions>>
fn parse_partitions(&mut self) -> Result<Option<Partitions>>
“PARTITION ON COLUMNS (…)” clause
fn parse_partition_entry(&mut self) -> Result<Expr>
sourcefn parse_comma_separated<T, F>(&mut self, f: F) -> Result<Vec<T>>
fn parse_comma_separated<T, F>(&mut self, f: F) -> Result<Vec<T>>
Parse a comma-separated list wrapped by “()”, and of which all items accepted by F
fn parse_columns(&mut self) -> Result<(Vec<Column>, Vec<TableConstraint>)>
fn parse_column( &mut self, columns: &mut Vec<Column>, constraints: &mut Vec<TableConstraint>, ) -> Result<()>
sourcefn parse_column_name(&mut self) -> Result<Ident, ParserError>
fn parse_column_name(&mut self) -> Result<Ident, ParserError>
Parse the column name and check if it’s valid.
pub fn parse_column_def(&mut self) -> Result<Column>
fn parse_optional_column_option( parser: &mut Parser<'_>, ) -> Result<Option<ColumnOption>>
fn parse_column_extensions( parser: &mut Parser<'_>, column_name: &Ident, column_type: &DataType, column_extensions: &mut ColumnExtensions, ) -> Result<bool>
fn parse_optional_table_constraint(&mut self) -> Result<Option<TableConstraint>>
sourcefn parse_table_engine(&mut self, default: &str) -> Result<String>
fn parse_table_engine(&mut self, default: &str) -> Result<String>
Parses the set of valid formats
source§impl ParserContext<'_>
impl ParserContext<'_>
sourcepub(crate) fn parse_deallocate(&mut self) -> Result<String>
pub(crate) fn parse_deallocate(&mut self) -> Result<String>
Parses MySQL style ‘PREPARE stmt_name’ into a stmt_name string.
source§impl ParserContext<'_>
impl ParserContext<'_>
DELETE statement parser implementation
pub(crate) fn parse_delete(&mut self) -> Result<Statement>
source§impl ParserContext<'_>
impl ParserContext<'_>
DESCRIBE statement parser implementation
pub(crate) fn parse_describe(&mut self) -> Result<Statement>
fn parse_describe_table(&mut self) -> Result<Statement>
source§impl ParserContext<'_>
impl ParserContext<'_>
DROP statement parser implementation
pub(crate) fn parse_drop(&mut self) -> Result<Statement>
fn parse_drop_view(&mut self) -> Result<Statement>
fn parse_drop_flow(&mut self) -> Result<Statement>
fn parse_drop_table(&mut self) -> Result<Statement>
fn parse_drop_database(&mut self) -> Result<Statement>
source§impl ParserContext<'_>
impl ParserContext<'_>
source§impl ParserContext<'_>
impl ParserContext<'_>
EXPLAIN statement parser implementation
pub(crate) fn parse_explain(&mut self) -> Result<Statement>
source§impl ParserContext<'_>
impl ParserContext<'_>
INSERT statement parser implementation
pub(crate) fn parse_insert(&mut self) -> Result<Statement>
source§impl ParserContext<'_>
impl ParserContext<'_>
sourcepub(crate) fn parse_mysql_prepare(&mut self) -> Result<(String, String)>
pub(crate) fn parse_mysql_prepare(&mut self) -> Result<(String, String)>
Parses MySQL style ‘PREPARE stmt_name FROM stmt’ into a (stmt_name, stmt) tuple.
Only use for MySQL. for PostgreSQL, use sqlparser::parser::Parser::parse_prepare
instead.
source§impl ParserContext<'_>
impl ParserContext<'_>
sourcepub(crate) fn parse_query(&mut self) -> Result<Statement>
pub(crate) fn parse_query(&mut self) -> Result<Statement>
Parses select and it’s variants.
source§impl ParserContext<'_>
impl ParserContext<'_>
SET variables statement parser implementation
pub(crate) fn parse_set_variables(&mut self) -> Result<Statement>
source§impl ParserContext<'_>
impl ParserContext<'_>
SHOW statement parser implementation
sourcepub(crate) fn parse_show(&mut self) -> Result<Statement>
pub(crate) fn parse_show(&mut self) -> Result<Statement>
Parses SHOW statements
todo(hl) support show settings
/show create
/show users
etc.
fn parse_show_create_database(&mut self) -> Result<Statement>
sourcefn parse_show_create_table(&mut self) -> Result<Statement>
fn parse_show_create_table(&mut self) -> Result<Statement>
Parse SHOW CREATE TABLE statement
fn parse_show_create_flow(&mut self) -> Result<Statement>
fn parse_show_create_view(&mut self) -> Result<Statement>
fn parse_show_table_name(&mut self) -> Result<String>
fn parse_db_name(&mut self) -> Result<Option<String>>
fn parse_show_columns(&mut self, full: bool) -> Result<Statement>
fn parse_show_kind(&mut self) -> Result<ShowKind>
fn parse_show_index(&mut self) -> Result<Statement>
fn parse_show_tables(&mut self, full: bool) -> Result<Statement>
fn parse_show_table_status(&mut self) -> Result<Statement>
sourcepub fn parse_show_databases(&mut self, full: bool) -> Result<Statement>
pub fn parse_show_databases(&mut self, full: bool) -> Result<Statement>
Parses SHOW DATABASES
statement.
fn parse_show_views(&mut self) -> Result<Statement>
fn parse_show_flows(&mut self) -> Result<Statement>
source§impl ParserContext<'_>
impl ParserContext<'_>
TQL extension parser, including:
TQL EVAL <query>
TQL EXPLAIN [VERBOSE] <query>
TQL ANALYZE [VERBOSE] <query>
pub(crate) fn parse_tql(&mut self) -> Result<Statement>
fn parse_tql_params(&mut self) -> Result<TqlParameters, TQLError>
pub fn comma_or_rparen(token: &Token) -> bool
fn is_comma(token: &Token) -> bool
fn is_rparen(token: &Token) -> bool
fn has_verbose_keyword(&mut self) -> bool
sourcefn parse_string_or_number_or_word(
parser: &mut Parser<'_>,
delimiter_tokens: &[Token],
) -> Result<(String, Token), TQLError>
fn parse_string_or_number_or_word( parser: &mut Parser<'_>, delimiter_tokens: &[Token], ) -> Result<(String, Token), TQLError>
Try to parse and consume a string, number or word token.
Return Ok
if it’s parsed and one of the given delimiter tokens is consumed.
The string and matched delimiter will be returned as a tuple.
fn parse_tokens(tokens: Vec<Token>) -> Result<String, TQLError>
fn parse_to_expr(tokens: Vec<Token>) -> Result<Expr, TQLError>
fn parse_tql_query( parser: &mut Parser<'_>, sql: &str, ) -> Result<String, ParserError>
source§impl ParserContext<'_>
impl ParserContext<'_>
TRUNCATE [TABLE] table_name;
pub(crate) fn parse_truncate(&mut self) -> Result<Statement>
Auto Trait Implementations§
impl<'a> Freeze for ParserContext<'a>
impl<'a> !RefUnwindSafe for ParserContext<'a>
impl<'a> !Send for ParserContext<'a>
impl<'a> !Sync for ParserContext<'a>
impl<'a> Unpin for ParserContext<'a>
impl<'a> !UnwindSafe for ParserContext<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T, V> Convert<T> for Vwhere
V: Into<T>,
impl<T, V> Convert<T> for Vwhere
V: Into<T>,
fn convert(value: Self) -> T
fn convert_box(value: Box<Self>) -> Box<T>
fn convert_vec(value: Vec<Self>) -> Vec<T>
fn convert_vec_box(value: Vec<Box<Self>>) -> Vec<Box<T>>
fn convert_matrix(value: Vec<Vec<Self>>) -> Vec<Vec<T>>
fn convert_option(value: Option<Self>) -> Option<T>
fn convert_option_box(value: Option<Box<Self>>) -> Option<Box<T>>
fn convert_option_vec(value: Option<Vec<Self>>) -> Option<Vec<T>>
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.