|
| 1 | +.. Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +.. or more contributor license agreements. See the NOTICE file |
| 3 | +.. distributed with this work for additional information |
| 4 | +.. regarding copyright ownership. The ASF licenses this file |
| 5 | +.. to you under the Apache License, Version 2.0 (the |
| 6 | +.. "License"); you may not use this file except in compliance |
| 7 | +.. with the License. You may obtain a copy of the License at |
| 8 | +.. |
| 9 | +.. http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +.. |
| 11 | +.. Unless required by applicable law or agreed to in writing, |
| 12 | +.. software distributed under the License is distributed on an |
| 13 | +.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +.. KIND, either express or implied. See the License for the |
| 15 | +.. specific language governing permissions and limitations |
| 16 | +.. under the License. |
| 17 | +
|
| 18 | +========== |
| 19 | +Quickstart |
| 20 | +========== |
| 21 | + |
| 22 | +Here we'll briefly tour using ADBC with the `DataFusion`_ driver. |
| 23 | + |
| 24 | +.. _DataFusion: https://datafusion.apache.org/ |
| 25 | + |
| 26 | +Installation |
| 27 | +============ |
| 28 | + |
| 29 | +Add a dependency on ``adbc_core`` and ``adbc_datafusion``: |
| 30 | + |
| 31 | +.. code-block:: shell |
| 32 | +
|
| 33 | + cargo add adbc_core adbc_datafusion |
| 34 | +
|
| 35 | +Loading DataFusion |
| 36 | +================== |
| 37 | + |
| 38 | +Create a driver instance, then a database handle, and then finally a |
| 39 | +connection. (This is a bit redundant for something like DataFusion, but the |
| 40 | +intent is that the database handle can hold shared state that multiple |
| 41 | +connections can share.) |
| 42 | + |
| 43 | +.. code-block:: rust |
| 44 | +
|
| 45 | + // These traits must be in scope |
| 46 | + use adbc_core::{Connection, Database, Driver, Statement}; |
| 47 | +
|
| 48 | + let mut driver = adbc_datafusion::DataFusionDriver {}; |
| 49 | + let db = driver.new_database().expect("Failed to create database handle"); |
| 50 | + let mut conn = db.new_connection().expect("Failed to create connection"); |
| 51 | +
|
| 52 | +Running Queries |
| 53 | +=============== |
| 54 | + |
| 55 | +To run queries, we can create a statement and set a query: |
| 56 | + |
| 57 | +.. code-block:: rust |
| 58 | +
|
| 59 | + let mut stmt = conn.new_statement().expect("Failed to create statement"); |
| 60 | + stmt.set_sql_query("SELECT 1").expect("Failed to set SQL query"); |
| 61 | +
|
| 62 | +We can then execute the query to get an Arrow ``RecordBatchReader``: |
| 63 | + |
| 64 | +.. code-block:: rust |
| 65 | +
|
| 66 | + let reader = stmt.execute().expect("Failed to execute statement"); |
| 67 | + for batch in reader { |
| 68 | + let batch = batch.expect("Failed to read batch"); |
| 69 | + println!("{:?}", batch); |
| 70 | + } |
0 commit comments