|
1 | | -use std::{collections::HashMap, sync::Arc}; |
| 1 | +// use std::{collections::HashMap, sync::Arc}; |
2 | 2 |
|
3 | | -use datafusion::prelude::SessionContext; |
4 | | -use datafusion::sql::TableReference; |
5 | | -use datafusion_table_providers::{ |
6 | | - mongodb::{connection_pool::MongoDBConnectionPool, MongoDBTableFactory}, util::secrets::to_secret_map, |
7 | | -}; |
| 3 | +// use datafusion::prelude::SessionContext; |
| 4 | +// use datafusion::sql::TableReference; |
| 5 | +// use datafusion_table_providers::{ |
| 6 | +// mongodb::{connection_pool::MongoDBConnectionPool, MongoDBTableFactory}, util::secrets::to_secret_map, |
| 7 | +// }; |
8 | 8 |
|
9 | | -/// This example demonstrates how to: |
10 | | -/// 1. Create a MongoDB connection pool |
11 | | -/// 2. Create and use MongoDBTableFactory to generate TableProvider |
12 | | -/// 3. Use SQL queries to access MongoDB table data |
13 | | -/// |
14 | | -/// Prerequisites: |
15 | | -/// Start a MongoDB server using Docker: |
16 | | -/// ```bash |
17 | | -/// docker run --name mongodb \ |
18 | | -/// -e MONGO_INITDB_ROOT_USERNAME=root \ |
19 | | -/// -e MONGO_INITDB_ROOT_PASSWORD=password \ |
20 | | -/// -e MONGO_INITDB_DATABASE=mongo_db \ |
21 | | -/// -p 27017:27017 \ |
22 | | -/// -d mongo:7.0 |
23 | | -/// # Wait for the MongoDB server to start |
24 | | -/// sleep 30 |
25 | | -/// |
26 | | -/// # Create a table in the MongoDB server and insert some data |
27 | | -/// docker exec -i mongodb mongosh -u root -p password --authenticationDatabase admin <<EOF |
28 | | -/// use mongo_db; |
29 | | -/// |
30 | | -/// db.companies.insertOne({ |
31 | | -/// id: 1, |
32 | | -/// name: "Acme Corporation" |
33 | | -/// }); |
34 | | -/// EOF |
35 | | -/// ``` |
36 | | -#[tokio::main] |
37 | | -async fn main(){ |
| 9 | +// /// This example demonstrates how to: |
| 10 | +// /// 1. Create a MongoDB connection pool |
| 11 | +// /// 2. Create and use MongoDBTableFactory to generate TableProvider |
| 12 | +// /// 3. Use SQL queries to access MongoDB table data |
| 13 | +// /// |
| 14 | +// /// Prerequisites: |
| 15 | +// /// Start a MongoDB server using Docker: |
| 16 | +// /// ```bash |
| 17 | +// /// docker run --name mongodb \ |
| 18 | +// /// -e MONGO_INITDB_ROOT_USERNAME=root \ |
| 19 | +// /// -e MONGO_INITDB_ROOT_PASSWORD=password \ |
| 20 | +// /// -e MONGO_INITDB_DATABASE=mongo_db \ |
| 21 | +// /// -p 27017:27017 \ |
| 22 | +// /// -d mongo:7.0 |
| 23 | +// /// # Wait for the MongoDB server to start |
| 24 | +// /// sleep 30 |
| 25 | +// /// |
| 26 | +// /// # Create a table in the MongoDB server and insert some data |
| 27 | +// /// docker exec -i mongodb mongosh -u root -p password --authenticationDatabase admin <<EOF |
| 28 | +// /// use mongo_db; |
| 29 | +// /// |
| 30 | +// /// db.companies.insertOne({ |
| 31 | +// /// id: 1, |
| 32 | +// /// name: "Acme Corporation" |
| 33 | +// /// }); |
| 34 | +// /// EOF |
| 35 | +// /// ``` |
| 36 | +// #[tokio::main] |
| 37 | +// async fn main(){ |
38 | 38 |
|
39 | | - // Create MongoDB connection parameters |
40 | | - // Including connection string and SSL mode settings |
41 | | - let mongodb_params = to_secret_map(HashMap::from([ |
42 | | - ( |
43 | | - "connection_string".to_string(), |
44 | | - "mongodb://root:password@localhost:27017/mongo_db?authSource=admin".to_string(), |
45 | | - ), |
46 | | - ("sslmode".to_string(), "disabled".to_string()), |
47 | | - ])); |
| 39 | +// // Create MongoDB connection parameters |
| 40 | +// // Including connection string and SSL mode settings |
| 41 | +// let mongodb_params = to_secret_map(HashMap::from([ |
| 42 | +// ( |
| 43 | +// "connection_string".to_string(), |
| 44 | +// "mongodb://root:password@localhost:27017/mongo_db?authSource=admin".to_string(), |
| 45 | +// ), |
| 46 | +// ("sslmode".to_string(), "disabled".to_string()), |
| 47 | +// ])); |
48 | 48 |
|
49 | | - // Create MongoDB connection pool |
50 | | - let mongodb_pool = Arc::new( |
51 | | - MongoDBConnectionPool::new(mongodb_params) |
52 | | - .await |
53 | | - .expect("unable to create MongoDB connection pool"), |
54 | | - ); |
| 49 | +// // Create MongoDB connection pool |
| 50 | +// let mongodb_pool = Arc::new( |
| 51 | +// MongoDBConnectionPool::new(mongodb_params) |
| 52 | +// .await |
| 53 | +// .expect("unable to create MongoDB connection pool"), |
| 54 | +// ); |
55 | 55 |
|
56 | | - // Create MongoDB table provider factory |
57 | | - // Used to generate TableProvider instances that can read MongoDB table data |
58 | | - let table_factory = MongoDBTableFactory::new(mongodb_pool.clone()); |
| 56 | +// // Create MongoDB table provider factory |
| 57 | +// // Used to generate TableProvider instances that can read MongoDB table data |
| 58 | +// let table_factory = MongoDBTableFactory::new(mongodb_pool.clone()); |
59 | 59 |
|
60 | | - // Create DataFusion session context |
61 | | - let ctx = SessionContext::new(); |
| 60 | +// // Create DataFusion session context |
| 61 | +// let ctx = SessionContext::new(); |
62 | 62 |
|
63 | | - // Demonstrate direct table provider registration |
64 | | - // This method registers the table in the default catalog |
65 | | - // Here we register the MongoDB "companies" table as "companies_v2" |
66 | | - ctx.register_table( |
67 | | - "companies_v2", |
68 | | - table_factory |
69 | | - .table_provider(TableReference::bare("companies")) |
70 | | - .await |
71 | | - .expect("failed to register table provider"), |
72 | | - ) |
73 | | - .expect("failed to register table"); |
| 63 | +// // Demonstrate direct table provider registration |
| 64 | +// // This method registers the table in the default catalog |
| 65 | +// // Here we register the MongoDB "companies" table as "companies_v2" |
| 66 | +// ctx.register_table( |
| 67 | +// "companies_v2", |
| 68 | +// table_factory |
| 69 | +// .table_provider(TableReference::bare("companies")) |
| 70 | +// .await |
| 71 | +// .expect("failed to register table provider"), |
| 72 | +// ) |
| 73 | +// .expect("failed to register table"); |
74 | 74 |
|
75 | | - // Query Example: Query the renamed table through default catalog |
76 | | - let df = ctx |
77 | | - .sql("SELECT * FROM datafusion.public.companies_v2") |
78 | | - .await |
79 | | - .expect("select failed"); |
80 | | - df.show().await.expect("show failed"); |
81 | | -} |
| 75 | +// // Query Example: Query the renamed table through default catalog |
| 76 | +// let df = ctx |
| 77 | +// .sql("SELECT * FROM datafusion.public.companies_v2") |
| 78 | +// .await |
| 79 | +// .expect("select failed"); |
| 80 | +// df.show().await.expect("show failed"); |
| 81 | +// } |
0 commit comments