Skip to content

Commit 892f162

Browse files
authored
Merge branch 'main' into fix/bloom_filter_decimal
2 parents d33aae6 + 7bb6e15 commit 892f162

41 files changed

Lines changed: 2795 additions & 505 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 86 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/src/bin/external_aggr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@ impl ExternalAggrConfig {
318318
);
319319
let extension = DEFAULT_PARQUET_EXTENSION;
320320

321-
let options = ListingOptions::new(format)
322-
.with_file_extension(extension)
323-
.with_collect_stat(state.config().collect_statistics());
321+
let options = ListingOptions::new(format).with_file_extension(extension);
324322

325323
let table_path = ListingTableUrl::parse(path)?;
326324
let config = ListingTableConfig::new(table_path).with_listing_options(options);

benchmarks/src/imdb/run.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ impl RunOpt {
425425
let table_format = self.file_format.as_str();
426426

427427
// Obtain a snapshot of the SessionState
428-
let state = ctx.state();
429428
let (format, path, extension): (Arc<dyn FileFormat>, String, &'static str) =
430429
match table_format {
431430
// dbgen creates .tbl ('|' delimited) files without header
@@ -458,9 +457,7 @@ impl RunOpt {
458457
}
459458
};
460459

461-
let options = ListingOptions::new(format)
462-
.with_file_extension(extension)
463-
.with_collect_stat(state.config().collect_statistics());
460+
let options = ListingOptions::new(format).with_file_extension(extension);
464461

465462
let table_path = ListingTableUrl::parse(path)?;
466463
let config = ListingTableConfig::new(table_path).with_listing_options(options);

benchmarks/src/sort_pushdown.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ impl RunOpt {
162162
let config = self.common.config()?;
163163
let rt = self.common.build_runtime()?;
164164
let state = SessionStateBuilder::new()
165-
.with_config(config)
165+
// Always collect statistics for sort pushdown
166+
.with_config(config.with_collect_statistics(true))
166167
.with_runtime_env(rt)
167168
.with_default_features()
168169
.build();
@@ -255,9 +256,7 @@ impl RunOpt {
255256
);
256257
let extension = DEFAULT_PARQUET_EXTENSION;
257258

258-
let options = ListingOptions::new(format)
259-
.with_file_extension(extension)
260-
.with_collect_stat(true); // Always collect statistics for sort pushdown
259+
let options = ListingOptions::new(format).with_file_extension(extension);
261260

262261
let table_path = ListingTableUrl::parse(path)?;
263262
let schema = options.infer_schema(&state, &table_path).await?;

benchmarks/src/sort_tpch.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ impl RunOpt {
333333
);
334334
let extension = DEFAULT_PARQUET_EXTENSION;
335335

336-
let options = ListingOptions::new(format)
337-
.with_file_extension(extension)
338-
.with_collect_stat(state.config().collect_statistics());
336+
let options = ListingOptions::new(format).with_file_extension(extension);
339337

340338
let table_path = ListingTableUrl::parse(path)?;
341339
let schema = options.infer_schema(&state, &table_path).await?;

benchmarks/src/tpcds/run.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ impl RunOpt {
364364
table: &str,
365365
) -> Result<Arc<dyn TableProvider>> {
366366
let path = self.path.to_str().unwrap();
367-
let target_partitions = self.partitions();
368367

369368
// Obtain a snapshot of the SessionState
370369
let state = ctx.state();
@@ -380,9 +379,7 @@ impl RunOpt {
380379

381380
let table_path = ListingTableUrl::parse(path)?;
382381
let options = ListingOptions::new(Arc::new(format))
383-
.with_file_extension(DEFAULT_PARQUET_EXTENSION)
384-
.with_target_partitions(target_partitions)
385-
.with_collect_stat(state.config().collect_statistics());
382+
.with_file_extension(DEFAULT_PARQUET_EXTENSION);
386383

387384
let schema = options.infer_schema(&state, &table_path).await?;
388385
let constraints = table_constraints(table, schema.as_ref());

benchmarks/src/tpch/run.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ impl RunOpt {
283283
) -> Result<Arc<dyn TableProvider>> {
284284
let path = self.path.to_str().unwrap();
285285
let table_format = self.file_format.as_str();
286-
let target_partitions = self.partitions();
287286

288287
// Obtain a snapshot of the SessionState
289288
let state = ctx.state();
@@ -320,10 +319,7 @@ impl RunOpt {
320319
};
321320

322321
let table_path = ListingTableUrl::parse(path)?;
323-
let options = ListingOptions::new(format)
324-
.with_file_extension(extension)
325-
.with_target_partitions(target_partitions)
326-
.with_collect_stat(state.config().collect_statistics());
322+
let options = ListingOptions::new(format).with_file_extension(extension);
327323

328324
let schema = match table_format {
329325
"parquet" => options.infer_schema(&state, &table_path).await?,

datafusion-cli/src/exec.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::print_format::PrintFormat;
2323
use crate::{
2424
command::{Command, OutputFormat},
2525
helper::CliHelper,
26-
object_storage::get_object_store,
26+
object_storage::{get_object_store, stdin::StdinUtils},
2727
print_options::{MaxRows, PrintOptions},
2828
};
2929
use datafusion::common::instant::Instant;
@@ -417,9 +417,14 @@ async fn create_plan(
417417
// Note that cmd is a mutable reference so that create_external_table function can remove all
418418
// datafusion-cli specific options before passing through to datafusion. Otherwise, datafusion
419419
// will raise Configuration errors.
420-
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &plan {
420+
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &mut plan {
421421
// To support custom formats, treat error as None
422422
let format = config_file_type_from_str(&cmd.file_type);
423+
424+
// Expose stdin (e.g. `cat data.csv | datafusion-cli`) as a `stdin://`
425+
// object store, registered like any other scheme in `get_object_store`.
426+
cmd.location = StdinUtils::rewrite_location(&cmd.location, format.as_ref());
427+
423428
register_object_store_and_config_extensions(
424429
ctx,
425430
&cmd.location,

datafusion-cli/src/main.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use datafusion_cli::functions::{
3737
use datafusion_cli::object_storage::instrumented::{
3838
InstrumentedObjectStoreMode, InstrumentedObjectStoreRegistry,
3939
};
40+
use datafusion_cli::object_storage::{StdinCarriesCommands, is_stdin_location};
4041
use datafusion_cli::{
4142
DATAFUSION_CLI_VERSION, exec,
4243
pool_type::PoolType,
@@ -158,6 +159,23 @@ struct Args {
158159
object_store_profiling: InstrumentedObjectStoreMode,
159160
}
160161

162+
impl Args {
163+
/// Without -c/-f the CLI enters the REPL, which reads its SQL from
164+
/// stdin — interactively or piped.
165+
fn repl_mode(&self) -> bool {
166+
self.command.is_empty() && self.file.is_empty()
167+
}
168+
169+
/// Whether the CLI consumes stdin for its own SQL input. This covers the
170+
/// REPL (no -c/-f, reading SQL interactively or piped) as well as an
171+
/// explicit `-f /dev/stdin` (or the other stdin pseudo-paths), where the
172+
/// SQL file *is* stdin. In either case stdin is already spoken for and
173+
/// cannot also back a `LOCATION '/dev/stdin'` table.
174+
fn reads_sql_from_stdin(&self) -> bool {
175+
self.repl_mode() || self.file.iter().any(|f| is_stdin_location(f))
176+
}
177+
}
178+
161179
#[tokio::main]
162180
/// Calls [`main_inner`], then handles printing errors and returning the correct exit code
163181
pub async fn main() -> ExitCode {
@@ -268,6 +286,7 @@ async fn main_inner() -> Result<()> {
268286
instrumented_registry: Arc::clone(&instrumented_registry),
269287
};
270288

289+
let repl_mode = args.repl_mode();
271290
let commands = args.command;
272291
let files = args.file;
273292
let rc = match args.rc {
@@ -285,7 +304,7 @@ async fn main_inner() -> Result<()> {
285304
}
286305
};
287306

288-
if commands.is_empty() && files.is_empty() {
307+
if repl_mode {
289308
if !rc.is_empty() {
290309
exec::exec_from_files(&ctx, rc, &print_options).await?;
291310
}
@@ -330,8 +349,16 @@ fn get_session_config(args: &Args) -> Result<SessionConfig> {
330349
config_options.format.null = String::from("NULL");
331350
}
332351

333-
let session_config =
352+
let mut session_config =
334353
SessionConfig::from(config_options).with_information_schema(true);
354+
355+
if args.reads_sql_from_stdin() {
356+
// When stdin carries the session's SQL — the REPL (including any rc
357+
// file run before it) or an explicit `-f /dev/stdin` — it cannot also
358+
// serve as a data source for `LOCATION '/dev/stdin'`.
359+
session_config = session_config.with_extension(Arc::new(StdinCarriesCommands));
360+
}
361+
335362
Ok(session_config)
336363
}
337364

datafusion-cli/src/object_storage.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// under the License.
1717

1818
pub mod instrumented;
19+
pub(crate) mod stdin;
20+
21+
pub use stdin::{StdinCarriesCommands, is_stdin_location};
1922

2023
use async_trait::async_trait;
2124
use aws_config::BehaviorVersion;
@@ -564,6 +567,9 @@ pub(crate) async fn get_object_store(
564567
.with_url(url.origin().ascii_serialization())
565568
.build()?,
566569
),
570+
_ if scheme == stdin::StdinUtils::SCHEME => {
571+
stdin::StdinUtils::get_or_create(state, url).await?
572+
}
567573
_ => {
568574
// For other types, try to get from `object_store_registry`:
569575
state

0 commit comments

Comments
 (0)