Skip to content

Commit 3d64de4

Browse files
authored
refactor: make SqlToRel::new derive the parser options from the context provider (#14822)
* derive sql parser options * fix
1 parent 99c811a commit 3d64de4

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

datafusion/sql/src/planner.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::sync::Arc;
2121
use std::vec;
2222

2323
use arrow::datatypes::*;
24+
use datafusion_common::config::SqlParserOptions;
2425
use datafusion_common::error::add_possible_columns_to_diag;
2526
use datafusion_common::{
2627
field_not_found, internal_err, plan_datafusion_err, DFSchemaRef, Diagnostic,
@@ -129,6 +130,19 @@ impl Default for ParserOptions {
129130
}
130131
}
131132

133+
impl From<&SqlParserOptions> for ParserOptions {
134+
fn from(options: &SqlParserOptions) -> Self {
135+
Self {
136+
parse_float_as_decimal: options.parse_float_as_decimal,
137+
enable_ident_normalization: options.enable_ident_normalization,
138+
support_varchar_with_length: options.support_varchar_with_length,
139+
enable_options_value_normalization: options
140+
.enable_options_value_normalization,
141+
collect_spans: options.collect_spans,
142+
}
143+
}
144+
}
145+
132146
/// Ident Normalizer
133147
#[derive(Debug)]
134148
pub struct IdentNormalizer {
@@ -316,12 +330,18 @@ pub struct SqlToRel<'a, S: ContextProvider> {
316330
}
317331

318332
impl<'a, S: ContextProvider> SqlToRel<'a, S> {
319-
/// Create a new query planner
333+
/// Create a new query planner.
334+
///
335+
/// The query planner derives the parser options from the context provider.
320336
pub fn new(context_provider: &'a S) -> Self {
321-
Self::new_with_options(context_provider, ParserOptions::default())
337+
let parser_options = ParserOptions::from(&context_provider.options().sql_parser);
338+
Self::new_with_options(context_provider, parser_options)
322339
}
323340

324-
/// Create a new query planner
341+
/// Create a new query planner with the given parser options.
342+
///
343+
/// The query planner ignores the parser options from the context provider
344+
/// and uses the given parser options instead.
325345
pub fn new_with_options(context_provider: &'a S, options: ParserOptions) -> Self {
326346
let ident_normalize = options.enable_ident_normalization;
327347

0 commit comments

Comments
 (0)