You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/28 12:33:03 UTC

[GitHub] [arrow-datafusion] alamb commented on a change in pull request #785: Support DataFrame.collect for Ballista DataFrames

alamb commented on a change in pull request #785:
URL: https://github.com/apache/arrow-datafusion/pull/785#discussion_r678237456



##########
File path: ballista-examples/src/bin/ballista-dataframe.rs
##########
@@ -38,18 +38,7 @@ async fn main() -> Result<()> {
         .select_columns(&["id", "bool_col", "timestamp_col"])?
         .filter(col("id").gt(lit(1)))?;
 
-    // execute the query - note that calling collect on the DataFrame
-    // trait will execute the query with DataFusion so we have to call
-    // collect on the BallistaContext instead and pass it the DataFusion
-    // logical plan
-    let mut stream = ctx.collect(&df.to_logical_plan()).await?;
-
-    // print the results
-    let mut results = vec![];
-    while let Some(batch) = stream.next().await {
-        let batch = batch?;
-        results.push(batch);
-    }
+    let results = df.collect().await?;

Review comment:
       That is certainly nicer 👍 

##########
File path: ballista/rust/core/src/execution_plans/distributed_query.rs
##########
@@ -0,0 +1,213 @@
+// 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.
+
+use std::any::Any;
+use std::convert::TryInto;
+use std::pin::Pin;
+use std::sync::Arc;
+use std::time::Duration;
+
+use crate::client::BallistaClient;
+use crate::config::BallistaConfig;
+use crate::serde::protobuf::{
+    execute_query_params::Query, job_status, scheduler_grpc_client::SchedulerGrpcClient,
+    ExecuteQueryParams, GetJobStatusParams, GetJobStatusResult, KeyValuePair,
+    PartitionLocation,
+};
+use crate::utils::WrappedStream;
+
+use datafusion::arrow::datatypes::{Schema, SchemaRef};
+use datafusion::error::{DataFusionError, Result};
+use datafusion::logical_plan::LogicalPlan;
+use datafusion::physical_plan::{
+    ExecutionPlan, Partitioning, RecordBatchStream, SendableRecordBatchStream,
+};
+
+use async_trait::async_trait;
+use futures::future;
+use futures::StreamExt;
+use log::{error, info};
+
+/// This operator sends a logial plan to a Ballista scheduler for execution and
+/// polls the scheduler until the query is complete and then fetches the resulting
+/// batches directly from the executors that hold the results from the final
+/// query stage.
+#[derive(Debug, Clone)]
+pub struct DistributedQueryExec {
+    /// Ballista scheduler URL
+    scheduler_url: String,
+    /// Ballista configuration
+    config: BallistaConfig,
+    /// Logical plan to execute
+    plan: LogicalPlan,
+}
+
+impl DistributedQueryExec {
+    pub fn new(scheduler_url: String, config: BallistaConfig, plan: LogicalPlan) -> Self {
+        Self {
+            scheduler_url,
+            config,
+            plan,
+        }
+    }
+}
+
+#[async_trait]
+impl ExecutionPlan for DistributedQueryExec {

Review comment:
       This is a cool pattern 👍 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org