alamb commented on code in PR #14677: URL: https://github.com/apache/datafusion/pull/14677#discussion_r1970419771
########## datafusion/sqllogictest/test_files/explain_tree.slt: ########## @@ -0,0 +1,198 @@ +# 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. + +# Tests for tree explain + + + +statement ok +set datafusion.explain.format = "pretty"; + +######## Setup Data Files ####### + +# table1: CSV +query I +COPY (VALUES (1, 'foo', 1, '2023-01-01'), (2, 'bar', 2, '2023-01-02'), (3, 'baz', 3, '2023-01-03')) +TO 'test_files/scratch/explain_tree/table1.csv'; +---- +3 + +statement ok +CREATE EXTERNAL TABLE table1 ( + int_col INT, + string_col TEXT, + bigint_col BIGINT, + date_col DATE +) +STORED AS CSV +LOCATION 'test_files/scratch/explain_tree/table1.csv'; + +# table2: Parquet +query I +COPY (SELECT * from table1) +TO 'test_files/scratch/explain_tree/table2.parquet' +---- +3 + +statement ok +CREATE EXTERNAL TABLE table2 +STORED AS PARQUET +LOCATION 'test_files/scratch/explain_tree/table2.parquet'; + + +# table3: Memoru +statement ok +CREATE TABLE table3 as select * from table1; + +######## Begin Queries ######## + +# Filter +query TT +explain SELECT int_col FROM table1 WHERE string_col != 'foo'; +---- +logical_plan +01)Projection: table1.int_col +02)--Filter: table1.string_col != Utf8("foo") +03)----TableScan: table1 projection=[int_col, string_col], partial_filters=[table1.string_col != Utf8("foo")] +physical_plan +01)┌───────────────────────────┐ +02)│ CoalesceBatchesExec │ +03)└─────────────┬─────────────┘ +04)┌─────────────┴─────────────┐ +05)│ FilterExec │ +06)└─────────────┬─────────────┘ +07)┌─────────────┴─────────────┐ +08)│ RepartitionExec │ +09)└─────────────┬─────────────┘ +10)┌─────────────┴─────────────┐ +11)│ DataSourceExec │ +12)└───────────────────────────┘ + +# Aggregate +query TT +explain SELECT string_col, SUM(bigint_col) FROM table1 GROUP BY string_col; +---- +logical_plan +01)Aggregate: groupBy=[[table1.string_col]], aggr=[[sum(table1.bigint_col)]] +02)--TableScan: table1 projection=[string_col, bigint_col] +physical_plan +01)┌───────────────────────────┐ +02)│ AggregateExec │ +03)└─────────────┬─────────────┘ +04)┌─────────────┴─────────────┐ +05)│ CoalesceBatchesExec │ +06)└─────────────┬─────────────┘ +07)┌─────────────┴─────────────┐ +08)│ RepartitionExec │ +09)└─────────────┬─────────────┘ +10)┌─────────────┴─────────────┐ +11)│ AggregateExec │ +12)└─────────────┬─────────────┘ +13)┌─────────────┴─────────────┐ +14)│ RepartitionExec │ +15)└─────────────┬─────────────┘ +16)┌─────────────┴─────────────┐ +17)│ DataSourceExec │ +18)└───────────────────────────┘ + +# 2 Joins +query TT +explain SELECT table1.string_col, table2.date_col FROM table1 JOIN table2 ON table1.int_col = table2.int_col; +---- +logical_plan +01)Projection: table1.string_col, table2.date_col +02)--Inner Join: table1.int_col = table2.int_col +03)----TableScan: table1 projection=[int_col, string_col] +04)----TableScan: table2 projection=[int_col, date_col] +physical_plan +01)┌───────────────────────────┐ +02)│ CoalesceBatchesExec │ +03)└─────────────┬─────────────┘ +04)┌─────────────┴─────────────┐ +05)│ HashJoinExec ├──────────────┐ +06)└─────────────┬─────────────┘ │ +07)┌─────────────┴─────────────┐┌─────────────┴─────────────┐ +08)│ CoalesceBatchesExec ││ CoalesceBatchesExec │ +09)└─────────────┬─────────────┘└─────────────┬─────────────┘ +10)┌─────────────┴─────────────┐┌─────────────┴─────────────┐ +11)│ RepartitionExec ││ RepartitionExec │ +12)└─────────────┬─────────────┘└─────────────┬─────────────┘ +13)┌─────────────┴─────────────┐┌─────────────┴─────────────┐ +14)│ RepartitionExec ││ RepartitionExec │ +15)└─────────────┬─────────────┘└─────────────┬─────────────┘ +16)┌─────────────┴─────────────┐┌─────────────┴─────────────┐ +17)│ DataSourceExec ││ DataSourceExec │ +18)└───────────────────────────┘└───────────────────────────┘ + +# 3 Joins +query TT +explain SELECT + table1.string_col, + table2.date_col, + table3.date_col +FROM + table1 JOIN table2 ON table1.int_col = table2.int_col + JOIN table3 ON table2.int_col = table3.int_col; +---- +logical_plan Review Comment: It is pretty neat to see the joins visually like this -- 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-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org