-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support selecting from local files #152
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,15 @@ impl ExecutionContext { | |
extension.register_on_ctx(config, &mut session_ctx)?; | ||
} | ||
|
||
// Enable the dynamic file provider (so that we can read files from the | ||
// local filesystem) | ||
// TODO file a ticket to make the API consuming!! | ||
// I did like | ||
// session_ctx.enable_url_table(); | ||
// expecting that to work, but it didn't as the code returns a new session context | ||
// instead of modifying the existing one | ||
let session_ctx = session_ctx.enable_url_table(); | ||
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. this is the only change needed (it is a nice API thanks to @goldmedal) 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. this is pretty awesome |
||
|
||
Ok(Self { | ||
session_ctx, | ||
#[cfg(feature = "flightsql")] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,18 +15,18 @@ | |
// specific language governing permissions and limitations | ||
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 renamed the tests from 'extensions' to 'execution' to better reflect it is testing execution in general rather than only extension execution |
||
// under the License. | ||
|
||
//! Tests for extensions (stored in the `extension_cases` directory) | ||
//! Tests for `ExecutionContext` and extensions (stored in the `execution_cases` directory) | ||
|
||
use datafusion::arrow::array::RecordBatch; | ||
use datafusion::arrow::util::pretty::pretty_format_batches; | ||
use datafusion::error::Result; | ||
use datafusion::sql::parser::DFParser; | ||
use datafusion_common::Result; | ||
use dft::config::AppConfig; | ||
use dft::execution::ExecutionContext; | ||
use futures::{StreamExt, TryStreamExt}; | ||
use log::debug; | ||
|
||
mod extension_cases; | ||
mod execution_cases; | ||
|
||
/// Encapsulates an `ExecutionContext` for running queries in tests | ||
pub struct TestExecution { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! Tests for basic execution | ||
|
||
use crate::TestExecution; | ||
|
||
#[tokio::test] | ||
async fn test_basic_execution() { | ||
let mut execution = TestExecution::new(); | ||
|
||
let actual = execution.run_and_format("SELECT 1+3, 11").await; | ||
|
||
insta::assert_yaml_snapshot!(actual, @r###" | ||
- +---------------------+-----------+ | ||
- "| Int64(1) + Int64(3) | Int64(11) |" | ||
- +---------------------+-----------+ | ||
- "| 4 | 11 |" | ||
- +---------------------+-----------+ | ||
"###); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_ddl_statements() { | ||
let mut execution = TestExecution::new() | ||
.with_setup("CREATE TABLE foo(x int) as VALUES (11), (12), (13)") | ||
.await; | ||
|
||
let actual = execution.run_and_format("SELECT x, x+1 FROM foo").await; | ||
|
||
insta::assert_yaml_snapshot!(actual, @r###" | ||
- +----+------------------+ | ||
- "| x | foo.x + Int64(1) |" | ||
- +----+------------------+ | ||
- "| 11 | 12 |" | ||
- "| 12 | 13 |" | ||
- "| 13 | 14 |" | ||
- +----+------------------+ | ||
"###); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! Tests for selecting data from local files | ||
use crate::TestExecution; | ||
|
||
|
||
#[tokio::test] | ||
async fn local_csv_file() { | ||
let mut execution = TestExecution::new(); | ||
|
||
let actual = execution | ||
.run_and_format("SELECT * from 'data/alltypes_plain.snappy.parquet'") | ||
.await; | ||
|
||
insta::assert_yaml_snapshot!(actual, @r###" | ||
- +----+----------+-------------+--------------+---------+------------+-----------+------------+------------------+------------+---------------------+ | ||
- "| id | bool_col | tinyint_col | smallint_col | int_col | bigint_col | float_col | double_col | date_string_col | string_col | timestamp_col |" | ||
- +----+----------+-------------+--------------+---------+------------+-----------+------------+------------------+------------+---------------------+ | ||
- "| 6 | true | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 30342f30312f3039 | 30 | 2009-04-01T00:00:00 |" | ||
- "| 7 | false | 1 | 1 | 1 | 10 | 1.1 | 10.1 | 30342f30312f3039 | 31 | 2009-04-01T00:01:00 |" | ||
- +----+----------+-------------+--------------+---------+------------+-----------+------------+------------------+------------+---------------------+ | ||
"###); | ||
} |
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.
i agree that would be nicer
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.
apache/datafusion#12551 tracking tickeet