Repository: dbt-labs/dbt-core

Issue:
[CT-2373][Bug] `dbt show` doesn't work for seeds
```
dbt show --select +orders 
19:52:09  Running with dbt=1.5.0-b5
19:52:10  Found 5 models, 20 tests, 0 snapshots, 0 analyses, 309 macros, 0 operations, 3 seed files, 0 sources, 0 exposures, 0 metrics, 0 groups
19:52:10  
19:52:10  Concurrency: 3 threads (target='dev')
19:52:10  
Error: Traceback (most recent call last):
  File "/Users/chenyuli/git/dbt-core/core/dbt/cli/requires.py", line 100, in wrapper
    result, success = func(*args, **kwargs)
  File "/Users/chenyuli/git/dbt-core/core/dbt/cli/main.py", line 345, in show
    results = task.run()
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 438, in run
    result = self.execute_with_hooks(selected_uids)
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 401, in execute_with_hooks
    res = self.execute_nodes()
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 350, in execute_nodes
    self.run_queue(pool)
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 259, in run_queue
    self._raise_set_error()
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 240, in _raise_set_error
    raise self._raise_next_tick
dbt.exceptions.DbtRuntimeError: Runtime Error
  Database Error in seed raw_payments (seeds/raw_payments.csv)
    can't execute an empty query
```

_Originally posted by @ChenyuLInx in https://github.com/dbt-labs/dbt-core/pull/7208#pullrequestreview-1371920476_
[CT-2373][Bug] `dbt show` doesn't work for seeds
```
dbt show --select +orders 
19:52:09  Running with dbt=1.5.0-b5
19:52:10  Found 5 models, 20 tests, 0 snapshots, 0 analyses, 309 macros, 0 operations, 3 seed files, 0 sources, 0 exposures, 0 metrics, 0 groups
19:52:10  
19:52:10  Concurrency: 3 threads (target='dev')
19:52:10  
Error: Traceback (most recent call last):
  File "/Users/chenyuli/git/dbt-core/core/dbt/cli/requires.py", line 100, in wrapper
    result, success = func(*args, **kwargs)
  File "/Users/chenyuli/git/dbt-core/core/dbt/cli/main.py", line 345, in show
    results = task.run()
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 438, in run
    result = self.execute_with_hooks(selected_uids)
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 401, in execute_with_hooks
    res = self.execute_nodes()
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 350, in execute_nodes
    self.run_queue(pool)
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 259, in run_queue
    self._raise_set_error()
  File "/Users/chenyuli/git/dbt-core/core/dbt/task/runnable.py", line 240, in _raise_set_error
    raise self._raise_next_tick
dbt.exceptions.DbtRuntimeError: Runtime Error
  Database Error in seed raw_payments (seeds/raw_payments.csv)
    can't execute an empty query
```

_Originally posted by @ChenyuLInx in https://github.com/dbt-labs/dbt-core/pull/7208#pullrequestreview-1371920476_


Discussion:
I was about to open a bug report for this, but then I found this one.
To be clear, the gnarly stack trace is already addressed and it displays much more nicely now (albeit still confusing if the error is intended or not):

```
$ dbt show -s my_seed

19:13:33  Running with dbt=1.5.0-rc1
19:13:33  Found 4 models, 0 tests, 1 snapshot, 1 analysis, 307 macros, 0 operations, 4 seed files, 3 sources, 0 exposures, 0 metrics, 0 groups
19:13:33  
19:13:33  Concurrency: 5 threads (target='postgres')
19:13:33  
19:13:33  Encountered an error:
Runtime Error
  Database Error in seed my_seed (seeds/my_seed.csv)
    can't execute an empty query
```

## Possible improvements

For a better user experience, we could do one of two things:
1. Display a message indicating that `show`ing seeds is not supported
2. Support `show`ing seeds
## Workarounds in the meantime

### Option 1: `dbt seed --show`

