forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinformation_schema.rs
More file actions
611 lines (518 loc) · 27.3 KB
/
information_schema.rs
File metadata and controls
611 lines (518 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
// 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 async_trait::async_trait;
use datafusion::execution::context::SessionState;
use datafusion::{
catalog::{
catalog::{CatalogProvider, MemoryCatalogProvider},
schema::{MemorySchemaProvider, SchemaProvider},
},
datasource::{TableProvider, TableType},
logical_plan::Expr,
};
use super::*;
#[tokio::test]
async fn information_schema_tables_not_exist_by_default() {
let ctx = SessionContext::new();
let err = plan_and_collect(&ctx, "SELECT * from information_schema.tables")
.await
.unwrap_err();
assert_eq!(
err.to_string(),
// Error propagates from SessionState::schema_for_ref
"Error during planning: failed to resolve schema: information_schema"
);
}
#[tokio::test]
async fn information_schema_tables_no_tables() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let result = plan_and_collect(&ctx, "SELECT * from information_schema.tables")
.await
.unwrap();
let expected = vec![
"+---------------+--------------------+------------+------------+",
"| table_catalog | table_schema | table_name | table_type |",
"+---------------+--------------------+------------+------------+",
"| datafusion | information_schema | columns | VIEW |",
"| datafusion | information_schema | tables | VIEW |",
"| datafusion | information_schema | views | VIEW |",
"+---------------+--------------------+------------+------------+",
];
assert_batches_sorted_eq!(expected, &result);
}
#[tokio::test]
async fn information_schema_tables_tables_default_catalog() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
// Now, register an empty table
ctx.register_table("t", table_with_sequence(1, 1).unwrap())
.unwrap();
let result = plan_and_collect(&ctx, "SELECT * from information_schema.tables")
.await
.unwrap();
let expected = vec![
"+---------------+--------------------+------------+------------+",
"| table_catalog | table_schema | table_name | table_type |",
"+---------------+--------------------+------------+------------+",
"| datafusion | information_schema | columns | VIEW |",
"| datafusion | information_schema | tables | VIEW |",
"| datafusion | information_schema | views | VIEW |",
"| datafusion | public | t | BASE TABLE |",
"+---------------+--------------------+------------+------------+",
];
assert_batches_sorted_eq!(expected, &result);
// Newly added tables should appear
ctx.register_table("t2", table_with_sequence(1, 1).unwrap())
.unwrap();
let result = plan_and_collect(&ctx, "SELECT * from information_schema.tables")
.await
.unwrap();
let expected = vec![
"+---------------+--------------------+------------+------------+",
"| table_catalog | table_schema | table_name | table_type |",
"+---------------+--------------------+------------+------------+",
"| datafusion | information_schema | columns | VIEW |",
"| datafusion | information_schema | tables | VIEW |",
"| datafusion | information_schema | views | VIEW |",
"| datafusion | public | t | BASE TABLE |",
"| datafusion | public | t2 | BASE TABLE |",
"+---------------+--------------------+------------+------------+",
];
assert_batches_sorted_eq!(expected, &result);
}
#[tokio::test]
async fn information_schema_tables_tables_with_multiple_catalogs() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let catalog = MemoryCatalogProvider::new();
let schema = MemorySchemaProvider::new();
schema
.register_table("t1".to_owned(), table_with_sequence(1, 1).unwrap())
.unwrap();
schema
.register_table("t2".to_owned(), table_with_sequence(1, 1).unwrap())
.unwrap();
catalog
.register_schema("my_schema", Arc::new(schema))
.unwrap();
ctx.register_catalog("my_catalog", Arc::new(catalog));
let catalog = MemoryCatalogProvider::new();
let schema = MemorySchemaProvider::new();
schema
.register_table("t3".to_owned(), table_with_sequence(1, 1).unwrap())
.unwrap();
catalog
.register_schema("my_other_schema", Arc::new(schema))
.unwrap();
ctx.register_catalog("my_other_catalog", Arc::new(catalog));
let result = plan_and_collect(&ctx, "SELECT * from information_schema.tables")
.await
.unwrap();
let expected = vec![
"+------------------+--------------------+------------+------------+",
"| table_catalog | table_schema | table_name | table_type |",
"+------------------+--------------------+------------+------------+",
"| datafusion | information_schema | columns | VIEW |",
"| datafusion | information_schema | tables | VIEW |",
"| datafusion | information_schema | views | VIEW |",
"| my_catalog | information_schema | columns | VIEW |",
"| my_catalog | information_schema | tables | VIEW |",
"| my_catalog | information_schema | views | VIEW |",
"| my_catalog | my_schema | t1 | BASE TABLE |",
"| my_catalog | my_schema | t2 | BASE TABLE |",
"| my_other_catalog | information_schema | columns | VIEW |",
"| my_other_catalog | information_schema | tables | VIEW |",
"| my_other_catalog | information_schema | views | VIEW |",
"| my_other_catalog | my_other_schema | t3 | BASE TABLE |",
"+------------------+--------------------+------------+------------+",
];
assert_batches_sorted_eq!(expected, &result);
}
#[tokio::test]
async fn information_schema_tables_table_types() {
struct TestTable(TableType);
#[async_trait]
impl TableProvider for TestTable {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn table_type(&self) -> TableType {
self.0
}
fn schema(&self) -> SchemaRef {
unimplemented!()
}
async fn scan(
&self,
_ctx: &SessionState,
_: &Option<Vec<usize>>,
_: &[Expr],
_: Option<usize>,
) -> Result<Arc<dyn ExecutionPlan>> {
unimplemented!()
}
}
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
ctx.register_table("physical", Arc::new(TestTable(TableType::Base)))
.unwrap();
ctx.register_table("query", Arc::new(TestTable(TableType::View)))
.unwrap();
ctx.register_table("temp", Arc::new(TestTable(TableType::Temporary)))
.unwrap();
let result = plan_and_collect(&ctx, "SELECT * from information_schema.tables")
.await
.unwrap();
let expected = vec![
"+---------------+--------------------+------------+-----------------+",
"| table_catalog | table_schema | table_name | table_type |",
"+---------------+--------------------+------------+-----------------+",
"| datafusion | information_schema | columns | VIEW |",
"| datafusion | information_schema | tables | VIEW |",
"| datafusion | information_schema | views | VIEW |",
"| datafusion | public | physical | BASE TABLE |",
"| datafusion | public | query | VIEW |",
"| datafusion | public | temp | LOCAL TEMPORARY |",
"+---------------+--------------------+------------+-----------------+",
];
assert_batches_sorted_eq!(expected, &result);
}
#[tokio::test]
async fn information_schema_show_tables_no_information_schema() {
let ctx = SessionContext::with_config(SessionConfig::new());
ctx.register_table("t", table_with_sequence(1, 1).unwrap())
.unwrap();
// use show tables alias
let err = plan_and_collect(&ctx, "SHOW TABLES").await.unwrap_err();
assert_eq!(err.to_string(), "Error during planning: SHOW TABLES is not supported unless information_schema is enabled");
}
#[tokio::test]
async fn information_schema_describe_table() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let sql = "CREATE OR REPLACE TABLE y AS VALUES (1,2),(3,4);";
ctx.sql(sql).await.unwrap();
let sql_all = "describe y;";
let results_all = execute_to_batches(&ctx, sql_all).await;
let expected = vec![
"+-------------+-----------+-------------+",
"| column_name | data_type | is_nullable |",
"+-------------+-----------+-------------+",
"| column1 | Int64 | YES |",
"| column2 | Int64 | YES |",
"+-------------+-----------+-------------+",
];
assert_batches_eq!(expected, &results_all);
}
#[tokio::test]
async fn information_schema_describe_table_not_exists() {
let ctx = SessionContext::with_config(SessionConfig::new());
let sql_all = "describe table;";
let err = plan_and_collect(&ctx, sql_all).await.unwrap_err();
assert_eq!(
err.to_string(),
"Error during planning: 'datafusion.public.table' not found"
);
}
#[tokio::test]
async fn information_schema_show_tables() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
ctx.register_table("t", table_with_sequence(1, 1).unwrap())
.unwrap();
// use show tables alias
let result = plan_and_collect(&ctx, "SHOW TABLES").await.unwrap();
let expected = vec![
"+---------------+--------------------+------------+------------+",
"| table_catalog | table_schema | table_name | table_type |",
"+---------------+--------------------+------------+------------+",
"| datafusion | information_schema | columns | VIEW |",
"| datafusion | information_schema | tables | VIEW |",
"| datafusion | information_schema | views | VIEW |",
"| datafusion | public | t | BASE TABLE |",
"+---------------+--------------------+------------+------------+",
];
assert_batches_sorted_eq!(expected, &result);
let result = plan_and_collect(&ctx, "SHOW tables").await.unwrap();
assert_batches_sorted_eq!(expected, &result);
}
#[tokio::test]
async fn information_schema_show_columns_no_information_schema() {
let ctx = SessionContext::with_config(SessionConfig::new());
ctx.register_table("t", table_with_sequence(1, 1).unwrap())
.unwrap();
let err = plan_and_collect(&ctx, "SHOW COLUMNS FROM t")
.await
.unwrap_err();
assert_eq!(err.to_string(), "Error during planning: SHOW COLUMNS is not supported unless information_schema is enabled");
}
#[tokio::test]
async fn information_schema_show_columns_like_where() {
let ctx = SessionContext::with_config(SessionConfig::new());
ctx.register_table("t", table_with_sequence(1, 1).unwrap())
.unwrap();
let expected =
"Error during planning: SHOW COLUMNS with WHERE or LIKE is not supported";
let err = plan_and_collect(&ctx, "SHOW COLUMNS FROM t LIKE 'f'")
.await
.unwrap_err();
assert_eq!(err.to_string(), expected);
let err = plan_and_collect(&ctx, "SHOW COLUMNS FROM t WHERE column_name = 'bar'")
.await
.unwrap_err();
assert_eq!(err.to_string(), expected);
}
#[tokio::test]
async fn information_schema_show_columns() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
ctx.register_table("t", table_with_sequence(1, 1).unwrap())
.unwrap();
let result = plan_and_collect(&ctx, "SHOW COLUMNS FROM t").await.unwrap();
let expected = vec![
"+---------------+--------------+------------+-------------+-----------+-------------+",
"| table_catalog | table_schema | table_name | column_name | data_type | is_nullable |",
"+---------------+--------------+------------+-------------+-----------+-------------+",
"| datafusion | public | t | i | Int32 | YES |",
"+---------------+--------------+------------+-------------+-----------+-------------+",
];
assert_batches_sorted_eq!(expected, &result);
let result = plan_and_collect(&ctx, "SHOW columns from t").await.unwrap();
assert_batches_sorted_eq!(expected, &result);
// This isn't ideal but it is consistent behavior for `SELECT * from "T"`
let err = plan_and_collect(&ctx, "SHOW columns from \"T\"")
.await
.unwrap_err();
assert_eq!(
err.to_string(),
// Error propagates from SessionState::get_table_provider
"Error during planning: 'datafusion.public.T' not found"
);
}
// test errors with WHERE and LIKE
#[tokio::test]
async fn information_schema_show_columns_full_extended() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
ctx.register_table("t", table_with_sequence(1, 1).unwrap())
.unwrap();
let result = plan_and_collect(&ctx, "SHOW FULL COLUMNS FROM t")
.await
.unwrap();
let expected = vec![
"+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+",
"| table_catalog | table_schema | table_name | column_name | ordinal_position | column_default | is_nullable | data_type | character_maximum_length | character_octet_length | numeric_precision | numeric_precision_radix | numeric_scale | datetime_precision | interval_type |",
"+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+",
"| datafusion | public | t | i | 0 | | YES | Int32 | | | 32 | 2 | | | |",
"+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+",
];
assert_batches_sorted_eq!(expected, &result);
let result = plan_and_collect(&ctx, "SHOW EXTENDED COLUMNS FROM t")
.await
.unwrap();
assert_batches_sorted_eq!(expected, &result);
}
#[tokio::test]
async fn information_schema_show_table_table_names() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
ctx.register_table("t", table_with_sequence(1, 1).unwrap())
.unwrap();
let result = plan_and_collect(&ctx, "SHOW COLUMNS FROM public.t")
.await
.unwrap();
let expected = vec![
"+---------------+--------------+------------+-------------+-----------+-------------+",
"| table_catalog | table_schema | table_name | column_name | data_type | is_nullable |",
"+---------------+--------------+------------+-------------+-----------+-------------+",
"| datafusion | public | t | i | Int32 | YES |",
"+---------------+--------------+------------+-------------+-----------+-------------+",
];
assert_batches_sorted_eq!(expected, &result);
let result = plan_and_collect(&ctx, "SHOW columns from datafusion.public.t")
.await
.unwrap();
assert_batches_sorted_eq!(expected, &result);
let err = plan_and_collect(&ctx, "SHOW columns from t2")
.await
.unwrap_err();
assert_eq!(
err.to_string(),
// Error propagates from SessionState::get_table_provider
"Error during planning: 'datafusion.public.t2' not found"
);
let err = plan_and_collect(&ctx, "SHOW columns from datafusion.public.t2")
.await
.unwrap_err();
assert_eq!(
err.to_string(),
// Error propagates from SessionState::get_table_provider
"Error during planning: 'datafusion.public.t2' not found"
);
}
#[tokio::test]
async fn show_unsupported() {
let ctx = SessionContext::with_config(SessionConfig::new());
let err = plan_and_collect(&ctx, "SHOW SOMETHING_UNKNOWN")
.await
.unwrap_err();
assert_eq!(err.to_string(), "This feature is not implemented: SHOW SOMETHING_UNKNOWN not implemented. Supported syntax: SHOW <TABLES>");
}
#[tokio::test]
async fn information_schema_columns_not_exist_by_default() {
let ctx = SessionContext::new();
let err = plan_and_collect(&ctx, "SELECT * from information_schema.columns")
.await
.unwrap_err();
assert_eq!(
err.to_string(),
// Error propagates from SessionState::schema_for_ref
"Error during planning: failed to resolve schema: information_schema"
);
}
fn table_with_many_types() -> Arc<dyn TableProvider> {
let schema = Schema::new(vec![
Field::new("int32_col", DataType::Int32, false),
Field::new("float64_col", DataType::Float64, true),
Field::new("utf8_col", DataType::Utf8, true),
Field::new("large_utf8_col", DataType::LargeUtf8, false),
Field::new("binary_col", DataType::Binary, false),
Field::new("large_binary_col", DataType::LargeBinary, false),
Field::new(
"timestamp_nanos",
DataType::Timestamp(TimeUnit::Nanosecond, None),
false,
),
]);
let batch = RecordBatch::try_new(
Arc::new(schema.clone()),
vec![
Arc::new(Int32Array::from_slice(&[1])),
Arc::new(Float64Array::from_slice(&[1.0])),
Arc::new(StringArray::from(vec![Some("foo")])),
Arc::new(LargeStringArray::from(vec![Some("bar")])),
Arc::new(BinaryArray::from_slice(&[b"foo" as &[u8]])),
Arc::new(LargeBinaryArray::from_slice(&[b"foo" as &[u8]])),
Arc::new(TimestampNanosecondArray::from_opt_vec(
vec![Some(123)],
None,
)),
],
)
.unwrap();
let provider = MemTable::try_new(Arc::new(schema), vec![vec![batch]]).unwrap();
Arc::new(provider)
}
#[tokio::test]
async fn information_schema_columns() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let catalog = MemoryCatalogProvider::new();
let schema = MemorySchemaProvider::new();
schema
.register_table("t1".to_owned(), table_with_sequence(1, 1).unwrap())
.unwrap();
schema
.register_table("t2".to_owned(), table_with_many_types())
.unwrap();
catalog
.register_schema("my_schema", Arc::new(schema))
.unwrap();
ctx.register_catalog("my_catalog", Arc::new(catalog));
let result = plan_and_collect(&ctx, "SELECT * from information_schema.columns")
.await
.unwrap();
let expected = vec![
"+---------------+--------------+------------+------------------+------------------+----------------+-------------+-----------------------------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+",
"| table_catalog | table_schema | table_name | column_name | ordinal_position | column_default | is_nullable | data_type | character_maximum_length | character_octet_length | numeric_precision | numeric_precision_radix | numeric_scale | datetime_precision | interval_type |",
"+---------------+--------------+------------+------------------+------------------+----------------+-------------+-----------------------------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+",
"| my_catalog | my_schema | t1 | i | 0 | | YES | Int32 | | | 32 | 2 | | | |",
"| my_catalog | my_schema | t2 | binary_col | 4 | | NO | Binary | | 2147483647 | | | | | |",
"| my_catalog | my_schema | t2 | float64_col | 1 | | YES | Float64 | | | 24 | 2 | | | |",
"| my_catalog | my_schema | t2 | int32_col | 0 | | NO | Int32 | | | 32 | 2 | | | |",
"| my_catalog | my_schema | t2 | large_binary_col | 5 | | NO | LargeBinary | | 9223372036854775807 | | | | | |",
"| my_catalog | my_schema | t2 | large_utf8_col | 3 | | NO | LargeUtf8 | | 9223372036854775807 | | | | | |",
"| my_catalog | my_schema | t2 | timestamp_nanos | 6 | | NO | Timestamp(Nanosecond, None) | | | | | | | |",
"| my_catalog | my_schema | t2 | utf8_col | 2 | | YES | Utf8 | | 2147483647 | | | | | |",
"+---------------+--------------+------------+------------------+------------------+----------------+-------------+-----------------------------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+",
];
assert_batches_sorted_eq!(expected, &result);
}
#[tokio::test]
async fn show_create_view() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let table_sql = "CREATE TABLE abc AS VALUES (1,2,3), (4,5,6)";
plan_and_collect(&ctx, table_sql).await.unwrap();
let view_sql = "CREATE VIEW xyz AS SELECT * FROM abc";
plan_and_collect(&ctx, view_sql).await.unwrap();
let results_sql = "SHOW CREATE TABLE xyz";
let results = plan_and_collect(&ctx, results_sql).await.unwrap();
assert_eq!(results[0].num_rows(), 1);
let expected = vec![
"+---------------+--------------+------------+--------------------------------------+",
"| table_catalog | table_schema | table_name | definition |",
"+---------------+--------------+------------+--------------------------------------+",
"| datafusion | public | xyz | CREATE VIEW xyz AS SELECT * FROM abc |",
"+---------------+--------------+------------+--------------------------------------+",
];
assert_batches_eq!(expected, &results);
}
#[tokio::test]
async fn show_create_view_in_catalog() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let table_sql = "CREATE TABLE abc AS VALUES (1,2,3), (4,5,6)";
plan_and_collect(&ctx, table_sql).await.unwrap();
let schema_sql = "CREATE SCHEMA test";
plan_and_collect(&ctx, schema_sql).await.unwrap();
let view_sql = "CREATE VIEW test.xyz AS SELECT * FROM abc";
plan_and_collect(&ctx, view_sql).await.unwrap();
let result_sql = "SHOW CREATE TABLE test.xyz";
let results = plan_and_collect(&ctx, result_sql).await.unwrap();
assert_eq!(results[0].num_rows(), 1);
let expected = vec![
"+---------------+--------------+------------+-------------------------------------------+",
"| table_catalog | table_schema | table_name | definition |",
"+---------------+--------------+------------+-------------------------------------------+",
"| datafusion | test | xyz | CREATE VIEW test.xyz AS SELECT * FROM abc |",
"+---------------+--------------+------------+-------------------------------------------+",
];
assert_batches_eq!(expected, &results);
}
#[tokio::test]
async fn show_create_table() {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let table_sql = "CREATE TABLE abc AS VALUES (1,2,3), (4,5,6)";
plan_and_collect(&ctx, table_sql).await.unwrap();
let result_sql = "SHOW CREATE TABLE abc";
let results = plan_and_collect(&ctx, result_sql).await.unwrap();
let expected = vec![
"+---------------+--------------+------------+------------+",
"| table_catalog | table_schema | table_name | definition |",
"+---------------+--------------+------------+------------+",
"| datafusion | public | abc | |",
"+---------------+--------------+------------+------------+",
];
assert_batches_eq!(expected, &results);
}
/// Execute SQL and return results
async fn plan_and_collect(ctx: &SessionContext, sql: &str) -> Result<Vec<RecordBatch>> {
ctx.sql(sql).await?.collect().await
}