-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix regenerate_sqlite_files.sh due to changes in sqllogictests
#14881
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
datafusion/sqllogictest/regenerate/src/engines/datafusion_engine/runner.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
|
Contributor
Author
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 brutal -- I edited these files so they compiled and then copied them to the regenerate location, similarly to how it is tone for the runner.rs |
||
| // 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. | ||
|
|
||
| use std::sync::Arc; | ||
| use std::{path::PathBuf, time::Duration}; | ||
|
|
||
| use super::{error::Result, normalize, DFSqlLogicTestError}; | ||
| use arrow::record_batch::RecordBatch; | ||
| use async_trait::async_trait; | ||
| use datafusion::physical_plan::common::collect; | ||
| use datafusion::physical_plan::execute_stream; | ||
| use datafusion::prelude::SessionContext; | ||
| use indicatif::ProgressBar; | ||
| use log::Level::{Debug, Info}; | ||
| use log::{debug, log_enabled, warn}; | ||
| use sqllogictest::DBOutput; | ||
| use tokio::time::Instant; | ||
|
|
||
| use crate::engines::output::{DFColumnType, DFOutput}; | ||
|
|
||
| pub struct DataFusion { | ||
| ctx: SessionContext, | ||
| relative_path: PathBuf, | ||
| pb: ProgressBar, | ||
| } | ||
|
|
||
| impl DataFusion { | ||
| pub fn new(ctx: SessionContext, relative_path: PathBuf, pb: ProgressBar) -> Self { | ||
| Self { | ||
| ctx, | ||
| relative_path, | ||
| pb, | ||
| } | ||
| } | ||
|
|
||
| fn update_slow_count(&self) { | ||
| let msg = self.pb.message(); | ||
| let split: Vec<&str> = msg.split(" ").collect(); | ||
| let mut current_count = 0; | ||
|
|
||
| if split.len() > 2 { | ||
| // third match will be current slow count | ||
| current_count = split[2].parse::<i32>().unwrap(); | ||
| } | ||
|
|
||
| current_count += 1; | ||
|
|
||
| self.pb | ||
| .set_message(format!("{} - {} took > 500 ms", split[0], current_count)); | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl sqllogictest::AsyncDB for DataFusion { | ||
| type Error = DFSqlLogicTestError; | ||
| type ColumnType = DFColumnType; | ||
|
|
||
| async fn run(&mut self, sql: &str) -> Result<DFOutput> { | ||
| if log_enabled!(Debug) { | ||
| debug!( | ||
| "[{}] Running query: \"{}\"", | ||
| self.relative_path.display(), | ||
| sql | ||
| ); | ||
| } | ||
|
|
||
| let start = Instant::now(); | ||
| let result = run_query(&self.ctx, sql).await; | ||
| let duration = start.elapsed(); | ||
|
|
||
| if duration.gt(&Duration::from_millis(500)) { | ||
| self.update_slow_count(); | ||
| } | ||
|
|
||
| self.pb.inc(1); | ||
|
|
||
| if log_enabled!(Info) && duration.gt(&Duration::from_secs(2)) { | ||
| warn!( | ||
| "[{}] Running query took more than 2 sec ({duration:?}): \"{sql}\"", | ||
| self.relative_path.display() | ||
| ); | ||
| } | ||
|
|
||
| result | ||
| } | ||
|
|
||
| /// Engine name of current database. | ||
| fn engine_name(&self) -> &str { | ||
| "DataFusion" | ||
| } | ||
|
|
||
| /// [`DataFusion`] calls this function to perform sleep. | ||
| /// | ||
| /// The default implementation is `std::thread::sleep`, which is universal to any async runtime | ||
| /// but would block the current thread. If you are running in tokio runtime, you should override | ||
| /// this by `tokio::time::sleep`. | ||
| async fn sleep(dur: Duration) { | ||
| tokio::time::sleep(dur).await; | ||
| } | ||
| } | ||
|
|
||
| async fn run_query(ctx: &SessionContext, sql: impl Into<String>) -> Result<DFOutput> { | ||
| let df = ctx.sql(sql.into().as_str()).await?; | ||
| let task_ctx = Arc::new(df.task_ctx()); | ||
| let plan = df.create_physical_plan().await?; | ||
|
|
||
| let stream = execute_stream(plan, task_ctx)?; | ||
| let types = normalize::convert_schema_to_types(stream.schema().fields()); | ||
| let results: Vec<RecordBatch> = collect(stream).await?; | ||
| let rows = normalize::convert_batches(results)?; | ||
|
|
||
| if rows.is_empty() && types.is_empty() { | ||
| Ok(DBOutput::StatementComplete(0)) | ||
| } else { | ||
| Ok(DBOutput::Rows { types, rows }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
postgresql://postgres@localhost:5432/postgresdoesn't work for me.Run with
$(whoami)to find your name, and the command should beAnd run this to find database
This works
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 just run postgres in docker:
docker run --name df_postgres -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=test -d -p 5432:5432 postgres:latest export PG_URI=postgres://test:test@host.docker.internal:5432/test ./datafusion/sqllogictest/regenerate_sqlite_files.sh