```shell
$ dbt seed --show -s my_seed

19:21:37  Running with dbt=1.5.0-rc1
19:21:38  Found 4 models, 0 tests, 1 snapshot, 1 analysis, 307 macros, 0 operations, 4 seed files, 3 sources, 0 exposures, 0 metrics, 0 groups
19:21:38  
19:21:38  Concurrency: 5 threads (target='postgres')
19:21:38  
19:21:38  1 of 1 START seed file dbt_dbeatty.my_seed ..................................... [RUN]
19:21:38  1 of 1 OK loaded seed file dbt_dbeatty.my_seed ................................. [INSERT 4 in 0.10s]
19:21:38  
19:21:38  Finished running 1 seed in 0 hours 0 minutes and 0.33 seconds (0.33s).
19:21:38  
19:21:38  Random sample of table: dbt_dbeatty.my_seed
19:21:38  -------------------------------------------
| id | fruit  |
| -- | ------ |
|  1 | apple  |
|  2 | orange |
19:21:38  
19:21:38  
19:21:38  Completed successfully
19:21:38  
19:21:38  Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1
```

### Option 2: `dbt show --inline`

Assuming that `dbt seed` has already been run, then we can use the `--inline` option to `ref` the seed:

```shell
$ dbt show --inline 'select * from {{ ref("my_seed") }}'

19:17:49  Running with dbt=1.5.0-rc1
19:17:49  Found 4 models, 0 tests, 1 snapshot, 1 analysis, 307 macros, 0 operations, 4 seed files, 3 sources, 0 exposures, 0 metrics, 0 groups
19:17:49  
19:17:50  Concurrency: 5 threads (target='postgres')
19:17:50  
19:17:50  Previewing inline node:
| id | fruit  |
| -- | ------ |
|  1 | apple  |
|  2 | orange |
```

If `dbt seed` hasn't already been run, then you'll get an error like this:
```
Runtime Error
  Database Error in sql operation inline_query (from remote system.sql)
    relation "dbt_dbeatty.my_seed" does not exist
    LINE 2: select * from "postgres"."dbt_dbeatty"."my_seed"
```
The question is: Do we think there's actual merit in showing a Markdown table preview of a CSV file that's also available locally? (i.e. the little-known, little-used behavior of `dbt seed --show`)

If we were to support another command or configuration for this (https://github.com/dbt-labs/dbt-core/issues/7391), that would also accomplish what Doug outlined as the second option (= preview the table already built from this seed).
The merit comes in me being able to use my `dbt show` hammer 🔨  without giving any thought to the resource type(s) I am selecting.

Example use-cases:
- I want to take a peek at the datasets in a data flow through a series of steps.
- I'm collaborating with someone in GitHub, and I want to describe a series of transformations.

<img width="308" alt="image" src="https://user-images.githubusercontent.com/44704949/233402961-89cb8e8e-06fc-4195-94f2-2831b5c5215f.png">
I was about to open a bug report for this, but then I found this one.
To be clear, the gnarly stack trace is already addressed and it displays much more nicely now (albeit still confusing if the error is intended or not):

```
$ dbt show -s my_seed

19:13:33  Running with dbt=1.5.0-rc1
19:13:33  Found 4 models, 0 tests, 1 snapshot, 1 analysis, 307 macros, 0 operations, 4 seed files, 3 sources, 0 exposures, 0 metrics, 0 groups
19:13:33  
19:13:33  Concurrency: 5 threads (target='postgres')
19:13:33  
19:13:33  Encountered an error:
Runtime Error
  Database Error in seed my_seed (seeds/my_seed.csv)
    can't execute an empty query
```

## Possible improvements

For a better user experience, we could do one of two things:
1. Display a message indicating that `show`ing seeds is not supported
2. Support `show`ing seeds
## Workarounds in the meantime

### Option 1: `dbt seed --show`

```shell
$ dbt seed --show -s my_seed

19:21:37  Running with dbt=1.5.0-rc1
19:21:38  Found 4 models, 0 tests, 1 snapshot, 1 analysis, 307 macros, 0 operations, 4 seed files, 3 sources, 0 exposures, 0 metrics, 0 groups
19:21:38  
19:21:38  Concurrency: 5 threads (target='postgres')
19:21:38  
19:21:38  1 of 1 START seed file dbt_dbeatty.my_seed ..................................... [RUN]
19:21:38  1 of 1 OK loaded seed file dbt_dbeatty.my_seed ................................. [INSERT 4 in 0.10s]
19:21:38  
19:21:38  Finished running 1 seed in 0 hours 0 minutes and 0.33 seconds (0.33s).
19:21:38  
19:21:38  Random sample of table: dbt_dbeatty.my_seed
19:21:38  -------------------------------------------
| id | fruit  |
| -- | ------ |
|  1 | apple  |
|  2 | orange |
19:21:38  
19:21:38  
19:21:38  Completed successfully
19:21:38  
19:21:38  Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1
```

### Option 2: `dbt show --inline`

Assuming that `dbt seed` has already been run, then we can use the `--inline` option to `ref` the seed:

```shell
$ dbt show --inline 'select * from {{ ref("my_seed") }}'

19:17:49  Running with dbt=1.5.0-rc1
19:17:49  Found 4 models, 0 tests, 1 snapshot, 1 analysis, 307 macros, 0 operations, 4 seed files, 3 sources, 0 exposures, 0 metrics, 0 groups
19:17:49  
19:17:50  Concurrency: 5 threads (target='postgres')
19:17:50  
19:17:50  Previewing inline node:
| id | fruit  |
| -- | ------ |
|  1 | apple  |
|  2 | orange |
```

If `dbt seed` hasn't already been run, then you'll get an error like this:
```
Runtime Error
  Database Error in sql operation inline_query (from remote system.sql)
    relation "dbt_dbeatty.my_seed" does not exist
    LINE 2: select * from "postgres"."dbt_dbeatty"."my_seed"
```
The question is: Do we think there's actual merit in showing a Markdown table preview of a CSV file that's also available locally? (i.e. the little-known, little-used behavior of `dbt seed --show`)

If we were to support another command or configuration for this (https://github.com/dbt-labs/dbt-core/issues/7391), that would also accomplish what Doug outlined as the second option (= preview the table already built from this seed).
The merit comes in me being able to use my `dbt show` hammer 🔨  without giving any thought to the resource type(s) I am selecting.

Example use-cases:
- I want to take a peek at the datasets in a data flow through a series of steps.
- I'm collaborating with someone in GitHub, and I want to describe a series of transformations.

<img width="308" alt="image" src="https://user-images.githubusercontent.com/44704949/233402961-89cb8e8e-06fc-4195-94f2-2831b5c5215f.png">

Resolving patch:
diff --git a/core/dbt/task/show.py b/core/dbt/task/show.py
--- a/core/dbt/task/show.py
+++ b/core/dbt/task/show.py
@@ -2,12 +2,14 @@
 import threading
 import time
 
+from dbt.contracts.graph.nodes import SeedNode
 from dbt.contracts.results import RunResult, RunStatus
 from dbt.events.base_types import EventLevel
 from dbt.events.functions import fire_event
 from dbt.events.types import ShowNode, Note
 from dbt.exceptions import DbtRuntimeError
 from dbt.task.compile import CompileTask, CompileRunner
+from dbt.task.seed import SeedRunner
 
 
 class ShowRunner(CompileRunner):
@@ -41,8 +43,11 @@ def _runtime_initialize(self):
             raise DbtRuntimeError("Either --select or --inline must be passed to show")
         super()._runtime_initialize()
 
-    def get_runner_type(self, _):
-        return ShowRunner
+    def get_runner_type(self, node):
+        if isinstance(node, SeedNode):
+            return SeedRunner
+        else:
+            return ShowRunner
 
     def task_end_messages(self, results):
         is_inline = bool(getattr(self.args, "inline", None))


Test patch:
diff --git a/tests/functional/show/test_show.py b/tests/functional/show/test_show.py
--- a/tests/functional/show/test_show.py
+++ b/tests/functional/show/test_show.py
@@ -87,6 +87,10 @@ def test_second_ephemeral_model(self, project):
         )
         assert "col_hundo" in log_output
 
+    def test_seed(self, project):
+        (results, log_output) = run_dbt_and_capture(["show", "--select", "sample_seed"])
+        assert "Previewing node 'sample_seed'" in log_output
+
 
 class TestShowModelVersions:
     @pytest.fixture(scope="class")